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

Commit a8878ac

Browse files
authored
v1.2.0 to support STM32 + LAN8742A
### Releases v1.2.0 1. Add support to **STM32F/L/H/G/WB/MP1 (without TLS/SSL)** using `built-in LAN8742A` Ethernet, such as Nucleo-144, DISCOVERY, etc. 2. Add examples for `STM32`
1 parent 4b78a72 commit a8878ac

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

src/AsyncMqttClient_Generic.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@
4949

5050
#ifdef ESP32
5151

52-
#if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) )
53-
#define USING_CORE_ESP32_CORE_V200_PLUS true
54-
55-
#if (_ASYNC_MQTT_LOGLEVEL_ > 3)
56-
#warning Using code for ESP32 core v2.0.0+ in AsyncMqttClient_Generic.hpp
57-
#endif
58-
59-
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP32 core v2.0.0+")
60-
61-
#else
62-
#if (_ASYNC_MQTT_LOGLEVEL_ > 3)
63-
#warning Using code for ESP32 core v1.0.6- in AsyncMqttClient_Generic.hpp
64-
#endif
65-
66-
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP32 core v1.0.6-")
67-
68-
#endif
52+
#if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) )
53+
#define USING_CORE_ESP32_CORE_V200_PLUS true
54+
55+
#if (_ASYNC_MQTT_LOGLEVEL_ > 3)
56+
#warning Using code for ESP32 core v2.0.0+ in AsyncMqttClient_Generic.hpp
57+
#endif
58+
59+
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP32 core v2.0.0+")
60+
61+
#else
62+
#if (_ASYNC_MQTT_LOGLEVEL_ > 3)
63+
#warning Using code for ESP32 core v1.0.6- in AsyncMqttClient_Generic.hpp
64+
#endif
65+
66+
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP32 core v1.0.6-")
67+
68+
#endif
6969

7070
#if ASYNC_TCP_SSL_ENABLED
7171
#include <AsyncTCP_SSL.h>
@@ -86,24 +86,24 @@
8686
#else
8787
#include <ESPAsyncTCP.h>
8888

89-
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP8266")
89+
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for ESP8266")
9090
#endif
9191

9292
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
9393
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
9494
defined(STM32WB) || defined(STM32MP1) )
9595

9696
#if ASYNC_TCP_SSL_ENABLED
97-
#error STM32 ASYNC_TCP_SSL_ENABLED not ready yet
97+
#error STM32 ASYNC_TCP_SSL_ENABLED not ready yet
9898
#include <STM32AsyncTCP_SSL.h>
9999
#warning STM32 ASYNC_TCP_SSL_ENABLED
100100
#else
101101
#include <STM32AsyncTCP.h>
102102

103-
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for STM32")
103+
#define ASYNC_MQTT_GENERIC_VERSION (ASYNC_MQTT_GENERIC_SHORT_VERSION " for STM32")
104104
#endif
105105

106-
#define ASYNC_MQTT_USING_STM32 true
106+
#define ASYNC_MQTT_USING_STM32 true
107107

108108
#else
109109
#error Platform not supported
@@ -302,7 +302,6 @@ class AsyncMqttClient
302302

303303
void _sendPing();
304304

305-
//const char* macAddressToClientID(const uint8_t* _macAddress);
306305
char* macAddressToClientID(char* buffer, const uint8_t* _macAddress);
307306
};
308307

src/AsyncMqttClient_Generic_Impl.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ AsyncMqttClient::AsyncMqttClient()
177177
#elif defined(ESP8266)
178178
sprintf(_generatedClientId, "esp8266-%06x", ESP.getChipId());
179179
#elif ASYNC_MQTT_USING_STM32
180-
// Will create _clientId from macAddress later in connect() as ID not available now
180+
// Will create _clientId from macAddress later in connect() as ID not available now
181181
#endif
182182

183183
_clientId = _generatedClientId;
@@ -1125,21 +1125,21 @@ void AsyncMqttClient::connect()
11251125
return;
11261126

11271127
#if ASYNC_MQTT_USING_STM32
1128-
// 6 HEX bytes + NULL
1129-
char buffer[13];
1130-
1131-
macAddressToClientID(buffer, Ethernet.MACAddress());
1132-
snprintf(_generatedClientId, sizeof(_generatedClientId), "stm32-%s", buffer);
1133-
1134-
//snprintf(_generatedClientId, sizeof(_generatedClientId), "stm32-%s", macAddressToClientID(Ethernet.MACAddress()));
1135-
1128+
// 6 HEX bytes + NULL
1129+
char buffer[13];
1130+
1131+
macAddressToClientID(buffer, Ethernet.MACAddress());
1132+
snprintf(_generatedClientId, sizeof(_generatedClientId), "stm32-%s", buffer);
1133+
1134+
//snprintf(_generatedClientId, sizeof(_generatedClientId), "stm32-%s", macAddressToClientID(Ethernet.MACAddress()));
1135+
11361136
_clientId = _generatedClientId;
11371137
#endif
11381138

11391139
AMQTT_LOGINFO("CONNECTING");
1140-
1140+
11411141
AMQTT_LOGINFO1("ClientID =", _clientId);
1142-
1142+
11431143
_state = CONNECTING;
11441144
_disconnectReason = AsyncMqttClientDisconnectReason::TCP_DISCONNECTED; // reset any previous
11451145

@@ -1257,15 +1257,16 @@ const char* AsyncMqttClient::getClientId() const
12571257

12581258
char* AsyncMqttClient::macAddressToClientID(char* buffer, const uint8_t* _macAddress)
12591259
{
1260-
// 6 HEX bytes + NULL = min(13) for buffer
1261-
// static char buffer[13];
1262-
memset((void*) buffer, 0, sizeof(buffer));
1263-
1264-
for (int i = 0; i < 6; i++)
1265-
sprintf(&buffer[i * 2], "%02X", _macAddress[i]); //convert number to hex
1266-
1260+
// 6 HEX bytes + NULL = min(13) for buffer
1261+
// static char buffer[13];
1262+
memset((void*) buffer, 0, sizeof(buffer));
1263+
1264+
for (int i = 0; i < 6; i++)
1265+
sprintf(&buffer[i * 2], "%02X", _macAddress[i]); //convert number to hex
1266+
12671267
return ( buffer );
12681268
}
1269+
12691270
/////////////////////////////////////////////////////////
12701271

12711272
#endif // ASYNC_MQTT_CLIENT_IMPL_H

0 commit comments

Comments
 (0)