Coder Social home page Coder Social logo

khoih-prog / asyncmqtt_generic Goto Github PK

View Code? Open in Web Editor NEW
57.0 5.0 10.0 897 KB

Arduino Arduino Library for ESP8266, ESP32, Portenta_H7, STM32 and RP2040W asynchronous MQTT client implementation. This library, ported to support ESP32, WT32_ETH01 (ESP32 + LAN8720), ESP8266, Portenta_H7 (Ethernet or WiFi) and STM32 (LAN8742A or LAN8720 Ethernet), Teensy 4.1 using QNEthernet, RASPBERRY_PI_PICO_W with CYW43439 WiFi. Currently supporting TLS/SSL for ESP32 only

License: MIT License

C 65.93% C++ 32.91% Shell 1.01% Python 0.15%
tls fingerprint async esp32 esp8266 stm32f7 portenta-h7 lan8720 lan8742a wt32-eth01

asyncmqtt_generic's Introduction

AsyncMQTT_Generic Library (Async MQTT Client for ESP8266, ESP32, etc.)

arduino-library-badge GitHub release contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Important Notes for ESP8266

The new ESP8266 cores v3.0.2+ introduces many new breaking features, such as replacing axtls with bearssl, as well as good ones such as LwIP Ethernet W5500lwIP, W5100lwIP and ENC28J60lwIP libraries.

Because the original ESPAsyncTCP library is not well maintained to cope with dynamic environment of new cores, features, etc., this library has to use the forked ESPAsyncTCP library, which has been created to keep up with the fast changes and avoid compile errors in future cores.

Hopefully the bearssl feature of the new ESP8266 cores will be added to the forked ESPAsyncTCP library in the near future to support SSL.



Why do we need this AsyncMQTT_Generic library

Features

This AsyncMQTT_Generic library is based on and modified from Marvin Roger's async-mqtt-client Library, to provide support to many more boards besides ESP32/ESP8266, such as STM32F, Portenta_H7, Teensy 4.1, etc. boards. Those supported boards can be used with ESP8266/ESP32’s WiFi, LAN8742A Ethernet, Portenta_H7 WiFi/Ethernet, Teensy 4.1 QNEthernet, RASPBERRY_PI_PICO_W with CYW43439 WiFi, ESP32 with LwIP W5500 or ENC28J60.

Why Async is better

  • Using asynchronous network means that you can handle more than one connection at the same time
  • You are called once the request is ready and parsed
  • When you send the response, you are immediately ready to handle other connections while the server is taking care of sending the response in the background
  • Speed is OMG
  • Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse
  • Easily extensible to handle any type of content
  • Supports Continue 100
  • Async WebSocket plugin offering different locations without extra servers or ports
  • Async EventSource (Server-Sent Events) plugin to send events to the browser
  • URL Rewrite plugin for conditional and permanent url rewrites
  • ServeStatic plugin that supports cache, Last-Modified, default index and more
  • Simple template processing engine to handle templates

Currently supported Boards

This AsyncMQTT_Generic library currently supports these following boards:

  1. ESP32

  2. ESP8266

  3. WT32_ETH01 (ESP32 + LAN8720A)

  4. STM32F/L/H/G/WB/MP1 boards with built-in Ethernet LAN8742A such as :

  • Nucleo-144 (F429ZI, F767ZI)
  • Discovery (STM32F746G-DISCOVERY)
  • All STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet
  1. STM32F4/F7 boards using Ethernet LAN8720 such as :
  • Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)
  • Discovery (DISCO_F746NG)
  • STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)

Note: Must use with STM32 core v2.2.0-

  1. Portenta_H7 using either Murata WiFi or Vision-shield Ethernet

  2. Teensy 4.1 using QNEthernet Library

  3. RASPBERRY_PI_PICO_W with CYW43439 WiFi using arduino-pico core v2.4.0+

  4. ESP32 boards using LwIP ENC28J60 Ethernet

  5. ESP32 boards using LwIP W5500 Ethernet


To-be-supported Boards

  1. Any future board with supporting AsyncTCP library
  2. ESP32 boards using LwIP W6100 Ethernet


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. ESP32 Core 2.0.6+ for ESP32-based boards. Latest release
  3. ESP8266 Core 3.1.1+ for ESP8266-based boards. Latest release.
  4. Arduino Core for STM32 v2.4.0+ for STM32F/L/H/G/WB/MP1 boards using built-in LAN8742A. GitHub release. Use core v2.2.0- for LAN8720.
  5. Arduino mbed_portenta core 3.5.4+ for Arduino (Use Arduino Board Manager) Portenta_H7-based boards. GitHub release
  6. Earle Philhower's arduino-pico core v2.7.1+ for RASPBERRY_PI_PICO_W with CYW43439 WiFi, etc. GitHub release
  7. Teensy core v1.57+ for Teensy 4.1. GitHub release
  8. KH_Forked ESPAsyncTCP v1.3.0+ for ESP8266. To install manually for Arduino IDE
  9. AsyncTCP v1.1.1+ for ESP32.
  10. STM32Ethernet library v1.3.0+ for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery). GitHub release
  11. LwIP library v2.1.2+ for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery). GitHub release
  12. KH_Forked STM32AsyncTCP library v1.0.1+ for built-in Ethernet on (Nucleo-144, Discovery). To install manually for Arduino IDE
  13. WebServer_WT32_ETH01 library v1.5.1+ to use WT32_ETH01 (ESP32 + LAN8720). To install, check arduino-library-badge
  14. WebServer_ESP32_W5500 library v1.5.3+ to use (ESP32 + LwIP W5500). To install, check arduino-library-badge
  15. WebServer_ESP32_ENC library v1.5.3+ to use (ESP32 + LwIP ENC28J60). To install, check arduino-library-badge
  16. Portenta_H7_AsyncTCP library v1.4.0+ to use Portenta_H7 using either Murata WiFi or Vision-shield Ethernet. To install, check arduino-library-badge.
  17. Teensy41_AsyncTCP library v1.1.0+ to use Teensy 4.1 using QNEthernet Library. To install, check arduino-library-badge.
  18. AsyncTCP_RP2040W library v1.1.0+ to use RASPBERRY_PI_PICO_W with CYW43439 WiFi. To install, check arduino-library-badge.
  19. AsyncTCP_SSL library v1.3.1+ to use TLS/SSL for ESP32. To install, check arduino-library-badge.
  20. ESPAsync_WiFiManager library v1.15.1+ for ESP32/ESP8266 using some examples. GitHub release
  21. AsyncWebServer_RP2040W library v1.4.1+ for RP2040W using some examples. GitHub release


Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for AsyncMQTT_Generic, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

Another way to install is to:

  1. Navigate to AsyncMQTT_Generic page.
  2. Download the latest release AsyncMQTT_Generic-main.zip.
  3. Extract the zip file to AsyncMQTT_Generic-main directory
  4. Copy whole AsyncMQTT_Generic-main folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO:

  1. Install VS Code
  2. Install PlatformIO
  3. Install AsyncMQTT_Generic library by using Library Manager. Search for AsyncMQTT_Generic in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


Packages' Patches

1. For STM32 boards

1.1 For STM32 boards to use LAN8720

For Generic STM32F4 series boards, such as STM32F407VE, using LAN8720, please use STM32 core v2.2.0 as breaking core v2.3.0 creates the compile error.


To use LAN8720 on some STM32 boards

  • Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)
  • Discovery (DISCO_F746NG)
  • STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)

you have to copy the files stm32f4xx_hal_conf_default.h and stm32f7xx_hal_conf_default.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files.

Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h for STM32F4.
  • ~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h for Nucleo-144 STM32F7.

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F4xx/stm32f4xx_hal_conf_default.h
  • `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F7xx/stm32f7xx_hal_conf_default.h

1.2 For STM32 boards to use Serial1

To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards, you have to copy the files STM32 variant.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.

Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h for Nucleo-144 NUCLEO_F767ZI.
  • ~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h for Nucleo-64 NUCLEO_L053R8.

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h
  • ~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h

2. For Teensy boards

To be able to compile and run on Teensy boards, you have to copy the files in Packages_Patches for Teensy directory into Teensy hardware directory (./arduino-1.8.19/hardware/teensy/avr/boards.txt).

Supposing the Arduino version is 1.8.19. These files must be copied into the directory:

  • ./arduino-1.8.19/hardware/teensy/avr/boards.txt
  • ./arduino-1.8.19/hardware/teensy/avr/cores/teensy/Stream.h
  • ./arduino-1.8.19/hardware/teensy/avr/cores/teensy3/Stream.h
  • ./arduino-1.8.19/hardware/teensy/avr/cores/teensy4/Stream.h

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz These files must be copied into the directory:

  • ./arduino-x.yy.zz/hardware/teensy/avr/boards.txt
  • ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy/Stream.h
  • ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy3/Stream.h
  • ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.h

3. For Portenta_H7 boards using Arduino IDE in Linux

To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.), you have to copy the file portenta_post_install.sh into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh).

Then run the following command using sudo

$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh

This will create the file /etc/udev/rules.d/49-portenta_h7.rules as follows:

# Portenta H7 bootloader mode UDEV rules

SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"

Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory:

  • ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh

Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

  • ~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh


HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)

Please have a look at ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to have more detailed description and solution of the issue.

1. ESP32 has 2 ADCs, named ADC1 and ADC2

2. ESP32 ADCs functions

  • ADC1 controls ADC function for pins GPIO32-GPIO39
  • ADC2 controls ADC function for pins GPIO0, 2, 4, 12-15, 25-27

3.. ESP32 WiFi uses ADC2 for WiFi functions

Look in file adc_common.c

In ADC2, there're two locks used for different cases:

  1. lock shared with app and Wi-Fi: ESP32: When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed. ESP32S2: The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.

  2. lock shared between tasks: when several tasks sharing the ADC2, we want to guarantee all the requests will be handled. Since conversions are short (about 31us), app returns the lock very soon, we use a spinlock to stand there waiting to do conversions one by one.

adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.

  • In order to use ADC2 for other functions, we have to acquire complicated firmware locks and very difficult to do
  • So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).
  • Use ADC1, and pins GPIO32-GPIO39
  • If somehow it's a must to use those pins serviced by ADC2 (GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27), use the fix mentioned at the end of ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to work with ESP32 WiFi/BlueTooth (BT/BLE).


Basic Usage

Please check API documentation.



HOWTO use STM32F4 with LAN8720

1. Wiring

This is the Wiring for STM32F4 (BLACK_F407VE, etc.) using LAN8720

LAN8720 PHY <---> STM32F4
TX1 <---> PB_13
TX_EN <---> PB_11
TX0 <---> PB_12
RX0 <---> PC_4
RX1 <---> PC_5
nINT/RETCLK <---> PA_1
CRS <---> PA_7
MDIO <---> PA_2
MDC <---> PC_1
GND <---> GND
VCC <---> +3.3V

2. HOWTO program using STLink V-2 or V-3

Connect as follows. To program, use STM32CubeProgrammer or Arduino IDE with

  • U(S)ART Support: "Enabled (generic Serial)"

  • Upload Method : "STM32CubeProgrammer (SWD)"

  • Jumper settings to program via STLInk

From <---> To
BOOT0 <---> 3.3V
  • Jumper settings when running normally to avoid accidentally reprogram
From <---> To
BOOT0 <---> GND

STLink <---> STM32F4
SWCLK <---> SWCLK
SWDIO <---> SWDIO
RST <---> NRST
GND <---> GND
5v <---> 5V


3. HOWTO use Serial Port for Debugging

Connect FDTI (USB to Serial) as follows:

FDTI <---> STM32F4
RX <---> TX=PA_9
TX <---> RX=PA_10
GND <---> GND


HOWTO use ESP8266 with W5x00 or ENC28J60 Ethernet

1. ESP8266 Wiring

This is the wiring for EP8266 W5x00 or ENC28J60 Ethernet when using SS = GPIO16

W5x00/ENC28J60 Ethernet <---> ESP8266
MOSI <---> MOSI = GPIO13
MISO <---> MISO = GPIO12
SCK <---> SCK = GPIO14
SS <---> GPIO16
GND <---> GND
VCC <---> +3.3V


HOWTO use ESP32 with LwIP W5500 or ENC28J60 Ethernet

1. ESP32 Wiring

This is the wiring for ESP8266 W5500 or ENC28J60 Ethernet when using SS = GPIO5

// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4
//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5

W5x00/ENC28J60 Ethernet <---> ESP32
MOSI <---> MOSI = GPIO23
MISO <---> MISO = GPIO19
SCK <---> SCK = GPIO18
SS <---> GPIO5
INT <---> GPIO4
GND <---> GND
VCC <---> +3.3V


Examples

1. For ESP32

  1. FullyFeatured_ESP32
  2. FullyFeaturedSSL_ESP32
  3. AsyncWebServer_MQTT New

2. For ESP8266

  1. FullyFeatured_ESP8266
  2. FullyFeatured_ESP8266_Ethernet Use with core v3.0.2+

3. For WT32_ETH01

  1. FullyFeatured_WT32_ETH01
  2. FullyFeaturedSSL_WT32_ETH01

4. For STM32 using LAN8742A

  1. FullyFeatured_STM32

5. For STM32 using LAN8720

  1. FullyFeatured_STM32_LAN8720 Use with core v2.2.0-

6. For Portenta_H7 using Murata WiFi

  1. FullyFeatured_PortentaH7_WiFi

7. For Portenta_H7 using built-in Ethernet

  1. FullyFeatured_PortentaH7_Ethernet

8. For Teensy 4.1 using QNEthernet Library

  1. FullyFeatured_QNEthernet

9. or RASPBERRY_PI_PICO_W with CYW43439 WiFi

  1. FullyFeatured_RP2040W
  2. AsyncWebServer_MQTT_RP2040W New

10. For ESP32_ENC

  1. FullyFeatured_ESP32_ENC
  2. FullyFeaturedSSL_ESP32_ENC

11. For ESP32_W5500

  1. FullyFeatured_ESP32_W5500
  2. FullyFeaturedSSL_ESP32_W5500


// Example project which can be built with SSL enabled or disabled.
// The espressif8266_stage platform must be installed.
// Refer to platformio.ini for the build configuration and platform installation.
#include "defines.h"
#include <WiFi.h>
extern "C"
{
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
}
#define ASYNC_TCP_SSL_ENABLED true
//#define ASYNC_TCP_SSL_ENABLED false
#include <AsyncMqtt_Generic.h>
//#define MQTT_HOST IPAddress(192, 168, 2, 110)
#define MQTT_HOST "broker.emqx.io" // Broker address
#if ASYNC_TCP_SSL_ENABLED
#define MQTT_SECURE true
const uint8_t MQTT_SERVER_FINGERPRINT[] = {0x7e, 0x36, 0x22, 0x01, 0xf9, 0x7e, 0x99, 0x2f, 0xc5, 0xdb, 0x3d, 0xbe, 0xac, 0x48, 0x67, 0x5b, 0x5d, 0x47, 0x94, 0xd2};
const char *PubTopic = "async-mqtt/ESP32_SSL_Pub"; // Topic to publish
#define MQTT_PORT 8883
#else
const char *PubTopic = "async-mqtt/ESP32_Pub"; // Topic to publish
#define MQTT_PORT 1883
#endif
AsyncMqttClient mqttClient;
TimerHandle_t mqttReconnectTimer;
TimerHandle_t wifiReconnectTimer;
void connectToWifi()
{
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
void connectToMqtt()
{
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
void WiFiEvent(WiFiEvent_t event)
{
switch (event)
{
#if USING_CORE_ESP32_CORE_V200_PLUS
case ARDUINO_EVENT_WIFI_READY:
Serial.println("WiFi ready");
break;
case ARDUINO_EVENT_WIFI_STA_START:
Serial.println("WiFi STA starting");
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
Serial.println("WiFi STA connected");
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
Serial.println("WiFi connected");
Serial.print("IP address: "); Serial.println(WiFi.localIP());
connectToMqtt();
break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
Serial.println("WiFi lost IP");
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Serial.println("WiFi lost connection");
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
xTimerStart(wifiReconnectTimer, 0);
break;
#else
case SYSTEM_EVENT_STA_GOT_IP:
Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
connectToMqtt();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
Serial.println("WiFi lost connection");
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
xTimerStart(wifiReconnectTimer, 0);
break;
#endif
default:
break;
}
}
void printSeparationLine()
{
Serial.println("************************************************");
}
void onMqttConnect(bool sessionPresent)
{
Serial.print("Connected to MQTT broker: "); Serial.print(MQTT_HOST);
Serial.print(", port: "); Serial.println(MQTT_PORT);
Serial.print("PubTopic: "); Serial.println(PubTopic);
printSeparationLine();
Serial.print("Session present: "); Serial.println(sessionPresent);
uint16_t packetIdSub = mqttClient.subscribe(PubTopic, 2);
Serial.print("Subscribing at QoS 2, packetId: "); Serial.println(packetIdSub);
mqttClient.publish(PubTopic, 0, true, "ESP32 Test");
Serial.println("Publishing at QoS 0");
uint16_t packetIdPub1 = mqttClient.publish(PubTopic, 1, true, "test 2");
Serial.print("Publishing at QoS 1, packetId: "); Serial.println(packetIdPub1);
uint16_t packetIdPub2 = mqttClient.publish(PubTopic, 2, true, "test 3");
Serial.print("Publishing at QoS 2, packetId: "); Serial.println(packetIdPub2);
printSeparationLine();
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
{
(void) reason;
Serial.println("Disconnected from MQTT.");
if (WiFi.isConnected())
{
xTimerStart(mqttReconnectTimer, 0);
}
}
void onMqttSubscribe(const uint16_t& packetId, const uint8_t& qos)
{
Serial.println("Subscribe acknowledged.");
Serial.print(" packetId: "); Serial.println(packetId);
Serial.print(" qos: "); Serial.println(qos);
}
void onMqttUnsubscribe(const uint16_t& packetId)
{
Serial.println("Unsubscribe acknowledged.");
Serial.print(" packetId: "); Serial.println(packetId);
}
void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
const size_t& len, const size_t& index, const size_t& total)
{
(void) payload;
Serial.println("Publish received.");
Serial.print(" topic: "); Serial.println(topic);
Serial.print(" qos: "); Serial.println(properties.qos);
Serial.print(" dup: "); Serial.println(properties.dup);
Serial.print(" retain: "); Serial.println(properties.retain);
Serial.print(" len: "); Serial.println(len);
Serial.print(" index: "); Serial.println(index);
Serial.print(" total: "); Serial.println(total);
}
void onMqttPublish(const uint16_t& packetId)
{
Serial.println("Publish acknowledged");
Serial.print(" packetId: "); Serial.println(packetId);
}
void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);
Serial.print("\nStarting FullyFeatureSSL_ESP32 on "); Serial.println(ARDUINO_BOARD);
Serial.println(ASYNC_MQTT_GENERIC_VERSION);
mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
WiFi.onEvent(WiFiEvent);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
#if ASYNC_TCP_SSL_ENABLED
mqttClient.setSecure(MQTT_SECURE);
if (MQTT_SECURE)
{
//mqttClient.addServerFingerprint((const uint8_t[])MQTT_SERVER_FINGERPRINT);
mqttClient.addServerFingerprint((const uint8_t *)MQTT_SERVER_FINGERPRINT);
}
#endif
connectToWifi();
}
void loop()
{
}

2. File defines.h

#ifndef defines_h
#define defines_h
#define _ASYNC_MQTT_LOGLEVEL_ 1
#define WIFI_SSID "yourSSID"
#define WIFI_PASSWORD "yourpass"
#endif //defines_h



Debug Terminal Output Samples

1. FullyFeature_ESP8266 on ESP8266_NODEMCU_ESP12E

This is terminal debug output when running FullyFeatured_ESP8266 on ESP8266_NODEMCU_ESP12E connecting to broker.emqx.io MQTT server.

Starting FullyFeature_ESP8266 on ESP8266_NODEMCU_ESP12E
AsyncMQTT_Generic v1.8.1 for ESP8266
Connecting to Wi-Fi...
Connected to Wi-Fi. IP address: 192.168.2.82
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/ESP8266_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP8266_Pub
  qos: 2
  dup: 0
  retain: 1
  len: 13
  index: 0
  total: 13
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/ESP8266_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 13
  index: 0
  total: 13
Publish received.
  topic: async-mqtt/ESP8266_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 13
  index: 0
  total: 13
Publish received.
  topic: async-mqtt/ESP8266_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 13
  index: 0
  total: 13
Publish acknowledged.
  packetId: 3

2. FullyFeature_ESP32 on ESP32_DEV

This is terminal debug output when running FullyFeatured_ESP32 on ESP32_DEV connecting to broker.emqx.io MQTT server.

Starting FullyFeature_ESP32 on ESP32_DEV
AsyncMQTT_Generic v1.8.1 for ESP32 core v2.0.0+
Connecting to Wi-Fi...
WiFi ready
WiFi STA starting
WiFi STA connected
WiFi connected
IP address: 192.168.2.81
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/ESP32_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP32_Pub
  qos: 2
  dup: 0
  retain: 1
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 10
  index: 0
  total: 10
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/ESP32_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish acknowledged.
  packetId: 3

3. FullyFeatureSSL_ESP32 on ESP32_DEV

This is terminal debug output when running FullyFeaturedSSL_ESP32 on ESP32_DEV connecting to broker.emqx.io secured MQTT server (port 8883).

Starting FullyFeatureSSL_ESP32 on ESP32_DEV
AsyncMQTT_Generic v1.8.1 for ESP32 core v2.0.0+
Connecting to Wi-Fi...
WiFi ready
WiFi STA starting
WiFi STA connected
WiFi connected
IP address: 192.168.2.81
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 8883
PubTopic: async-mqtt/ESP32_SSL_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 2
  dup: 0
  retain: 1
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 10
  index: 0
  total: 10
Publish acknowledged
  packetId: 2
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish acknowledged
  packetId: 3

4. FullyFeatureSSL_ESP32 on ESP32_DEV with ASYNC_MQTT_LOGLEVEL

This is terminal debug output when running FullyFeaturedSSL_ESP32 on ESP32_DEV connecting to broker.emqx.io secured MQTT server (port 8883). The ASYNC_MQTT_LOGLEVEL is set at 4 to show all the debugging messages.

Starting FullyFeatureSSL_ESP32 on ESP32_DEV
AsyncMQTT_Generic v1.8.1 for ESP32 core v2.0.0+
Connecting to Wi-Fi...
WiFi ready
WiFi STA starting
WiFi STA connected
WiFi connected
IP address: 192.168.2.81
Connecting to MQTT...
[AMQTT] CONNECTING
[AMQTT] _onAck: ack len = 303
[AMQTT] _onAck: ack len = 75
[AMQTT] _onAck: ack len = 51
[AMQTT] TCP conn, MQTT CONNECT
[AMQTT] _addFront: new front, packetType = CONNECT
[AMQTT] _handleQueue: snd, packetType # CONNECT , tls: realSent = 61
[AMQTT] _handleQueue: sent / _headsize = 32 / 32
[AMQTT] _handleQueue: released packetType # CONNECT
[AMQTT] _onAck: ack len = 61
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv CONNACK
[AMQTT] CONNACK
Connected to MQTT broker: broker.emqx.io, port: 8883
PubTopic: async-mqtt/ESP32_SSL_Pub
************************************************
Session present: 0
[AMQTT] SUBSCRIBE
[AMQTT] _addBack: new back, packetType = SUBSCRIBE
[AMQTT] _handleQueue: snd, packetType # SUBSCRIBE , tls: realSent = 60
[AMQTT] _handleQueue: sent / _headsize = 31 / 31
Subscribing at QoS 2, packetId: 1
[AMQTT] PUBLISH
[AMQTT] _addBack: new back, packetType = PUBLISH
Publishing at QoS 0
[AMQTT] PUBLISH
[AMQTT] _addBack: new back, packetType = PUBLISH
Publishing at QoS 1, packetId: 2
[AMQTT] PUBLISH
[AMQTT] _addBack: new back, packetType = PUBLISH
Publishing at QoS 2, packetId: 3
************************************************
[AMQTT] _onAck: ack len = 60
[AMQTT] _onData : data rcv len = 5
[AMQTT] _onData: rcv SUBACK
[AMQTT] SUBACK
[AMQTT] SUB released
Subscribe acknowledged.
  packetId: 1
  qos: 2
[AMQTT] _handleQueue: released packetType # SUBSCRIBE
[AMQTT] _handleQueue: snd, packetType # PUBLISH , tls: realSent = 67
[AMQTT] _handleQueue: sent / _headsize = 38 / 38
[AMQTT] _handleQueue: released packetType # PUBLISH
[AMQTT] _handleQueue: snd, packetType # PUBLISH , tls: realSent = 65
[AMQTT] _handleQueue: sent / _headsize = 36 / 36
[AMQTT] _onData : data rcv len = 36
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 2
  dup: 0
  retain: 1
  len: 6
  index: 0
  total: 6
[AMQTT] _addBack: new back, packetType = PUBREC
[AMQTT] _onAck: ack len = 67
[AMQTT] _onData : data rcv len = 38
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 10
  index: 0
  total: 10
[AMQTT] _onAck: ack len = 65
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBACK
[AMQTT] PUB released
Publish acknowledged
  packetId: 2
[AMQTT] _onData : data rcv len = 36
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
[AMQTT] _addBack: new back, packetType = PUBACK
[AMQTT] _handleQueue: released packetType # PUBLISH
[AMQTT] _handleQueue: snd, packetType # PUBLISH , tls: realSent = 65
[AMQTT] _handleQueue: sent / _headsize = 36 / 36
[AMQTT] _onAck: ack len = 65
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBREC
[AMQTT] snd PUBREL
[AMQTT] PUB released
[AMQTT] _insert: new insert, packetType = PUBREL
[AMQTT] _handleQueue: released packetType # PUBLISH
[AMQTT] _handleQueue: snd, packetType # PUBREL , tls: realSent = 33
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _onData : data rcv len = 36
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/ESP32_SSL_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
[AMQTT] _addBack: new back, packetType = PUBREC
[AMQTT] _onAck: ack len = 33
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBCOMP
[AMQTT] PUBREL released
Publish acknowledged
  packetId: 3
[AMQTT] _handleQueue: released packetType # PUBREL
[AMQTT] _handleQueue: snd, packetType # PUBREC , tls: realSent = 33
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _onAck: ack len = 33
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBREL
[AMQTT] _insert: new insert, packetType = PUBCOMP
[AMQTT] _handleQueue: released packetType # PUBREC
[AMQTT] _handleQueue: snd, packetType # PUBCOMP , tls: realSent = 33
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _handleQueue: released packetType # PUBCOMP
[AMQTT] _handleQueue: snd, packetType # PUBACK , tls: realSent = 33
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _handleQueue: released packetType # PUBACK
[AMQTT] _handleQueue: snd, packetType # PUBREC , tls: realSent = 33
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] PUBREC released
[AMQTT] _onAck: ack len = 33
[AMQTT] _onAck: ack len = 66
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBREL
[AMQTT] _insert: new insert, packetType = PUBCOMP
[AMQTT] _handleQueue: released packetType # PUBREC
[AMQTT] _handleQueue: snd, packetType # PUBCOMP , tls: realSent = 33
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _handleQueue: released packetType # PUBCOMP
[AMQTT] PUBREC released
[AMQTT] _onAck: ack len = 33
[AMQTT] PING
[AMQTT] _addBack: new back, packetType = PINGREQ
[AMQTT] _handleQueue: snd, packetType # PINGREQ , tls: realSent = 31
[AMQTT] _handleQueue: sent / _headsize = 2 / 2
[AMQTT] _handleQueue: released packetType # PINGREQ
[AMQTT] _onAck: ack len = 31
[AMQTT] _onData : data rcv len = 2
[AMQTT] _onData: rcv PINGRESP
[AMQTT] PINGRESP

5. FullyFeatureSSL_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720

This is terminal debug output when running FullyFeaturedSSL_WT32_ETH01 on WT32-ETH01 connecting to broker.emqx.io secured MQTT server (port 8883).

Starting FullyFeatureSSL_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720
WebServer_WT32_ETH01 v1.5.1 for core v2.0.0+
AsyncMQTT_Generic v1.8.1 for ESP32 core v2.0.0+
ETH starting
ETH connected
ETH got IP
IP address: 192.168.2.97
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 8883
PubTopic: async-mqtt/WT32_ETH01_SSL_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/WT32_ETH01_SSL_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 15
  index: 0
  total: 15
Publish acknowledged
  packetId: 2
Publish received.
  topic: async-mqtt/WT32_ETH01_SSL_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/WT32_ETH01_SSL_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish acknowledged
  packetId: 3

6. FullyFeature_STM32 on NUCLEO_F767ZI

This is terminal debug output when running FullyFeature_STM32 on STM32F7 NUCLEO_F767ZI connecting to broker.emqx.io MQTT server. The Ethernet loss was tested by disconnecting, then reconnecting the Ethernet cable.

Starting FullyFeature_STM32 on NUCLEO_F767ZI
AsyncMQTT_Generic v1.8.1 for STM32
Connected to network. IP = 192.168.2.118
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/STM32_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 1
  len: 11
  index: 0
  total: 11
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test1
  qos: 0
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test2
  qos: 1
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish acknowledged.
  packetId: 3
Ethernet disconnected   <==== Test disconnect Ethernet very short time
Ethernet reconnected.
Ethernet disconnected   <==== Test disconnect Ethernet long enough time to force MQTT disconnection
Ethernet reconnected.
Disconnected from MQTT. <==== MQTT disconnected and reconnected
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/STM32_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 4
Publishing at QoS 0
Publishing at QoS 1, packetId: 5
Publishing at QoS 2, packetId: 6
************************************************
Subscribe acknowledged.
  packetId: 4
  qos: 2
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 1
  len: 11
  index: 0
  total: 11
Publish acknowledged.
  packetId: 5
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test1
  qos: 0
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test2
  qos: 1
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish acknowledged.
  packetId: 6

7. FullyFeature_STM32 on NUCLEO_F767ZI with ASYNC_MQTT_LOGLEVEL

Starting FullyFeature_STM32 on NUCLEO_F767ZI
AsyncMQTT_Generic v1.8.1 for STM32
Connected to network. IP = 192.168.2.126
Connecting to MQTT...
[AMQTT] CONNECTING
[AMQTT] ClientID = stm32-DEADBEEF3201
[AMQTT] TCP conn, MQTT CONNECT
[AMQTT] _addFront: new front, packetType = CONNECT
[AMQTT] _handleQueue: snd, packetType # CONNECT
[AMQTT] _handleQueue: sent / _headsize = 32 / 32
[AMQTT] _handleQueue: released packetType # CONNECT
[AMQTT] _onAck: ack len = 32
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv CONNACK
[AMQTT] CONNACK
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/STM32_Pub
************************************************
Session present: 0
[AMQTT] SUBSCRIBE
[AMQTT] _addBack: new back, packetType = SUBSCRIBE
[AMQTT] _handleQueue: snd, packetType # SUBSCRIBE
[AMQTT] _handleQueue: sent / _headsize = 27 / 27
Subscribing at QoS 2, packetId: 1
[AMQTT] PUBLISH
[AMQTT] _addBack: new back, packetType = PUBLISH
Publishing at QoS 0
[AMQTT] PUBLISH
[AMQTT] _addBack: new back, packetType = PUBLISH
Publishing at QoS 1, packetId: 2
[AMQTT] PUBLISH
[AMQTT] _addBack: new back, packetType = PUBLISH
Publishing at QoS 2, packetId: 3
************************************************
[AMQTT] _onAck: ack len = 27
[AMQTT] _onData : data rcv len = 5
[AMQTT] _onData: rcv SUBACK
[AMQTT] SUBACK
[AMQTT] SUB released
Subscribe acknowledged.
  packetId: 1
  qos: 2
[AMQTT] _handleQueue: released packetType # SUBSCRIBE
[AMQTT] _handleQueue: snd, packetType # PUBLISH
[AMQTT] _handleQueue: sent / _headsize = 35 / 35
[AMQTT] _handleQueue: released packetType # PUBLISH
[AMQTT] _handleQueue: snd, packetType # PUBLISH
[AMQTT] _handleQueue: sent / _headsize = 37 / 37
[AMQTT] _onData : data rcv len = 37
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 1
  len: 11
  index: 0
  total: 11
[AMQTT] _addBack: new back, packetType = PUBREC
[AMQTT] _onAck: ack len = 72
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBACK
[AMQTT] PUB released
Publish acknowledged.
  packetId: 2
[AMQTT] _onData : data rcv len = 72
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test1
  qos: 0
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test2
  qos: 1
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
[AMQTT] _addBack: new back, packetType = PUBACK
[AMQTT] _handleQueue: released packetType # PUBLISH
[AMQTT] _handleQueue: snd, packetType # PUBLISH
[AMQTT] _handleQueue: sent / _headsize = 37 / 37
[AMQTT] _onAck: ack len = 37
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBREC
[AMQTT] snd PUBREL
[AMQTT] PUB released
[AMQTT] _insert: new insert, packetType = PUBREL
[AMQTT] _handleQueue: released packetType # PUBLISH
[AMQTT] _handleQueue: snd, packetType # PUBREL
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _onData : data rcv len = 37
[AMQTT] _onData: rcv PUBLISH
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
[AMQTT] _addBack: new back, packetType = PUBREC
[AMQTT] _onAck: ack len = 4
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBCOMP
[AMQTT] PUBREL released
Publish acknowledged.
  packetId: 3
[AMQTT] _handleQueue: released packetType # PUBREL
[AMQTT] _handleQueue: snd, packetType # PUBREC
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _onAck: ack len = 4
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBREL
[AMQTT] _insert: new insert, packetType = PUBCOMP
[AMQTT] _handleQueue: released packetType # PUBREC
[AMQTT] _handleQueue: snd, packetType # PUBCOMP
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _handleQueue: released packetType # PUBCOMP
[AMQTT] _handleQueue: snd, packetType # PUBACK
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _handleQueue: released packetType # PUBACK
[AMQTT] _handleQueue: snd, packetType # PUBREC
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] PUBREC released
[AMQTT] _onAck: ack len = 12
[AMQTT] _onData : data rcv len = 4
[AMQTT] _onData: rcv PUBREL
[AMQTT] _insert: new insert, packetType = PUBCOMP
[AMQTT] _handleQueue: released packetType # PUBREC
[AMQTT] _handleQueue: snd, packetType # PUBCOMP
[AMQTT] _handleQueue: sent / _headsize = 4 / 4
[AMQTT] _handleQueue: released packetType # PUBCOMP
[AMQTT] PUBREC released
[AMQTT] _onAck: ack len = 4
[AMQTT] PING
[AMQTT] _addBack: new back, packetType = PINGREQ
[AMQTT] _handleQueue: snd, packetType # PINGREQ
[AMQTT] _handleQueue: sent / _headsize = 2 / 2
[AMQTT] _handleQueue: released packetType # PINGREQ
[AMQTT] _onAck: ack len = 2
[AMQTT] _onData : data rcv len = 2
[AMQTT] _onData: rcv PINGRESP
[AMQTT] PINGRESP
[AMQTT] PING
[AMQTT] _addBack: new back, packetType = PINGREQ
[AMQTT] _handleQueue: snd, packetType # PINGREQ
[AMQTT] _handleQueue: sent / _headsize = 2 / 2
[AMQTT] _handleQueue: released packetType # PINGREQ
[AMQTT] _onAck: ack len = 2
[AMQTT] _onData : data rcv len = 2
[AMQTT] _onData: rcv PINGRESP
[AMQTT] PINGRESP

8. FullyFeatured_STM32_LAN8720 on BLACK_F407VE

This is terminal debug output when running FullyFeatured_STM32_LAN8720 on STM32F4 BLACK_F407VE connecting to broker.emqx.io MQTT server.

Starting FullyFeatured_STM32_LAN8720 on BLACK_F407VE
AsyncMQTT_Generic v1.8.1 for STM32
Connected to network. IP = 192.168.2.132
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/STM32_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 1
  len: 11
  index: 0
  total: 11
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test1
  qos: 0
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test2
  qos: 1
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish received.
  topic: async-mqtt/STM32_Pub
  message: STM32 Test3
  qos: 2
  dup: 0
  retain: 0
  len: 11
  index: 0
  total: 11
Publish acknowledged.
  packetId: 3

9. FullyFeatured_PortentaH7_WiFi on PORTENTA_H7_M7

This is terminal debug output when running FullyFeatured_PortentaH7_WiFi on STM32H7 PORTENTA_H7_M7 using Murata WiFi, connecting to broker.emqx.io MQTT server.

Starting FullyFeatured_PortentaH7_WiFi on PORTENTA_H7_M7
AsyncMQTT_Generic v1.8.1 for Portenta_H7_M7
Connecting to SSID: HueNet1
Connected to SSID: HueNet1
Local IP Address: 192.168.2.134
Signal strength (RSSI):-37 dBm
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/Portenta_H7_WiFi_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/Portenta_H7_WiFi_Pub
  message: Portenta_H7_WiFi Test 3
  qos: 2
  dup: 0
  retain: 1
  len: 23
  index: 0
  total: 23
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/Portenta_H7_WiFi_Pub
  message: Portenta_H7_WiFi Test1
  qos: 0
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish received.
  topic: async-mqtt/Portenta_H7_WiFi_Pub
  message: Portenta_H7_WiFi Test 2
  qos: 1
  dup: 0
  retain: 0
  len: 23
  index: 0
  total: 23
Publish received.
  topic: async-mqtt/Portenta_H7_WiFi_Pub
  message: Portenta_H7_WiFi Test 3
  qos: 2
  dup: 0
  retain: 0
  len: 23
  index: 0
  total: 23
Publish acknowledged.
  packetId: 3

10. FullyFeatured_Portenta_H7_Ethernet on PORTENTA_H7_M7

This is terminal debug output when running FullyFeatured_PortentaH7_Ethernet on STM32H7 PORTENTA_H7_M7, using built-in Ethernet, connecting to broker.emqx.io MQTT server.

Starting FullyFeatured_PortentaH7_Ethernet on PORTENTA_H7_M7
AsyncMQTT_Generic v1.8.1 for Portenta_H7_M7
Connected to network. IP = 192.168.2.133
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/Portenta_H7_Ethernet_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test3
  qos: 2
  dup: 0
  retain: 1
  len: 26
  index: 0
  total: 26
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test1
  qos: 0
  dup: 0
  retain: 0
  len: 26
  index: 0
  total: 26
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test2
  qos: 1
  dup: 0
  retain: 0
  len: 26
  index: 0
  total: 26
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test3
  qos: 2
  dup: 0
  retain: 0
  len: 26
  index: 0
  total: 26
Publish acknowledged.
  packetId: 3
Ethernet disconnected   <==== Test disconnect Ethernet very short time
Ethernet reconnected.
Ethernet disconnected   <==== Test disconnect Ethernet long enough time to force MQTT disconnection
Ethernet reconnected.
[ATCP] setCloseError() to: Connection reset => -14
Disconnected from MQTT. <==== MQTT disconnected and reconnected
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/Portenta_H7_Ethernet_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 4
Publishing at QoS 0
Publishing at QoS 1, packetId: 5
Publishing at QoS 2, packetId: 6
************************************************
Subscribe acknowledged.
  packetId: 4
  qos: 2
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test3
  qos: 2
  dup: 0
  retain: 1
  len: 26
  index: 0
  total: 26
Publish acknowledged.
  packetId: 5
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test1
  qos: 0
  dup: 0
  retain: 0
  len: 26
  index: 0
  total: 26
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test2
  qos: 1
  dup: 0
  retain: 0
  len: 26
  index: 0
  total: 26
Publish received.
  topic: async-mqtt/Portenta_H7_Ethernet_Pub
  message: Portenta_H7_Ethernet Test3
  qos: 2
  dup: 0
  retain: 0
  len: 26
  index: 0
  total: 26
Publish acknowledged.
  packetId: 6

11. FullyFeatured_QNEthernet on TEENSY 4.1 using QNEthernet

This is terminal debug output when running FullyFeatured_QNEthernet on TEENSY 4.1, using built-in Ethernet with QNEthernet Library, connecting to broker.emqx.io MQTT server.

Starting FullyFeatured_QNEthernet on TEENSY 4.1
AsyncMQTT_Generic v1.8.1 for Teensy 4.1 QNEthernet
Initialize Ethernet using static IP => Connected! IP address:192.168.2.222
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/Teensy41_QNEthernet_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/Teensy41_QNEthernet_Pub
  message: Teensy41_QNEthernet_Pub Test3
  qos: 2
  dup: 0
  retain: 1
  len: 29
  index: 0
  total: 29
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/Teensy41_QNEthernet_Pub
  message: Teensy41_QNEthernet_Pub Test1
  qos: 0
  dup: 0
  retain: 0
  len: 29
  index: 0
  total: 29
Publish received.
  topic: async-mqtt/Teensy41_QNEthernet_Pub
  message: Teensy41_QNEthernet_Pub Test2
  qos: 1
  dup: 0
  retain: 0
  len: 29
  index: 0
  total: 29
Publish received.
  topic: async-mqtt/Teensy41_QNEthernet_Pub
  message: Teensy41_QNEthernet_Pub Test3
  qos: 2
  dup: 0
  retain: 0
  len: 29
  index: 0
  total: 29
Publish acknowledged.
  packetId: 3

12. FullyFeatured_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E using ESP8266_ENC28J60 Ethernet

This is terminal debug output when running FullyFeatured_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E, using ENC28J60 Ethernet with lwIP_enc28j60 Library, connecting to broker.emqx.io MQTT server.

Starting FullyFeatured_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E using ESP8266_ENC28J60 Ethernet
AsyncMQTT_Generic v1.8.1 for ESP8266
Connecting to network : .....................................
Ethernet DHCP IP address: 192.168.2.187
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/ESP8266_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test3
  qos: 2
  dup: 0
  retain: 1
  len: 22
  index: 0
  total: 22
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test1
  qos: 0
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test2
  qos: 1
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test3
  qos: 2
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish acknowledged.
  packetId: 3

13. FullyFeatured_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E using ESP8266_W5500 Ethernet

This is terminal debug output when running FullyFeatured_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E, using W5500 Ethernet with lwIP_w5500 Library, connecting to broker.emqx.io MQTT server.

Starting FullyFeatured_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E using ESP8266_W5500 Ethernet
AsyncMQTT_Generic v1.8.1 for ESP8266
Connecting to network : .
Ethernet DHCP IP address: 192.168.2.188
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/ESP8266_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test3
  qos: 2
  dup: 0
  retain: 1
  len: 22
  index: 0
  total: 22
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test1
  qos: 0
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test2
  qos: 1
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish received.
  topic: async-mqtt/ESP8266_Pub
  message: ESP8266_Ethernet Test3
  qos: 2
  dup: 0
  retain: 0
  len: 22
  index: 0
  total: 22
Publish acknowledged.
  packetId: 3

14. FullyFeature_RP2040W on RASPBERRY_PI_PICO_W

This is terminal debug output when running FullyFeature_RP2040W on RASPBERRY_PI_PICO_W, using CYW43439 WiFi, connecting to broker.emqx.io MQTT server.

Starting FullyFeature_RP2040W on RASPBERRY_PI_PICO_W
AsyncMQTT_Generic v1.8.1 for RP2040W CYW43439 WiFi
Connecting to SSID: HueNet2
Connected to SSID: HueNet2
Local IP Address: 192.168.2.180
Signal strength (RSSI):0 dBm
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 1883
PubTopic: async-mqtt/RP2040W_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/RP2040W_Pub
  message: RP2040W Test3
  qos: 2
  dup: 0
  retain: 1
  len: 13
  index: 0
  total: 13
Publish acknowledged.
  packetId: 2
Publish received.
  topic: async-mqtt/RP2040W_Pub
  message: RP2040W Test1
  qos: 0
  dup: 0
  retain: 0
  len: 13
  index: 0
  total: 13
Publish received.
  topic: async-mqtt/RP2040W_Pub
  message: RP2040W Test2
  qos: 1
  dup: 0
  retain: 0
  len: 13
  index: 0
  total: 13
Publish received.
  topic: async-mqtt/RP2040W_Pub
  message: RP2040W Test3
  qos: 2
  dup: 0
  retain: 0
  len: 13
  index: 0
  total: 13
Publish acknowledged.
  packetId: 3

15. FullyFeatureSSL_ESP32_ENC on ESP32_DEV with ESP32_ENC28J60

This is terminal debug output when running FullyFeatureSSL_ESP32_ENC on ESP32_DEV with ESP32_ENC28J60, connecting to broker.emqx.io MQTTS server

Starting FullyFeatureSSL_ESP32_ENC on ESP32_DEV with ESP32_ENC28J60
WebServer_ESP32_ENC v1.5.3 for core v2.0.0+
AsyncMQTT_Generic v1.8.1 for ESP32 core v2.0.0+
ETH starting
ETH connected
ETH got IP
IP address: 192.168.2.96
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 8883
PubTopic: async-mqtt/ESP32_ENC_SSL_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP32_ENC_SSL_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 14
  index: 0
  total: 14
Publish acknowledged
  packetId: 2
Publish received.
  topic: async-mqtt/ESP32_ENC_SSL_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_ENC_SSL_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish acknowledged
  packetId: 3

16. FullyFeatureSSL_ESP32_W5500 on ESP32_DEV with ESP32_W5500

This is terminal debug output when running FullyFeatureSSL_ESP32_W5500 on ESP32_DEV with W5500, connecting to broker.emqx.io MQTTS server

Starting FullyFeatureSSL_ESP32_W5500 on ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
AsyncMQTT_Generic v1.7.0 for ESP32 core v2.0.0+
ETH starting
ETH connected
ETH got IP
IP address: 192.168.2.103
Connecting to MQTT...
Connected to MQTT broker: broker.emqx.io, port: 8883
PubTopic: async-mqtt/ESP32_W5500_SSL_Pub
************************************************
Session present: 0
Subscribing at QoS 2, packetId: 1
Publishing at QoS 0
Publishing at QoS 1, packetId: 2
Publishing at QoS 2, packetId: 3
************************************************
Subscribe acknowledged.
  packetId: 1
  qos: 2
Publish received.
  topic: async-mqtt/ESP32_W5500_SSL_Pub
  qos: 2
  dup: 0
  retain: 1
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_W5500_SSL_Pub
  qos: 0
  dup: 0
  retain: 0
  len: 16
  index: 0
  total: 16
Publish acknowledged
  packetId: 2
Publish received.
  topic: async-mqtt/ESP32_W5500_SSL_Pub
  qos: 1
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish received.
  topic: async-mqtt/ESP32_W5500_SSL_Pub
  qos: 2
  dup: 0
  retain: 0
  len: 6
  index: 0
  total: 6
Publish acknowledged
  packetId: 3


Debug

Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, change the MYSQL_LOGLEVEL to 0

#define ASYNC_MQTT_DEBUG_PORT               Serial

// Debug Level from 0 to 4
#define _ASYNC_MQTT_LOGLEVEL_               1

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.

Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.



Issues

Submit issues to: AsyncMQTT_Generic issues



TO DO

  1. Support ESP8266, STM32, Portenta_H7, Teensy 4.1, RASPBERRY_PI_PICO_W using SSL/TLS
  2. Bug fixing.

DONE

  1. Add support to ESP32 (SSL and non-SSL)
  2. Add support to ESP8266 (non-SSL)
  3. Add support to WT32_ETH01 (SSL and non-SSL)
  4. Add support to Ethernet LAN8742A (non-SSL), using STM32Ethernet library and STM32duino_LwIP library.
  5. Add support to many STM32F4 and STM32F7 (without TLS/SSL) using LAN8720 Ethernet, such as F407xx, NUCLEO_F429ZI, DISCO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG, etc.
  6. Add support to Portenta_H7, using either Murata WiFi or Vision-shield Ethernet
  7. Add support to Teensy 4.1 using QNEthernet Library
  8. Add support to ESP8266 W5x00 using lwIP_w5100 or lwIP_w5500 library
  9. Add support to ESP8266 ENC28J60 using lwIP_enc28j60 library
  10. Add support RASPBERRY_PI_PICO_W with CYW43439 WiFi, using arduino-pico core v2.4.0+
  11. Change to new Forked ESPAsyncTCP library for ESP8266 boards, using WiFi or LwIP Ethernet, with ESP8266 core v3.0.2+ or WiFi with ESP8266 core v2.7.4 to avoid compile errors
  12. Add astyle using allman style. Restyle the library
  13. Add support to ESP32 boards using LwIP W5500 Ethernet, (SSL and non-SSL)
  14. Add support to ESP32 boards using LwIP ENC28J60 Ethernet, (SSL and non-SSL)
  15. Add AsyncWebServer_MQTT for ESP32 example to demo how to use AsyncWebServer and AsyncMQTT_Generic together
  16. Add AsyncWebServer_MQTT_RP2040W example to demo how to use AsyncWebServer_RP2040W and AsyncMQTT_Generic together
  17. Improve README.md so that links can be used in other sites, such as PIO


Contributions and Thanks

  1. Based on and modified from Marvin Roger's async-mqtt-client Library
  2. Thanks to Jens Chr Brynildsen for reporting Missing default case in switch causes #10 leading to v1.7.0
marvinroger
⭐️ Marvin Roger

jenschr
Jens Chr Brynildsen


Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell other people about this library

License

  • Most of the credits go to original author Marvin Roger

  • The library is licensed under MIT


Copyright

  1. Copyright (c) 2017- Marvin Roger
  2. Copyright (c) 2022- Khoi Hoang

asyncmqtt_generic's People

Contributors

dependabot[bot] avatar khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

asyncmqtt_generic's Issues

MQTT + SSL Compilation Error "include/ssl.h" No such file or directory.

Describe the bug

Compile fails when ASYNC_TCP_SSL_ENABLED is set.

Steps to Reproduce

#define ASYNC_TCP_SSL_ENABLED true

in setup()
#if ASYNC_TCP_SSL_ENABLED mqttClient.setSecure(MQTT_SECURE); #endif

and compile in Arduino IDE.

Expected behavior

Compile without error and MQTT over SSL should work.

Actual behavior

Compilation fails with error
C:\Users\lenovo\Documents\Arduino\libraries\ESPAsyncTCP-master\src/tcp_axtls.h:44:10: fatal error: include/ssl.h: No such file or directory 44 | #include "include/ssl.h" | ^~~~~~~~~~~~~~~ compilation terminated.

Information

Please ensure to specify the following:

  • Arduino IDE version (e.g. 1.8.18) or Platform.io version
  • ESP8266 Core Version (e.g. ESP8266 core v3.0.2)
  • Trying to enable MQTT + SSL.
  • Simplest possible steps to reproduce
  • Anything that might be relevant in your opinion, such as:
    • Operating system (Windows)
    • Network configuration

ESP32 PlatformIO Compilation Failure LwIP.h: No such file or directory

Describe the bug

Trying to compile AsyncMqtt_Generic library on ESP32 using PlatformIO.

Steps to Reproduce

Used FullyFeaturedSSL_ESP32.ino and tried compiling the same.

Expected behavior

Successful compile of the sketch.

Actual behavior

Getting error during compiliation.

Debug and AT-command log (if applicable)

` * Executing task in folder ESP32 Testings: C:\Users\lenovo.platformio\penv\Scripts\platformio.exe run

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Library Manager: Installing khoih-prog/AsyncMQTT_Generic @ ^1.6.1
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing me-no-dev/AsyncTCP @ >=1.1.1
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed!
Library Manager: Installing git+https://github.com/khoih-prog/ESPAsyncTCP
git version 2.37.1.windows.1
Cloning into 'C:\Users\lenovo.platformio.cache\tmp\pkg-installing-30z7lx_o'...
remote: Enumerating objects: 51, done.
remote: Counting objects: 100% (51/51), done.
remote: Compressing objects: 100% (46/46), done.
Receiving objects: 100% (51/51)sed 23 (delta 1), pack-reused 0
Receiving objects: 100% (51/51), 51.97 KiB | 403.00 KiB/s, done.
Resolving deltas: 100% (2/2), done.
Library Manager: [email protected]+sha.7cbee24 has been installed!
Library Manager: Installing khoih-prog/AsyncTCP_SSL @ >=1.3.0
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed!
Library Manager: Installing khoih-prog/ESPAsync_WiFiManager @ >=1.14.0
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing me-no-dev/ESP Async WebServer @ >=1.2.3
Unpacking [####################################] 100%
Library Manager: ESP Async [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing khoih-prog/ESP_DoubleResetDetector @ >=1.3.2
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed!
Library Manager: Installing khoih-prog/WebServer_WT32_ETH01 @ >=1.5.1
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed!
Library Manager: Installing git+https://github.com/khoih-prog/STM32AsyncTCP
git version 2.37.1.windows.1
Cloning into 'C:\Users\lenovo.platformio.cache\tmp\pkg-installing-rapgaval'...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 61 (delta 9), reused 53 (delta 9), pack-reused 0
Receiving objects: 100% (61/61), 52.72 KiB | 228.00 KiB/s, done.
Resolving deltas: 100% (9/9), done.
Library Manager: [email protected]+sha.e88a8bc has been installed!
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (5.1.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 @ 3.20004.220825 (2.0.4)
  • tool-esptoolpy @ 1.30300.0 (3.3.0)
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 40 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- AsyncMQTT_Generic @ 1.7.0
    | |-- AsyncTCP @ 1.1.1
    | |-- AsyncTCP_SSL @ 1.3.1
    | | |-- WiFiClientSecure @ 2.0.0
    | | | |-- WiFi @ 2.0.0
    | | | | |-- STM32AsyncTCP @ 1.0.1+sha.e88a8bc
    | |-- ESPAsync_WiFiManager @ 1.14.1
    | | |-- AsyncTCP @ 1.1.1
    | | |-- ESP Async WebServer @ 1.2.3
    | | | |-- AsyncTCP @ 1.1.1
    | | | |-- STM32AsyncTCP @ 1.0.1+sha.e88a8bc
    | | | |-- WiFi @ 2.0.0
    | | | | |-- STM32AsyncTCP @ 1.0.1+sha.e88a8bc
    | | |-- ESP_DoubleResetDetector @ 1.3.2
    | |-- WebServer_WT32_ETH01 @ 1.5.1
    | |-- STM32AsyncTCP @ 1.0.1+sha.e88a8bc
    |-- WiFi @ 2.0.0
    | |-- STM32AsyncTCP @ 1.0.1+sha.e88a8bc
    Building in debug mode
    Compiling .pio\build\esp32dev\src\main.cpp.o
    Updating bootloader headers
    Generating partitions .pio\build\esp32dev\partitions.bin
    esptool.py v3.3
    Flash params set to 0x0220
    Wrote 0x4400 bytes to file .pio\build\esp32dev\patched_bootloader.bin, ready to flash to offset 0x1000
    Compiling .pio\build\esp32dev\libff3\AsyncTCP\AsyncTCP.cpp.o
    Compiling .pio\build\esp32dev\lib154\STM32AsyncTCP\AsyncPrinter.cpp.o
    Compiling .pio\build\esp32dev\lib154\STM32AsyncTCP\STM32AsyncTCP.cpp.o
    In file included from .pio/libdeps/esp32dev/AsyncMQTT_Generic/src/AsyncMqtt_Generic.h:34,
    from src/main.cpp:33:
    .pio/libdeps/esp32dev/AsyncMQTT_Generic/src/AsyncMqttClient_Generic.hpp:79:6: warning: #warning ESP32 ASYNC_TCP_SSL_ENABLED [-Wcpp]
    #warning ESP32 ASYNC_TCP_SSL_ENABLED
    ^~~~~~~
    In file included from .pio/libdeps/esp32dev/STM32AsyncTCP/src/AsyncPrinter.h:26,
    from .pio/libdeps/esp32dev/STM32AsyncTCP/src/AsyncPrinter.cpp:22:
    .pio/libdeps/esp32dev/STM32AsyncTCP/src/STM32AsyncTCP.h:29:10: fatal error: LwIP.h: No such file or directory


#include <LwIP.h>
^~~~~~~~
compilation terminated.
*** [.pio\build\esp32dev\lib154\STM32AsyncTCP\AsyncPrinter.cpp.o] Error 1
In file included from .pio/libdeps/esp32dev/STM32AsyncTCP/src/STM32AsyncTCP.cpp:75:
.pio/libdeps/esp32dev/STM32AsyncTCP/src/STM32AsyncTCP.h:29:10: fatal error: LwIP.h: No such file or directory



#include <LwIP.h>
^~~~~~~~
compilation terminated.
*** [.pio\build\esp32dev\lib154\STM32AsyncTCP\STM32AsyncTCP.cpp.o] Error 1
======================================================================================= [FAILED] Took 64.87 seconds =======================================================================================`

Information

Please ensure to specify the following:

  • Platform IO 6.1.4
  • ESP32 2.0.4
  • Compile FullyFeaturedSSL_ESP32 sketch
  • Add these entries to platformio.ini and compile the sketch
    monitor_speed = 115200 monitor_filters = esp32_exception_decoder ; For Debugging crashes build_type = debug ; For Debugging crashes board_build.filesystem = littlefs lib_deps = khoih-prog/AsyncMQTT_Generic @ ^1.6.1
  • Running on Windows 10

Missing default case in switch causes

Describe the bug

In the example file "FullyFeatured_ESP32.ino", the Switch case does not have a "default" to catch anything not handled.

Steps to Reproduce

Compile example "FullyFeatured_ESP32.ino" in Arduino IDE with board set to "Adafruit Feather ESP32-S2".

Expected behavior

Expected the file to compile without errors

Actual behavior

Error compiling....

Solution

Just add a default case for the WiFiEvent(WiFiEvent_t event) method outside the "if" so that both versions has a default so you don't hqve to handle all possible cases:

default: break;

Information

Arduino IDE version: 1.8.19
ESP32 Core Version 2.0.4
OS: OSX 11.6

Context:
Trying to make the basic example compile

Additional context

Relevant error message:

/Users/jensa/Documents/Arduino/FullyFeatured_ESP32/FullyFeatured_ESP32.ino: In function 'void WiFiEvent(arduino_event_id_t)':
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_SCAN_DONE' not handled in switch [-Werror=switch]
   switch (event)
          ^
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_STA_STOP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_START' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STOP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STACONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STADISCONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_AP_GOT_IP6' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WIFI_FTM_REPORT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_START' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_STOP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_CONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_DISCONNECTED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_GOT_IP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_ETH_GOT_IP6' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_SUCCESS' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_FAILED' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_TIMEOUT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_PIN' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_WPS_ER_PBC_OVERLAP' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_SCAN_DONE' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_FOUND_CHANNEL' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_GOT_SSID_PSWD' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_SC_SEND_ACK_DONE' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_INIT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_DEINIT' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_START' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_END' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_CRED_RECV' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_CRED_FAIL' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_PROV_CRED_SUCCESS' not handled in switch [-Werror=switch]
FullyFeatured_ESP32:51:10: error: enumeration value 'ARDUINO_EVENT_MAX' not handled in switch [-Werror=switch]
cc1plus: some warnings being treated as errors
Multiple libraries were found for "WiFi.h"
 Used: /Users/jensa/Library/Arduino15/packages/esp32/hardware/esp32/2.0.4/libraries/WiFi
 Not used: /Applications/Arduino.app/Contents/Java/libraries/WiFi
Using library WiFi at version 2.0.0 in folder: /Users/jensa/Library/Arduino15/packages/esp32/hardware/esp32/2.0.4/libraries/WiFi 
Using library AsyncMQTT_Generic at version 1.6.1 in folder: /Users/jensa/Documents/Arduino/libraries/AsyncMQTT_Generic 
Using library AsyncTCP at version 1.1.1 in folder: /Users/jensa/Documents/Arduino/libraries/AsyncTCP 
exit status 1
enumeration value 'ARDUINO_EVENT_WIFI_SCAN_DONE' not handled in switch [-Werror=switch]

I can´t install library in platformio. Error to get ESPAsyncTCP

Hi,

when I install librery in platformio appear this error:

Library Manager: Installing git+https://github.com/khoih-prog/ESPAsyncTCP
git version 2.34.0.windows.1
Cloning into 'C:\Users\msanc.platformio.cache\tmp\pkg-installing-qo24k_s0'...
fatal: invalid branch name: init.defaultBranch =
Error: VCS: Could not process command ['git', 'clone', '--recursive', '--depth', '1', 'https://github.com/khoih-prog/ESPAsyncTCP', 'C:\Users\msanc\.platformio\.cache\tmp\pkg-installing-qo24k_s0']

This appear to be that deafultBranch is inexsitent in ESPAsyncTCP proyect

Platform.io version 6.1.5

  • ESP32 v2.0.5
  • OS WIndows 11

Regards

Dependencies fail to load in PlatformIO

Describe the bug

When building a project for Portenta in PlatformIO depending on AsyncMQTT_Generic, multiple errors are thrown, all seems to be related to missing stm32_def.h file. Possibly because the khoih-prog/Portenta_H7_AsyncTCP dependency fails to install.

Steps to Reproduce

  • Create new project fro Portenta H7 in platform IO
  • Add AsynqMQTT_Generic to the project using project manager.
  • Build.

Expected behavior

The blank program should build without issues

Actual behavior

Fails to build.
Dependcy khoih-prog/Portenta_H7_AsyncTCP fails to install
Multiple errors related to missing stm32_def.h file

When using the included platformio.ini file, the build crashes with the following info/error:
Library Manager: Installing stm32duino/STM32duino STM32Ethernet @ >=1.2.0 Error: Could not find the package with 'stm32duino/STM32duino STM32Ethernet @ >=1.2.0' requirements for your system 'windows_amd64'

Also, possibly unrelated, Vscode displays the following error during installation of the libraray:
Error: Multiple requests to rebuild the project "<name>" index have been received! Automatic index rebuilding process has been terminated for 10 minutes.

Information

  • Platform IO version: Core 6.0.1·Home 3.4.1
  • Vscode version: 1.67.2
  • Windows 10 Business

Additional context

It looks like the repository path for the Portenta_H7_AsyncTCP libraray is messed up on the platform.io site: (https://registry.platformio.org/libraries/khoih-prog/Portenta_H7_AsyncTCP)

image

Why include implementation in header?

Describe the bug

The reason for we can only include AsyncMqtt_Generic.h in one .cpp or .ino is because it contains not only headers but also implementations. In particular, AsyncMqtt_Generic.h:

#include "AsyncMqttClient_Generic.hpp"
#include "AsyncMqttClient_Generic_Impl.h"

Which AsyncMqttClient_Generic_Impl.h is actually implementation instead of header. In common practice, the AsyncMqttClient_Generic_Impl.h should end with .cpp/.c instead of .h. And use compiler configuration/compile script to let compiler compile it as object(and later linking) explicitly.
I'm curious why you take this approach to put header and implementation together. Is that something I missed?

And here's a problem: this approach makes abstracting/inheriting or even simply include in multiple files within same project impossible without modifying your code. For example:

  1. include AsyncMqtt_Generic.h in two cpp(ino is actually cpp) of same project will result double definition.
  2. include only AsyncMqttClient_Generic.hpp will result implementation not found, even if I use some trick to let compiler compile the AsyncMqttClient_Generic_Impl.h. I can do this in AsyncMqttClient_Generic_Impl.h for latter to make things work:
#include "AsyncMqttClient_Generic.hpp"

But then I have to modify your code. It's not "generic" anymore. So may I ask why would you take this approach?

Documentation

Sorry, found no other way.

Where are the parameters explained in your documentation?
e.g. mqttClient.publish(PubTopic, 0, true, "ESP32 Test");

SSL for ESP8266

Hello! with async mqtt client library, I can use SSL connection with ESP8266 using a ported version of ESPAsyncTCP is not possible with your release? It can be very usefull with 3.0.2 ESP8266 core

Combining Async_MQTT Generic and Portenta_H7_AsyncWebServer fails

Hi, back after some tests.

Combined 2 examples, exactly one-on-one: Portenta_H7_AsyncWebServer plus AsyncMQTT_Generic
Same issue as with the PubSubClinet library: Mbed OS crashes after webserver html calls within 1-2 minutes.
Problem : Both Async libraries can not co-exists.

Can' t post the issue at the Portenta_H7_AsyncWebServer git as its archived after our last mail exchange.

Jay

Arduino IDE 1.8.18
Arduino IDE 2.0
Portenta H7 rev2
lib Portenta_H7_AsyncWebServer 1.4.2
lib Portenta_H7_AsyncTCP 1.4.0
lib AsyncMQTT_Generic 1.8.0

Stuck on this error

platform.ini file as below

[common]
# ------------------------------------------------------------------------------
# PLATFORM:
#   !! DO NOT confuse platformio's ESP8266 development platform with Arduino core for ESP8266
#   platformIO 1.5.0 = arduino core 2.3.0
#   platformIO 1.6.0 = arduino core 2.4.0
#   platformIO 1.7.3 = arduino core 2.4.1
#   platformIO 1.8.0 = arduino core 2.4.2
# ------------------------------------------------------------------------------
esp8266_platform_2_3_0 = [email protected]
esp8266_platform_2_4_0 = [email protected]
esp8266_platform_2_4_1 = [email protected]
esp8266_platform_2_4_2 = [email protected]

[env]
framework = arduino
upload_speed = 460800
monitor_speed = 38400


[env:esp8266_make]
platform = ${common.esp8266_platform_2_4_0}
# platform = ${common.esp8266_platform_2_4_1}
board = esp01_1m
#board = esp01
#board = esp12e
#board = esp01
#board_build.f_cpu = 80000000L

#for BTX type ic Z logo ic
board_build.flash_mode = dout 
build_flags = 
    -g 
    #-D DEBUG_FAUXMO=Serial 
    #-D  DEBUG_FAUXMO_VERBOSE_TCP=0 
    #-D  DEBUG_FAUXMO_VERBOSE_UDP=0 
    -D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
    #-D  PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
    #-D PUYA_SUPPORT=1
    #-D XMC_SUPPORT=1
lib_deps =   
     vintlabs/FauxmoESP @ 3.4
     bblanchon/ArduinoJson @ 6.12
     knolleary/PubSubClient @ 2.8
     me-no-dev/ESP Async WebServer @ 1.2.2
     me-no-dev/ESPAsyncTCP @ 1.2.2
     me-no-dev/AsyncTCP @ 1.1.1
     khoih-prog/AsyncMQTT_Generic @ 1.8.0

lib_ignore =
   STM32Ethernet
   STM32duino LwIP
    WiFi
   Teensy41_AsyncTCP
   ESPAsync_WiFiManager
   WebServer_WT32_ETH01
   STM32AsyncTCP
   AsyncTCP_SSL
   AsyncTCP_RP2040W
   Portenta_H7_AsyncTCP
   WebServer_ESP32_W5500
   WebServer_ESP32_ENC

In file included from lib/async-mqtt-client-develop/src/AsyncMqttClient.hpp:29:0,
from lib/async-mqtt-client-develop/src/AsyncMqttClient.cpp:1:

lib/async-mqtt-client-develop/src/AsyncMqttClient.cpp: In member function 'uint16_t AsyncMqttClient::publish(const char*, uint8_t, bool, const char*, size_t, bool, uint16_t)':
lib/async-mqtt-client-develop/src/AsyncMqttClient/Helpers.hpp:47:33: error: 'class EspClass' has no member named 'getMaxFreeBlockSize'
   #define GET_FREE_MEMORY() ESP.getMaxFreeBlockSize()
                                 ^
lib/async-mqtt-client-develop/src/AsyncMqttClient.cpp:739:30: note: in expansion of macro 'GET_FREE_MEMORY'
   if (_state != CONNECTED || GET_FREE_MEMORY() < MQTT_MIN_FREE_MEMORY) return 0;
                              ^
Compiling .pio/build/esp8266_make/lib500/async-mqtt-client-develop/AsyncMqttClient/Packets/Out/Connect.cpp.o
*** [.pio/build/esp8266_make/lib500/async-mqtt-client-develop/AsyncMqttClient.cpp.o] Error 1

ESP8266 SSL example

Is your feature request related to a problem? Please describe.
Please provide support for SSL support also for ESP8266

SSL Connection to a MQTT broker triggers watchdog - WT32_ETH01 board

Hi,
I am not sure if its a bug or any mistake by me but thought this post will be usefull at the end.

Using:
WT32_ETH01 board
Arduino 1.8.19
AsyncMQTT_Generic v.1.4.0

Trying to connect to MQTT broker, myqtthub.com with SSL, using the /examples/WT32_ETH01/.
Only changed these from the original example code:

#define MQTT_HOST "node02.myqtthub.com"

const uint8_t MQTT_SERVER_FINGERPRINT[] = {0x97, 0xE2, 0x30, 0xF9, 0xAE, 0x79, 0x16, 0xED, 0xDB, 0x2F, 0x9B, 0x78, 0xE5, 0xF2, 0x6D, 0x2C, 0x07, 0x6E, 0xCD, 0x2F};

Get the fingerprint of the server from this adress: (got from the last certificate page, at top, not sure if it is ok)

https://crt.sh/?q=node02.myqtthub.com

When run the debug shows:

Starting FullyFeatureSSL_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720
WebServer_WT32_ETH01 v1.4.0 for core v1.0.6-
AsyncMQTT_Generic v1.4.0 for ESP32 core v1.0.6-
ETH Connected
ETH connected
IP address: 
192.168.1.145
Connecting to MQTT...
E (18585) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (18585) task_wdt:  - async_tcp_ssl (CPU 0/1)
E (18585) task_wdt: Tasks currently running:
E (18585) task_wdt: CPU 0: IDLE0
E (18585) task_wdt: CPU 1: IDLE1
E (18585) task_wdt: Aborting.
abort() was called at PC 0x401505b0 on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x40088708:0x3ffbf880 0x40088985:0x3ffbf8a0 0x401505b0:0x3ffbf8c0 0x40086f1d:0x3ffbf8e0 0x401654d3:0x3ffbc260 0x4015201f:0x3ffbc280 0x4008b145:0x3ffbc2a0 0x40089996:0x3ffbc2c0

Rebooting...
ets Jun  8 2016 00:22:57

When tried without a secure(SSL) connection it is working.
Even if the fingerprint code is wrong, it should show that it can not connect, instead when trying to connect watchdog triggers.

I could not find any other info to publish here.
If doing something wrong, any info will be usefull, thank you.

[OBSERVED] disconnection after router reboot ESP8266 : with 512 ESP MIN MEMORY paramter

Describe the bug

A clear and concise description of what the bug is.
my observation:
following configuration with 512 helps mqtt to get re-connect again when router is restarted and net gets online, but when i put 4096 , it dont reconnect automatically
in file : AsyncMqttClient_Generic.hpp
#ifndef MQTT_MIN_FREE_MEMORY
// #define MQTT_MIN_FREE_MEMORY 4096
#define MQTT_MIN_FREE_MEMORY 512
#endif

Steps to Reproduce

to reproduce the error
following is the hardware

Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz

Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...

Expected behavior

expected behaviour should be it should autoconnect with 4096 value [ i may be not aware of that #define parameter, please enlighten is i am being blind to any obvious thing, thanks ]

Actual behavior

behaviour should be autoconected after router it rebooted , you can check this scene by running library on esp8266 as above and then reboot router from web ui control panel, and observe the disconnection in serial logs

Debug and AT-command log (if applicable)

[ logs when 512 size connect logs ]

12:58:55:641] Connecting to MQTT...␍␊
[12:58:55:666] <removed ip address here intentionally>␍␊
[12:58:55:823] Connected to MQTT broker: [MAIN] Free heap: 38248 bytes␊
[12:59:02:691] [MAIN] Free heap: 38656 bytes␊
[12:59:07:692] [MAIN] Free heap: 38656 bytes␊

[ log when 4096]
first it connected automtically but when in restart it it show freq disconnection

[13:11:04:773] Connecting to MQTT...␍␊
[13:11:04:797] <broker hidden>
[13:11:04:825] Connected to MQTT broker: [MAIN] Free heap: 40656 bytes␊
[13:11:14:435] [MAIN] Free heap: 40656 bytes␊
[13:11:19:437] [MAIN] Free heap: 40656 bytes␊
[13:11:24:437] [MAIN] Free heap: 40656 bytes␊
[13:11:29:439] [MAIN] Free heap: 37456 bytes␊
[13:11:34:440] [MAIN] Free heap: 37456 bytes␊
[13:11:38:925] Disconnected from MQTT.␍␊
[13:11:39:441] [MAIN] Free heap: 41816 bytes␊
[13:11:44:442] [MAIN] Free heap: 40144 bytes␊
[13:11:49:590] [MAIN] Free heap: 40144 bytes␊
[13:11:52:490] 192.168.0.102␍␊
[13:11:52:507] Connecting to MQTT...␍␊
[13:11:52:531] <broker hidden>
[13:11:54:591] [MAIN] Free heap: 37224 bytes␊
[13:11:59:515] Disconnected from MQTT.␍␊
[13:11:59:592] [MAIN] Free heap: 38448 bytes␊
[13:12:01:515] Connecting to MQTT...␍␊
[13:12:01:541] <broker hidden>
[13:12:04:593] [MAIN] Free heap: 38448 bytes␊
[13:12:08:515] Disconnected from MQTT.␍␊
[13:12:09:594] [MAIN] Free heap: 38448 bytes␊
[13:12:10:515] Connecting to MQTT...␍␊
[13:12:10:546] <broker hidden>
[13:12:14:596] [MAIN] Free heap: 38448 bytes␊

Screenshots

NA

Information

Please ensure to specify the following:

my included libraries:

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqtt_Generic.h>
#include <Hash.h>

#include <ESP8266WiFiMulti.h>
#include <ESPAsyncWebServer.h>
#include "fauxmoESP.h"
#include <DNSServer.h>
#include <PubSubClient.h>
#include <FS.h>
#include <ArduinoJson.h>

platform ini file as below

#platform = ${common.esp8266_platform_2_4_0}
platform = ${common.esp8266_platform_2_7_0}
# platform = ${common.esp8266_platform_2_4_1}
board = esp01_1m
#board = esp01
#board = esp12e
#board = esp01
#board_build.f_cpu = 80000000L

#for BTX type ic Z logo ic
board_build.flash_mode = dout 
build_flags = 
    -g 
    #-D DEBUG_FAUXMO=Serial 
    #-D  DEBUG_FAUXMO_VERBOSE_TCP=0 
    #-D  DEBUG_FAUXMO_VERBOSE_UDP=0 
    -D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
    #-D  PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
    #-D PUYA_SUPPORT=1
    #-D XMC_SUPPORT=1
lib_deps =   
    vintlabs/FauxmoESP @ 3.4
    bblanchon/ArduinoJson @ 6.12
    knolleary/PubSubClient @ 2.8
    me-no-dev/ESP Async WebServer @ 1.2.2
    ; me-no-dev/ESPAsyncTCP @ 1.2.2
    me-no-dev/AsyncTCP @ 1.1.1
    khoih-prog/AsyncMQTT_Generic @ 1.8.0

code snippets from my code

void onMqttConnect(bool sessionPresent)
{
	String node = "client" + String(ESP.getChipId());
	String nodeid = node + " " + WiFi.localIP().toString();

	node = String(ESP.getChipId());

	String topicx = getParameterFromJson("topicname", "/config.json");
	String nodex = "{\"node\":\"" + node + "\",\"topic\":\"" + topicx + "\",\"client\":\"" + nodeid + "\"}";
	mqttClient.publish("modelStatus", 0, false, nodex.c_str());

	mqttClient.subscribe(topicx.c_str(), 2);

	Serial.print("Connected to MQTT broker: ");
}


void connectToMqtt()
{
	Serial.println("Connecting to MQTT...");
	// mqttClient.disconnect();
	mqttClient.connect();
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
{
	(void)reason;

	Serial.println("Disconnected from MQTT.");

	if (WiFi.isConnected())
	{
		mqttReconnectTimer.once(2, connectToMqtt);
	}
}

//in setup>>

wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
// mqttClient.setServer(MQTT_HOST, MQTT_PORT);
// String broker = getParameterFromJson("broker","/config.json");
// uint16_t port = 1883;
// Serial.println(broker);
mqttClient.setServer("brokerdomain_name", 1883);
// mqttClient.setServer("192.168.0.110", 1883);

connectToWifi();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.