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

Commit a8b0c4e

Browse files
authored
Update README.md and use allman astyle
1 parent 3c68455 commit a8b0c4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1838
-1400
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `ESP8266`,`ESP32`, `STM32`, `arduino-pico` or `Teensyduino` Core Version (e.g. ESP8266 core v3.0.2, ESP32 v2.0.4, STM32 v2.3.0, arduino-pico v2.5.2 or Teensyduino v1.57)
18+
* `ESP8266`,`ESP32`, `STM32`, `arduino-pico` or `Teensyduino` Core Version (e.g. ESP8266 core v3.0.2, ESP32 v2.0.5, STM32 v2.3.0, arduino-pico v2.6.3 or Teensyduino v1.57)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -27,12 +27,12 @@ Please ensure to specify the following:
2727

2828
```
2929
Arduino IDE version: 1.8.19
30-
ESP32 Core Version 2.0.4
30+
ESP32 Core Version 2.0.5
3131
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
32+
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3333
3434
Context:
35-
I encountered an endless loop while trying to connect to Local WiFi.
35+
I encountered a crash while using this library
3636
3737
Steps to reproduce:
3838
1. ...
@@ -41,13 +41,33 @@ Steps to reproduce:
4141
4. ...
4242
```
4343

44+
---
45+
4446
### Sending Feature Requests
4547

4648
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
4749

4850
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncMQTT_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
4951

52+
---
53+
5054
### Sending Pull Requests
5155

5256
Pull Requests with changes and fixes are also welcome!
5357

58+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
59+
60+
1. Change directory to the library GitHub
61+
62+
```
63+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncMQTT_Generic_GitHub/
64+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$
65+
```
66+
67+
2. Issue astyle command
68+
69+
```
70+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$ bash utils/restyle.sh
71+
```
72+
73+

README.md

Lines changed: 46 additions & 39 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# AsyncMQTT_Generic client for ESP8266, ESP32, etc.
1+
# AsyncMQTT_Generic Library (Async MQTT Client for ESP8266, ESP32, etc.)
22

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncMQTT_Generic.svg?)](https://www.ardu-badge.com/AsyncMQTT_Generic)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncMQTT_Generic.svg)](https://github.com/khoih-prog/AsyncMQTT_Generic/releases)
55
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
66
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncMQTT_Generic.svg)](http://github.com/khoih-prog/AsyncMQTT_Generic/issues)
77

8+
9+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
11+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
12+
<a href="https://profile-counter.glitch.me/khoih-prog-AsyncMQTT_Generic/count.svg" title="AsyncMQTT_Generic Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-AsyncMQTT_Generic/count.svg" style="height: 30px;width: 200px;"></a>
13+
814
---
915
---
1016

@@ -31,7 +37,7 @@
3137
### Releases v1.7.0
3238

3339
1. Fix ESP32 compile error. Check [Missing default case in switch causes #10](https://github.com/khoih-prog/AsyncMQTT_Generic/issues/10)
34-
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
40+
2. Change to new [KH_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
3541

3642
### Releases v1.6.1
3743

examples/ESP32/FullyFeaturedSSL_ESP32/FullyFeaturedSSL_ESP32.ino

Lines changed: 87 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/****************************************************************************************************************************
22
FullyFeatureSSL_ESP32.ino
3-
3+
44
AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support
5-
5+
66
Based on and modified from :
7-
7+
88
1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client)
9-
9+
1010
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
1111
*****************************************************************************************************************************/
12-
12+
1313
// Example project which can be built with SSL enabled or disabled.
1414
// The espressif8266_stage platform must be installed.
1515
// Refer to platformio.ini for the build configuration and platform installation.
@@ -20,8 +20,8 @@
2020

2121
extern "C"
2222
{
23-
#include "freertos/FreeRTOS.h"
24-
#include "freertos/timers.h"
23+
#include "freertos/FreeRTOS.h"
24+
#include "freertos/timers.h"
2525
}
2626

2727
#define ASYNC_TCP_SSL_ENABLED true
@@ -34,19 +34,19 @@ extern "C"
3434

3535
#if ASYNC_TCP_SSL_ENABLED
3636

37-
#define MQTT_SECURE true
38-
39-
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};
40-
const char *PubTopic = "async-mqtt/ESP32_SSL_Pub"; // Topic to publish
41-
42-
#define MQTT_PORT 8883
43-
37+
#define MQTT_SECURE true
38+
39+
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};
40+
const char *PubTopic = "async-mqtt/ESP32_SSL_Pub"; // Topic to publish
41+
42+
#define MQTT_PORT 8883
43+
4444
#else
4545

46-
const char *PubTopic = "async-mqtt/ESP32_Pub"; // Topic to publish
47-
48-
#define MQTT_PORT 1883
49-
46+
const char *PubTopic = "async-mqtt/ESP32_Pub"; // Topic to publish
47+
48+
#define MQTT_PORT 1883
49+
5050
#endif
5151

5252
AsyncMqttClient mqttClient;
@@ -70,42 +70,53 @@ void WiFiEvent(WiFiEvent_t event)
7070
switch (event)
7171
{
7272
#if USING_CORE_ESP32_CORE_V200_PLUS
73+
7374
case ARDUINO_EVENT_WIFI_READY:
7475
Serial.println("WiFi ready");
7576
break;
77+
7678
case ARDUINO_EVENT_WIFI_STA_START:
7779
Serial.println("WiFi STA starting");
7880
break;
81+
7982
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
8083
Serial.println("WiFi STA connected");
8184
break;
85+
8286
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
8387
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
8488
Serial.println("WiFi connected");
85-
Serial.print("IP address: "); Serial.println(WiFi.localIP());
89+
Serial.print("IP address: ");
90+
Serial.println(WiFi.localIP());
8691
connectToMqtt();
8792
break;
93+
8894
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
8995
Serial.println("WiFi lost IP");
9096
break;
97+
9198
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
9299
Serial.println("WiFi lost connection");
93100
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
94101
xTimerStart(wifiReconnectTimer, 0);
95102
break;
96103
#else
104+
97105
case SYSTEM_EVENT_STA_GOT_IP:
98106
Serial.println("WiFi connected");
99-
Serial.println("IP address: "); Serial.println(WiFi.localIP());
107+
Serial.println("IP address: ");
108+
Serial.println(WiFi.localIP());
100109
connectToMqtt();
101110
break;
111+
102112
case SYSTEM_EVENT_STA_DISCONNECTED:
103113
Serial.println("WiFi lost connection");
104114
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
105115
xTimerStart(wifiReconnectTimer, 0);
106116
break;
107117
#endif
108-
default:
118+
119+
default:
109120
break;
110121
}
111122
}
@@ -115,34 +126,41 @@ void printSeparationLine()
115126
Serial.println("************************************************");
116127
}
117128

118-
void onMqttConnect(bool sessionPresent)
129+
void onMqttConnect(bool sessionPresent)
119130
{
120-
Serial.print("Connected to MQTT broker: "); Serial.print(MQTT_HOST);
121-
Serial.print(", port: "); Serial.println(MQTT_PORT);
122-
Serial.print("PubTopic: "); Serial.println(PubTopic);
123-
131+
Serial.print("Connected to MQTT broker: ");
132+
Serial.print(MQTT_HOST);
133+
Serial.print(", port: ");
134+
Serial.println(MQTT_PORT);
135+
Serial.print("PubTopic: ");
136+
Serial.println(PubTopic);
137+
124138
printSeparationLine();
125-
Serial.print("Session present: "); Serial.println(sessionPresent);
126-
139+
Serial.print("Session present: ");
140+
Serial.println(sessionPresent);
141+
127142
uint16_t packetIdSub = mqttClient.subscribe(PubTopic, 2);
128-
Serial.print("Subscribing at QoS 2, packetId: "); Serial.println(packetIdSub);
129-
143+
Serial.print("Subscribing at QoS 2, packetId: ");
144+
Serial.println(packetIdSub);
145+
130146
mqttClient.publish(PubTopic, 0, true, "ESP32 Test");
131147
Serial.println("Publishing at QoS 0");
132-
148+
133149
uint16_t packetIdPub1 = mqttClient.publish(PubTopic, 1, true, "test 2");
134-
Serial.print("Publishing at QoS 1, packetId: "); Serial.println(packetIdPub1);
135-
150+
Serial.print("Publishing at QoS 1, packetId: ");
151+
Serial.println(packetIdPub1);
152+
136153
uint16_t packetIdPub2 = mqttClient.publish(PubTopic, 2, true, "test 3");
137-
Serial.print("Publishing at QoS 2, packetId: "); Serial.println(packetIdPub2);
154+
Serial.print("Publishing at QoS 2, packetId: ");
155+
Serial.println(packetIdPub2);
138156

139157
printSeparationLine();
140158
}
141159

142160
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
143161
{
144162
(void) reason;
145-
163+
146164
Serial.println("Disconnected from MQTT.");
147165

148166
if (WiFi.isConnected())
@@ -154,47 +172,62 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
154172
void onMqttSubscribe(const uint16_t& packetId, const uint8_t& qos)
155173
{
156174
Serial.println("Subscribe acknowledged.");
157-
Serial.print(" packetId: "); Serial.println(packetId);
158-
Serial.print(" qos: "); Serial.println(qos);
175+
Serial.print(" packetId: ");
176+
Serial.println(packetId);
177+
Serial.print(" qos: ");
178+
Serial.println(qos);
159179
}
160180

161181
void onMqttUnsubscribe(const uint16_t& packetId)
162182
{
163183
Serial.println("Unsubscribe acknowledged.");
164-
Serial.print(" packetId: "); Serial.println(packetId);
184+
Serial.print(" packetId: ");
185+
Serial.println(packetId);
165186
}
166187

167-
void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
188+
void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
168189
const size_t& len, const size_t& index, const size_t& total)
169190
{
170191
(void) payload;
171-
192+
172193
Serial.println("Publish received.");
173-
Serial.print(" topic: "); Serial.println(topic);
174-
Serial.print(" qos: "); Serial.println(properties.qos);
175-
Serial.print(" dup: "); Serial.println(properties.dup);
176-
Serial.print(" retain: "); Serial.println(properties.retain);
177-
Serial.print(" len: "); Serial.println(len);
178-
Serial.print(" index: "); Serial.println(index);
179-
Serial.print(" total: "); Serial.println(total);
194+
Serial.print(" topic: ");
195+
Serial.println(topic);
196+
Serial.print(" qos: ");
197+
Serial.println(properties.qos);
198+
Serial.print(" dup: ");
199+
Serial.println(properties.dup);
200+
Serial.print(" retain: ");
201+
Serial.println(properties.retain);
202+
Serial.print(" len: ");
203+
Serial.println(len);
204+
Serial.print(" index: ");
205+
Serial.println(index);
206+
Serial.print(" total: ");
207+
Serial.println(total);
180208
}
181209

182210
void onMqttPublish(const uint16_t& packetId)
183211
{
184212
Serial.println("Publish acknowledged");
185-
Serial.print(" packetId: "); Serial.println(packetId);
213+
Serial.print(" packetId: ");
214+
Serial.println(packetId);
186215
}
187216

188217
void setup()
189218
{
190219
Serial.begin(115200);
220+
191221
while (!Serial && millis() < 5000);
192222

193-
Serial.print("\nStarting FullyFeatureSSL_ESP32 on "); Serial.println(ARDUINO_BOARD);
223+
Serial.print("\nStarting FullyFeatureSSL_ESP32 on ");
224+
Serial.println(ARDUINO_BOARD);
194225
Serial.println(ASYNC_MQTT_GENERIC_VERSION);
195226

196-
mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
197-
wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
227+
mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0,
228+
reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
229+
wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0,
230+
reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
198231

199232
WiFi.onEvent(WiFiEvent);
200233

@@ -209,12 +242,13 @@ void setup()
209242

210243
#if ASYNC_TCP_SSL_ENABLED
211244
mqttClient.setSecure(MQTT_SECURE);
212-
213-
if (MQTT_SECURE)
245+
246+
if (MQTT_SECURE)
214247
{
215248
//mqttClient.addServerFingerprint((const uint8_t[])MQTT_SERVER_FINGERPRINT);
216249
mqttClient.addServerFingerprint((const uint8_t *)MQTT_SERVER_FINGERPRINT);
217250
}
251+
218252
#endif
219253

220254
connectToWifi();

examples/ESP32/FullyFeaturedSSL_ESP32/defines.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/****************************************************************************************************************************
22
defines.h
33
AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support
4-
4+
55
Based on and modified from :
6-
6+
77
1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client)
8-
8+
99
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
1010
***************************************************************************************************************************************/
1111

0 commit comments

Comments
 (0)