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

Commit 5fcfe1a

Browse files
authored
v1.7.0 to fix ESP32/ESP8266 compile error
### 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
1 parent 9e90dc5 commit 5fcfe1a

File tree

4 files changed

+100
-26
lines changed

4 files changed

+100
-26
lines changed

src/AsyncMqttClient_Generic.hpp

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
1111
12-
Version: 1.6.1
12+
Version: 1.7.0
1313
1414
Version Modified By Date Comments
1515
------- ----------- ---------- -----------
@@ -23,6 +23,7 @@
2323
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
2424
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
2525
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
26+
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
2627
*****************************************************************************************************************************/
2728

2829
#pragma once
@@ -41,15 +42,15 @@
4142

4243
/////////////////////////////////////////////////////////
4344

44-
#define ASYNC_MQTT_GENERIC_SHORT_VERSION "AsyncMQTT_Generic v1.6.1"
45+
#define ASYNC_MQTT_GENERIC_SHORT_VERSION "AsyncMQTT_Generic v1.7.0"
4546

4647
/////////////////////////////////////////////////////////
4748

4849
#define ASYNC_MQTT_GENERIC_VERSION_MAJOR 1
49-
#define ASYNC_MQTT_GENERIC_VERSION_MINOR 6
50-
#define ASYNC_MQTT_GENERIC_VERSION_PATCH 1
50+
#define ASYNC_MQTT_GENERIC_VERSION_MINOR 7
51+
#define ASYNC_MQTT_GENERIC_VERSION_PATCH 0
5152

52-
#define ASYNC_MQTT_GENERIC_VERSION_INT 1006001
53+
#define ASYNC_MQTT_GENERIC_VERSION_INT 1007000
5354

5455
/////////////////////////////////////////////////////////
5556

@@ -81,19 +82,46 @@
8182
#endif
8283

8384
#include <freertos/semphr.h>
85+
86+
/////////////////////////////////////////////////////////
8487

8588
#elif defined(ESP8266)
86-
89+
// Use ESP8266 core v2.7.4- for SSL as new cores don't use axtls anymore
90+
// Use core v3.0.2+ for LwIP Ethernet W5500lwIP, W5100lwIP and ENC28J60lwIP libraries
91+
// Must use KH forked ESPAsyncTCP library or compile error
92+
#if ( (USING_W5500 || USING_W5100 || USING_ENC28J60) && (ARDUINO_ESP8266_GIT_VER != 0xcf6ff4c4) )
93+
#error You must use LwIP Ethernet with ESP8266 core v3.0.2+ or error
94+
#endif
95+
96+
#if ( (ARDUINO_ESP8266_GIT_VER == 0xcf6ff4c4) || (ARDUINO_ESP8266_GIT_VER == 0xcbf44fb3) || \
97+
(ARDUINO_ESP8266_GIT_VER == 0xefb0341a) )
98+
#if ASYNC_TCP_SSL_ENABLED
99+
// Can't use SSL yet with core v3.0.0, v3.0.1 and v3.0.2. axtls replaced by bearssl
100+
// To be supported in the future ???
101+
#undef ASYNC_TCP_SSL_ENABLED
102+
#define ASYNC_TCP_SSL_ENABLED false
103+
#warning Disable ESP8266 ASYNC_TCP_SSL_ENABLED for core v3.0.0+
104+
#endif
105+
#endif
106+
87107
#if ASYNC_TCP_SSL_ENABLED
88108
//#include <ESPAsyncTCP_SSL.h>
89-
#include <ESPAsyncTCP.h>
109+
110+
// Must use the forked version or error
111+
#include <ESPAsyncTCP.h> // https://github.com/khoih-prog/ESPAsyncTCP
112+
90113
//#warning ESP8266 ASYNC_TCP_SSL_ENABLED
91114
#error ESP8266 ASYNC_TCP_SSL_ENABLED not ready yet
115+
92116
#else
93-
#include <ESPAsyncTCP.h>
117+
118+
// Must use the forked version or error
119+
#include <ESPAsyncTCP.h> // https://github.com/khoih-prog/ESPAsyncTCP
94120

95121
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP8266")
96122
#endif
123+
124+
/////////////////////////////////////////////////////////
97125

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

@@ -112,6 +140,8 @@
112140
#endif
113141

114142
#define ASYNC_MQTT_USING_PORTENTA_H7 true
143+
144+
/////////////////////////////////////////////////////////
115145

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

130160
#define ASYNC_MQTT_USING_STM32 true
131161

162+
/////////////////////////////////////////////////////////
163+
132164
#elif ( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) )
133165

134166
#if ASYNC_TCP_SSL_ENABLED
@@ -142,6 +174,8 @@
142174
#endif
143175

144176
#define ASYNC_MQTT_USING_TEENSY41_QNETHERNET true
177+
178+
/////////////////////////////////////////////////////////
145179

146180
#elif ( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
147181

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

158-
#define ASYNC_MQTT_USING_RP2040W true
192+
#define ASYNC_MQTT_USING_RP2040W true
193+
194+
/////////////////////////////////////////////////////////
159195

160196
#else
161197
#error Platform not supported
162198
#endif
163199

164-
165200
/////////////////////////////////////////////////////////
166201

167202
#if ASYNC_TCP_SSL_ENABLED
168203
#if (ESP32)
169204
#include <tcp_mbedtls.h>
170-
#elif defined(ESP8266)
205+
#elif ( defined(ESP8266) && (ARDUINO_ESP8266_GIT_VER == 0x2843a5ac) )
206+
// ESP8266 core v2.7.4 still has tcp_axtls support
171207
#include <tcp_axtls.h>
172208
#elif ASYNC_MQTT_USING_PORTENTA_H7
173209
#include <tcp_axtls.h>
@@ -176,7 +212,10 @@
176212
#elif ASYNC_MQTT_USING_TEENSY41_QNETHERNET
177213
#include <tcp_axtls.h>
178214
#elif ASYNC_MQTT_USING_RP2040W
179-
#include <tcp_axtls.h>
215+
#include <tcp_axtls.h>
216+
#else
217+
#undef ASYNC_TCP_SSL_ENABLED
218+
#define ASYNC_TCP_SSL_ENABLED false
180219
#endif
181220

182221
#define SHA1_SIZE 20

src/AsyncMqttClient_Generic_Debug.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
1111
12-
Version: 1.6.1
12+
Version: 1.7.0
1313
1414
Version Modified By Date Comments
1515
------- ----------- ---------- -----------
@@ -23,6 +23,7 @@
2323
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
2424
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
2525
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
26+
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
2627
*****************************************************************************************************************************/
2728

2829
#pragma once
@@ -59,8 +60,8 @@
5960

6061
/////////////////////////////////////////////////////////
6162

62-
#define AMQTT_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
63-
#define AMQTT_SSL_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
63+
#define AMQTT_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
64+
#define AMQTT_SSL_DEBUG(...) if(_ASYNC_MQTT_LOGLEVEL_>3) { AMQTT_PRINTF(__VA_ARGS__); }
6465

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

src/AsyncMqttClient_Generic_Impl.h

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
1111
12-
Version: 1.6.1
12+
Version: 1.7.0
1313
1414
Version Modified By Date Comments
1515
------- ----------- ---------- -----------
@@ -23,6 +23,7 @@
2323
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
2424
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
2525
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
26+
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
2627
*****************************************************************************************************************************/
2728

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

512-
_currentParsedPacket = new AsyncMqttClientInternals::ConnAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onConnAck, this, std::placeholders::_1, std::placeholders::_2));
513+
_currentParsedPacket =
514+
new AsyncMqttClientInternals::ConnAckPacket(&_parsingInformation,
515+
std::bind(&AsyncMqttClient::_onConnAck, this,
516+
std::placeholders::_1, std::placeholders::_2));
513517
_client.setRxTimeout(0);
514518
break;
515519

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

519-
_currentParsedPacket = new AsyncMqttClientInternals::PingRespPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPingResp, this));
523+
_currentParsedPacket =
524+
new AsyncMqttClientInternals::PingRespPacket(&_parsingInformation,
525+
std::bind(&AsyncMqttClient::_onPingResp, this));
520526
break;
521527

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

525-
_currentParsedPacket = new AsyncMqttClientInternals::SubAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onSubAck, this, std::placeholders::_1, std::placeholders::_2));
531+
_currentParsedPacket =
532+
new AsyncMqttClientInternals::SubAckPacket(&_parsingInformation,
533+
std::bind(&AsyncMqttClient::_onSubAck, this,
534+
std::placeholders::_1, std::placeholders::_2));
526535
break;
527536

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

531-
_currentParsedPacket = new AsyncMqttClientInternals::UnsubAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onUnsubAck, this, std::placeholders::_1));
540+
_currentParsedPacket =
541+
new AsyncMqttClientInternals::UnsubAckPacket(&_parsingInformation,
542+
std::bind(&AsyncMqttClient::_onUnsubAck, this,
543+
std::placeholders::_1));
532544
break;
533545

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

537-
_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));
549+
_currentParsedPacket =
550+
new AsyncMqttClientInternals::PublishPacket(&_parsingInformation,
551+
std::bind(&AsyncMqttClient::_onMessage, this,
552+
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
553+
std::placeholders::_4, std::placeholders::_5, std::placeholders::_6,
554+
std::placeholders::_7, std::placeholders::_8, std::placeholders::_9),
555+
std::bind(&AsyncMqttClient::_onPublish, this, std::placeholders::_1,
556+
std::placeholders::_2));
538557
break;
539558

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

543-
_currentParsedPacket = new AsyncMqttClientInternals::PubRelPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubRel, this, std::placeholders::_1));
562+
_currentParsedPacket =
563+
new AsyncMqttClientInternals::PubRelPacket(&_parsingInformation,
564+
std::bind(&AsyncMqttClient::_onPubRel, this,
565+
std::placeholders::_1));
544566
break;
545567

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

549-
_currentParsedPacket = new AsyncMqttClientInternals::PubAckPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubAck, this, std::placeholders::_1));
571+
_currentParsedPacket =
572+
new AsyncMqttClientInternals::PubAckPacket(&_parsingInformation,
573+
std::bind(&AsyncMqttClient::_onPubAck, this,
574+
std::placeholders::_1));
550575
break;
551576

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

555-
_currentParsedPacket = new AsyncMqttClientInternals::PubRecPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubRec, this, std::placeholders::_1));
580+
_currentParsedPacket =
581+
new AsyncMqttClientInternals::PubRecPacket(&_parsingInformation,
582+
std::bind(&AsyncMqttClient::_onPubRec, this,
583+
std::placeholders::_1));
556584
break;
557585

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

561-
_currentParsedPacket = new AsyncMqttClientInternals::PubCompPacket(&_parsingInformation, std::bind(&AsyncMqttClient::_onPubComp, this, std::placeholders::_1));
589+
_currentParsedPacket =
590+
new AsyncMqttClientInternals::PubCompPacket(&_parsingInformation,
591+
std::bind(&AsyncMqttClient::_onPubComp, this,
592+
std::placeholders::_1));
562593
break;
563594

564595
default:
@@ -590,6 +621,7 @@ void AsyncMqttClient::_onData(char* data, size_t len)
590621
_onPingResp();
591622
}
592623
}
624+
593625
break;
594626

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

603635
default:
604636
currentBytePosition = len;
637+
break;
605638
}
606639
} while (currentBytePosition != len);
607640
}

src/AsyncMqtt_Generic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
1111
12-
Version: 1.6.1
12+
Version: 1.7.0
1313
1414
Version Modified By Date Comments
1515
------- ----------- ---------- -----------
@@ -23,6 +23,7 @@
2323
1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library
2424
1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core
2525
1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway
26+
1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error
2627
*****************************************************************************************************************************/
2728

2829
#pragma once

0 commit comments

Comments
 (0)