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

Commit

Permalink
Update README.md and use allman astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Nov 23, 2022
1 parent 3c68455 commit a8b0c4e
Show file tree
Hide file tree
Showing 52 changed files with 1,838 additions and 1,400 deletions.
28 changes: 24 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `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)
* `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)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
Expand All @@ -27,12 +27,12 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
ESP32 Core Version 2.0.4
ESP32 Core Version 2.0.5
OS: Ubuntu 20.04 LTS
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
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
Context:
I encountered an endless loop while trying to connect to Local WiFi.
I encountered a crash while using this library
Steps to reproduce:
1. ...
Expand All @@ -41,13 +41,33 @@ Steps to reproduce:
4. ...
```

---

### Sending Feature Requests

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

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.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncMQTT_Generic_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$ bash utils/restyle.sh
```


85 changes: 46 additions & 39 deletions README.md

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# AsyncMQTT_Generic client for ESP8266, ESP32, etc.
# AsyncMQTT_Generic Library (Async MQTT Client for ESP8266, ESP32, etc.)

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


<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>
<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>
<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>
<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>

---
---

Expand All @@ -31,7 +37,7 @@
### Releases v1.7.0

1. Fix ESP32 compile error. Check [Missing default case in switch causes #10](https://github.com/khoih-prog/AsyncMQTT_Generic/issues/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
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

### Releases v1.6.1

Expand Down
140 changes: 87 additions & 53 deletions examples/ESP32/FullyFeaturedSSL_ESP32/FullyFeaturedSSL_ESP32.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/****************************************************************************************************************************
FullyFeatureSSL_ESP32.ino
AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support
Based on and modified from :
1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
*****************************************************************************************************************************/

// 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.
Expand All @@ -20,8 +20,8 @@

extern "C"
{
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
}

#define ASYNC_TCP_SSL_ENABLED true
Expand All @@ -34,19 +34,19 @@ extern "C"

#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
#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
const char *PubTopic = "async-mqtt/ESP32_Pub"; // Topic to publish

#define MQTT_PORT 1883

#endif

AsyncMqttClient mqttClient;
Expand All @@ -70,42 +70,53 @@ 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());
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());
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:

default:
break;
}
}
Expand All @@ -115,34 +126,41 @@ void printSeparationLine()
Serial.println("************************************************");
}

void onMqttConnect(bool sessionPresent)
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);

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);

Serial.print("Session present: ");
Serial.println(sessionPresent);

uint16_t packetIdSub = mqttClient.subscribe(PubTopic, 2);
Serial.print("Subscribing at QoS 2, packetId: "); Serial.println(packetIdSub);

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);

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);
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())
Expand All @@ -154,47 +172,62 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
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);
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);
Serial.print(" packetId: ");
Serial.println(packetId);
}

void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
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);
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);
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.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));
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);

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

#if ASYNC_TCP_SSL_ENABLED
mqttClient.setSecure(MQTT_SECURE);
if (MQTT_SECURE)

if (MQTT_SECURE)
{
//mqttClient.addServerFingerprint((const uint8_t[])MQTT_SERVER_FINGERPRINT);
mqttClient.addServerFingerprint((const uint8_t *)MQTT_SERVER_FINGERPRINT);
}

#endif

connectToWifi();
Expand Down
6 changes: 3 additions & 3 deletions examples/ESP32/FullyFeaturedSSL_ESP32/defines.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/****************************************************************************************************************************
defines.h
AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support
Based on and modified from :
1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
***************************************************************************************************************************************/

Expand Down
Loading

0 comments on commit a8b0c4e

Please sign in to comment.