Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
v1.7.0 to fix ESP32/ESP8266 compile error
Browse files Browse the repository at this point in the history
### Releases v1.7.0

1. Fix ESP32 compile error. Check [Missing default case in switch causes #10](#10)
2. Change to new [Forked ESPAsyncTCP library](https://github.com/khoih-prog/ESPAsyncTCP) for ESP8266 boards, using WiFi or LwIP Ethernet, with [ESP8266 core v3.0.2+](https://github.com/esp8266/Arduino/releases/tag/3.0.2) or WiFi with [ESP8266 core v2.7.4](https://github.com/esp8266/Arduino/releases/tag/2.7.4) to avoid compile errors
  • Loading branch information
khoih-prog authored Sep 14, 2022
1 parent 9e90dc5 commit 5fcfe1a
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 26 deletions.
63 changes: 51 additions & 12 deletions src/AsyncMqttClient_Generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
Version: 1.6.1
Version: 1.7.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -23,6 +23,7 @@
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
*****************************************************************************************************************************/

#pragma once
Expand All @@ -41,15 +42,15 @@

/////////////////////////////////////////////////////////

#define ASYNC_MQTT_GENERIC_SHORT_VERSION "AsyncMQTT_Generic v1.6.1"
#define ASYNC_MQTT_GENERIC_SHORT_VERSION "AsyncMQTT_Generic v1.7.0"

/////////////////////////////////////////////////////////

#define ASYNC_MQTT_GENERIC_VERSION_MAJOR 1
#define ASYNC_MQTT_GENERIC_VERSION_MINOR 6
#define ASYNC_MQTT_GENERIC_VERSION_PATCH 1
#define ASYNC_MQTT_GENERIC_VERSION_MINOR 7
#define ASYNC_MQTT_GENERIC_VERSION_PATCH 0

#define ASYNC_MQTT_GENERIC_VERSION_INT 1006001
#define ASYNC_MQTT_GENERIC_VERSION_INT 1007000

/////////////////////////////////////////////////////////

Expand Down Expand Up @@ -81,19 +82,46 @@
#endif

#include <freertos/semphr.h>

/////////////////////////////////////////////////////////

#elif defined(ESP8266)

// Use ESP8266 core v2.7.4- for SSL as new cores don't use axtls anymore
// Use core v3.0.2+ for LwIP Ethernet W5500lwIP, W5100lwIP and ENC28J60lwIP libraries
// Must use KH forked ESPAsyncTCP library or compile error
#if ( (USING_W5500 || USING_W5100 || USING_ENC28J60) && (ARDUINO_ESP8266_GIT_VER != 0xcf6ff4c4) )
#error You must use LwIP Ethernet with ESP8266 core v3.0.2+ or error
#endif

#if ( (ARDUINO_ESP8266_GIT_VER == 0xcf6ff4c4) || (ARDUINO_ESP8266_GIT_VER == 0xcbf44fb3) || \
(ARDUINO_ESP8266_GIT_VER == 0xefb0341a) )
#if ASYNC_TCP_SSL_ENABLED
// Can't use SSL yet with core v3.0.0, v3.0.1 and v3.0.2. axtls replaced by bearssl
// To be supported in the future ???
#undef ASYNC_TCP_SSL_ENABLED
#define ASYNC_TCP_SSL_ENABLED false
#warning Disable ESP8266 ASYNC_TCP_SSL_ENABLED for core v3.0.0+
#endif
#endif

#if ASYNC_TCP_SSL_ENABLED
//#include <ESPAsyncTCP_SSL.h>
#include <ESPAsyncTCP.h>

// Must use the forked version or error
#include <ESPAsyncTCP.h> // https://github.com/khoih-prog/ESPAsyncTCP

//#warning ESP8266 ASYNC_TCP_SSL_ENABLED
#error ESP8266 ASYNC_TCP_SSL_ENABLED not ready yet

#else
#include <ESPAsyncTCP.h>

// Must use the forked version or error
#include <ESPAsyncTCP.h> // https://github.com/khoih-prog/ESPAsyncTCP

#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP8266")
#endif

/////////////////////////////////////////////////////////

#elif ( ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) && defined(ARDUINO_ARCH_MBED) )

Expand All @@ -112,6 +140,8 @@
#endif

#define ASYNC_MQTT_USING_PORTENTA_H7 true

/////////////////////////////////////////////////////////

#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
Expand All @@ -129,6 +159,8 @@

#define ASYNC_MQTT_USING_STM32 true

/////////////////////////////////////////////////////////

#elif ( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) )

#if ASYNC_TCP_SSL_ENABLED
Expand All @@ -142,6 +174,8 @@
#endif

#define ASYNC_MQTT_USING_TEENSY41_QNETHERNET true

/////////////////////////////////////////////////////////

#elif ( defined(ARDUINO_RASPBERRY_PI_PICO_W) )

Expand All @@ -155,19 +189,21 @@
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for RP2040W CYW43439 WiFi")
#endif

#define ASYNC_MQTT_USING_RP2040W true
#define ASYNC_MQTT_USING_RP2040W true

/////////////////////////////////////////////////////////

#else
#error Platform not supported
#endif


/////////////////////////////////////////////////////////

#if ASYNC_TCP_SSL_ENABLED
#if (ESP32)
#include <tcp_mbedtls.h>
#elif defined(ESP8266)
#elif ( defined(ESP8266) && (ARDUINO_ESP8266_GIT_VER == 0x2843a5ac) )
// ESP8266 core v2.7.4 still has tcp_axtls support
#include <tcp_axtls.h>
#elif ASYNC_MQTT_USING_PORTENTA_H7
#include <tcp_axtls.h>
Expand All @@ -176,7 +212,10 @@
#elif ASYNC_MQTT_USING_TEENSY41_QNETHERNET
#include <tcp_axtls.h>
#elif ASYNC_MQTT_USING_RP2040W
#include <tcp_axtls.h>
#include <tcp_axtls.h>
#else
#undef ASYNC_TCP_SSL_ENABLED
#define ASYNC_TCP_SSL_ENABLED false
#endif

#define SHA1_SIZE 20
Expand Down
7 changes: 4 additions & 3 deletions src/AsyncMqttClient_Generic_Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
Version: 1.6.1
Version: 1.7.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -23,6 +23,7 @@
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -59,8 +60,8 @@

/////////////////////////////////////////////////////////

#define AMQTT_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
#define AMQTT_SSL_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
#define AMQTT_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
#define AMQTT_SSL_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }

#define AMQTT_ASSERT( a ) do{ if(!(a)){AMQTT_PRINTF("ASSERT: %s %u \n", __FILE__, __LINE__);}}while(0)

Expand Down
53 changes: 43 additions & 10 deletions src/AsyncMqttClient_Generic_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
Version: 1.6.1
Version: 1.7.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -23,6 +23,7 @@
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -509,56 +510,86 @@ void AsyncMqttClient::_onData(char* data, size_t len)
case AsyncMqttClientInternals::PacketType.CONNACK:
AMQTT_LOGINFO("_onData: rcv CONNACK");

_currentParsedPacket = new AsyncMqttClientInternals::ConnAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onConnAck, this, std::placeholders::_1, std::placeholders::_2));
_currentParsedPacket =
new AsyncMqttClientInternals::ConnAckPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onConnAck, this,
std::placeholders::_1, std::placeholders::_2));
_client.setRxTimeout(0);
break;

case AsyncMqttClientInternals::PacketType.PINGRESP:
AMQTT_LOGINFO("_onData: rcv PINGRESP");

_currentParsedPacket = new AsyncMqttClientInternals::PingRespPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPingResp, this));
_currentParsedPacket =
new AsyncMqttClientInternals::PingRespPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onPingResp, this));
break;

case AsyncMqttClientInternals::PacketType.SUBACK:
AMQTT_LOGINFO("_onData: rcv SUBACK");

_currentParsedPacket = new AsyncMqttClientInternals::SubAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onSubAck, this, std::placeholders::_1, std::placeholders::_2));
_currentParsedPacket =
new AsyncMqttClientInternals::SubAckPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onSubAck, this,
std::placeholders::_1, std::placeholders::_2));
break;

case AsyncMqttClientInternals::PacketType.UNSUBACK:
AMQTT_LOGINFO("_onData: rcv UNSUBACK");

_currentParsedPacket = new AsyncMqttClientInternals::UnsubAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onUnsubAck, this, std::placeholders::_1));
_currentParsedPacket =
new AsyncMqttClientInternals::UnsubAckPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onUnsubAck, this,
std::placeholders::_1));
break;

case AsyncMqttClientInternals::PacketType.PUBLISH:
AMQTT_LOGINFO("_onData: rcv PUBLISH");

_currentParsedPacket = new AsyncMqttClientInternals::PublishPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onMessage, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9), std::bind(&AsyncMqttClient::_onPublish, this, std::placeholders::_1, std::placeholders::_2));
_currentParsedPacket =
new AsyncMqttClientInternals::PublishPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onMessage, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4, std::placeholders::_5, std::placeholders::_6,
std::placeholders::_7, std::placeholders::_8, std::placeholders::_9),
std::bind(&AsyncMqttClient::_onPublish, this, std::placeholders::_1,
std::placeholders::_2));
break;

case AsyncMqttClientInternals::PacketType.PUBREL:
AMQTT_LOGINFO("_onData: rcv PUBREL");

_currentParsedPacket = new AsyncMqttClientInternals::PubRelPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubRel, this, std::placeholders::_1));
_currentParsedPacket =
new AsyncMqttClientInternals::PubRelPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onPubRel, this,
std::placeholders::_1));
break;

case AsyncMqttClientInternals::PacketType.PUBACK:
AMQTT_LOGINFO("_onData: rcv PUBACK");

_currentParsedPacket = new AsyncMqttClientInternals::PubAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubAck, this, std::placeholders::_1));
_currentParsedPacket =
new AsyncMqttClientInternals::PubAckPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onPubAck, this,
std::placeholders::_1));
break;

case AsyncMqttClientInternals::PacketType.PUBREC:
AMQTT_LOGINFO("_onData: rcv PUBREC");

_currentParsedPacket = new AsyncMqttClientInternals::PubRecPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubRec, this, std::placeholders::_1));
_currentParsedPacket =
new AsyncMqttClientInternals::PubRecPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onPubRec, this,
std::placeholders::_1));
break;

case AsyncMqttClientInternals::PacketType.PUBCOMP:
AMQTT_LOGINFO("_onData: rcv PUBCOMP");

_currentParsedPacket = new AsyncMqttClientInternals::PubCompPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubComp, this, std::placeholders::_1));
_currentParsedPacket =
new AsyncMqttClientInternals::PubCompPacket(&_parsingInformation,
std::bind(&AsyncMqttClient::_onPubComp, this,
std::placeholders::_1));
break;

default:
Expand Down Expand Up @@ -590,6 +621,7 @@ void AsyncMqttClient::_onData(char* data, size_t len)
_onPingResp();
}
}

break;

case AsyncMqttClientInternals::BufferState::VARIABLE_HEADER:
Expand All @@ -602,6 +634,7 @@ void AsyncMqttClient::_onData(char* data, size_t len)

default:
currentBytePosition = len;
break;
}
} while (currentBytePosition != len);
}
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncMqtt_Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
Version: 1.6.1
Version: 1.7.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -23,6 +23,7 @@
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
*****************************************************************************************************************************/

#pragma once
Expand Down

0 comments on commit 5fcfe1a

Please sign in to comment.