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

Commit 77a895f

Browse files
authored
v1.8.0 for ESP32 using WiFi / LwIP Ethernet
### Releases v1.8.0 1. Initial coding to port [AsyncMQTT_Generic](https://github.com/khoih-prog/AsyncMQTT_Generic) to `ESP32/S2/S3/C3` boards using WiFi or `LwIP W5500 / ENC28J60 / LAN8720 Ethernet` 2. Use `allman astyle` 3. Sync with [AsyncMQTT_Generic v1.8.0](https://github.com/khoih-prog/AsyncMQTT_Generic)
1 parent c2e49ca commit 77a895f

File tree

96 files changed

+8850
-1
lines changed

Some content is hidden

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

96 files changed

+8850
-1
lines changed

.codespellrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# See: https://github.com/codespell-project/codespell#using-a-config-file
2+
[codespell]
3+
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
4+
ignore-words-list = ,
5+
check-filenames =
6+
check-hidden =
7+
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches

CONTRIBUTING.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
## Contributing to AsyncMQTT_ESP32
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in [AsyncMQTT_ESP32](https://github.com/khoih-prog/AsyncMQTT_ESP32/issues/new) if you find them.
6+
7+
However, before reporting a bug please check through the following:
8+
9+
* [Existing Open Issues](https://github.com/khoih-prog/AsyncMQTT_ESP32/issues) - someone might have already encountered this.
10+
11+
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncMQTT_ESP32/issues/new).
12+
13+
### How to submit a bug report
14+
15+
Please ensure to specify the following:
16+
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18+
* Board Type (e.g. ESP32S3_DEV, ESP32S2_DEV, ESP32C3_DEV)
19+
* Board Core Version (e.g. ESP32 core v2.0.5)
20+
* Contextual information (e.g. what you were trying to achieve)
21+
* Simplest possible steps to reproduce
22+
* Anything that might be relevant in your opinion, such as:
23+
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
24+
* Network configuration
25+
26+
27+
Please be educated, civilized and constructive. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted.
28+
29+
30+
### Example
31+
32+
```
33+
Arduino IDE version: 1.8.19
34+
ESP32S3_DEV board
35+
ESP32 core v2.0.5
36+
OS: Ubuntu 20.04 LTS
37+
Linux xy-Inspiron-3593 5.15.0-56-generic #62~20.04.1-Ubuntu SMP Tue Nov 22 21:24:20 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
38+
39+
Context:
40+
I encountered a crash while using this library
41+
42+
Steps to reproduce:
43+
1. ...
44+
2. ...
45+
3. ...
46+
4. ...
47+
```
48+
49+
---
50+
51+
### Sending Feature Requests
52+
53+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
54+
55+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncMQTT_ESP32/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
56+
57+
---
58+
59+
### Sending Pull Requests
60+
61+
Pull Requests with changes and fixes are also welcome!
62+
63+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
64+
65+
1. Change directory to the library GitHub
66+
67+
```
68+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncMQTT_ESP32_GitHub/
69+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_ESP32_GitHub$
70+
```
71+
72+
2. Issue astyle command
73+
74+
```
75+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_ESP32_GitHub$ bash utils/restyle.sh
76+
```
77+
78+

Images/ENC28J60.png

140 KB
Loading

Images/ESP32S3_DEV.png

294 KB
Loading

Images/W5500.png

209 KB
Loading

Images/W5500_small.png

96 KB
Loading

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Khoi Hoang
3+
Copyright (c) 2019 Khoi Hoang
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

changelog.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# AsyncMQTT_ESP32 Library
2+
3+
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncMQTT_ESP32.svg?)](https://www.ardu-badge.com/AsyncMQTT_ESP32)
4+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncMQTT_ESP32.svg)](https://github.com/khoih-prog/AsyncMQTT_ESP32/releases)
5+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
6+
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncMQTT_ESP32.svg)](http://github.com/khoih-prog/AsyncMQTT_ESP32/issues)
7+
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+
12+
---
13+
---
14+
15+
## Table of Contents
16+
17+
* [Changelog](#changelog)
18+
* [Releases v1.8.0](#releases-v180)
19+
20+
---
21+
---
22+
23+
## Changelog
24+
25+
### Releases v1.8.0
26+
27+
1. Initial coding to port [AsyncMQTT_Generic](https://github.com/khoih-prog/AsyncMQTT_Generic) to `ESP32/S2/S3/C3` boards using WiFi or `LwIP W5500 / ENC28J60 / LAN8720 Ethernet`
28+
2. Use `allman astyle`
29+
3. Sync with [AsyncMQTT_Generic v1.8.0](https://github.com/khoih-prog/AsyncMQTT_Generic)

docs/1.-Getting-started.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Getting started
2+
3+
To use AsyncMqttClient, you need:
4+
5+
* An ESP8266 or ESP32
6+
* The Arduino IDE or equivalent IDE for ESP8266/32
7+
* Basic knowledge of the Arduino environment (use the IDE, upload a sketch, import libraries, ...)
8+
9+
## Installing AsyncMqttClient
10+
11+
There are two ways to install AsyncMqttClient.
12+
13+
### 1a. For the Arduino IDE
14+
15+
1. Download the [corresponding release](https://github.com/marvinroger/async-mqtt-client/releases/latest)
16+
2. Load the `.zip` with **Sketch → Include Library → Add .ZIP Library**
17+
18+
AsyncMqttClient has 1 dependency:
19+
* For ESP8266: [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP). Download the [.zip](https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip) and install it with the same method as above.
20+
* Fors ESP32: [AsyncTCP](https://github.com/me-no-dev/AsyncTCP). Download the [.zip](https://github.com/me-no-dev/AsyncTCP/archive/master.zip) and install it with the same method as above.
21+
22+
## Fully-featured sketch
23+
24+
See [examples/FullyFeatured-ESP8266.ino](../examples/FullyFeatured-ESP8266/FullyFeatured-ESP8266.ino)
25+
26+
**<u>Very important:</u> As a rule of thumb, never use blocking functions in the callbacks (don't use `delay()` or `yield()`).** Otherwise, you may very probably experience unexpected behaviors.
27+
28+
You can go to the [API reference](2.-API-reference.md).

docs/2.-API-reference.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# API reference
2+
3+
#### AsyncMqttClient()
4+
5+
Instantiate a new AsyncMqttClient object.
6+
7+
### Configuration
8+
9+
#### AsyncMqttClient& setKeepAlive(uint16_t `keepAlive`)
10+
11+
Set the keep alive. Defaults to 15 seconds.
12+
13+
* **`keepAlive`**: Keep alive in seconds
14+
15+
#### AsyncMqttClient& setClientId(const char\* `clientId`)
16+
17+
Set the client ID. Defaults to `esp8266<chip ID on 6 hex characters>`.
18+
19+
* **`clientId`**: Client ID
20+
21+
#### AsyncMqttClient& setCleanSession(bool `cleanSession`)
22+
23+
Whether or not to set the CleanSession flag. Defaults to `true`.
24+
25+
* **`cleanSession`**: clean session wanted or not
26+
27+
#### AsyncMqttClient& setMaxTopicLength(uint16_t `maxTopicLength`)
28+
29+
Set the maximum allowed topic length to receive. If an MQTT packet is received
30+
with a topic longer than this maximum, the packet will be ignored. Defaults to `128`.
31+
32+
* **`maxTopicLength`**: Maximum allowed topic length to receive
33+
34+
#### AsyncMqttClient& setCredentials(const char\* `username`, const char\* `password` = nullptr)
35+
36+
Set the username/password. Defaults to non-auth.
37+
38+
* **`username`**: Username
39+
* **`password`**: Password
40+
41+
#### AsyncMqttClient& setWill(const char\* `topic`, uint8_t `qos`, bool `retain`, const char\* `payload` = nullptr, size_t `length` = 0)
42+
43+
Set the Last Will Testament. Defaults to none.
44+
45+
* **`topic`**: Topic of the LWT
46+
* **`qos`**: QoS of the LWT
47+
* **`retain`**: Retain flag of the LWT
48+
* **`payload`**: Payload of the LWT. If unset, the payload will be empty
49+
* **`length`**: Payload length. If unset or set to 0, the payload will be considered as a string and its size will be calculated using `strlen(payload)`
50+
51+
#### AsyncMqttClient& setServer(IPAddress `ip`, uint16_t `port`)
52+
53+
Set the server.
54+
55+
* **`ip`**: IP of the server
56+
* **`port`**: Port of the server
57+
58+
#### AsyncMqttClient& setServer(const char\* `host`, uint16_t `port`)
59+
60+
Set the server.
61+
62+
* **`host`**: Host of the server
63+
* **`port`**: Port of the server
64+
65+
#### AsyncMqttClient& setSecure(bool `secure`)
66+
67+
Whether or not to use SSL. Defaults to `false`.
68+
69+
* **`secure`**: SSL wanted or not.
70+
71+
#### AsyncMqttClient& addServerFingerprint(const uint8_t\* `fingerprint`)
72+
73+
Adds an acceptable server fingerprint (SHA1). This may be called multiple times to permit any one of the specified fingerprints. By default, if no fingerprint is added, any fingerprint is accepted.
74+
75+
* **`fingerprint`**: Fingerprint to add
76+
77+
### Events handlers
78+
79+
#### AsyncMqttClient& onConnect(AsyncMqttClientInternals::OnConnectUserCallback `callback`)
80+
81+
Add a connect event handler.
82+
83+
* **`callback`**: Function to call
84+
85+
#### AsyncMqttClient& onDisconnect(AsyncMqttClientInternals::OnDisconnectUserCallback `callback`)
86+
87+
Add a disconnect event handler.
88+
89+
* **`callback`**: Function to call
90+
91+
#### AsyncMqttClient& onSubscribe(AsyncMqttClientInternals::OnSubscribeUserCallback `callback`)
92+
93+
Add a subscribe acknowledged event handler.
94+
95+
* **`callback`**: Function to call
96+
97+
#### AsyncMqttClient& onUnsubscribe(AsyncMqttClientInternals::OnUnsubscribeUserCallback `callback`)
98+
99+
Add an unsubscribe acknowledged event handler.
100+
101+
* **`callback`**: Function to call
102+
103+
#### AsyncMqttClient& onMessage(AsyncMqttClientInternals::OnMessageUserCallback `callback`)
104+
105+
Add a publish received event handler.
106+
107+
* **`callback`**: Function to call
108+
109+
#### AsyncMqttClient& onPublish(AsyncMqttClientInternals::OnPublishUserCallback `callback`)
110+
111+
Add a publish acknowledged event handler.
112+
113+
* **`callback`**: Function to call
114+
115+
### Operation functions
116+
117+
#### bool connected()
118+
119+
Return if the client is currently connected to the broker or not.
120+
121+
#### void connect()
122+
123+
Connect to the server.
124+
125+
#### void disconnect(bool `force` = false)
126+
127+
Disconnect from the server.
128+
129+
* **`force`**: Whether to force the disconnection. Defaults to `false` (clean disconnection).
130+
131+
#### uint16_t subscribe(const char\* `topic`, uint8_t `qos`)
132+
133+
Subscribe to the given topic at the given QoS.
134+
135+
Return the packet ID or 0 if failed.
136+
137+
* **`topic`**: Topic
138+
* **`qos`**: QoS
139+
140+
#### uint16_t unsubscribe(const char\* `topic`)
141+
142+
Unsubscribe from the given topic.
143+
144+
Return the packet ID or 0 if failed.
145+
146+
* **`topic`**: Topic
147+
148+
#### uint16_t publish(const char\* `topic`, uint8_t `qos`, bool `retain`, const char\* `payload` = nullptr, size_t `length` = 0, bool dup = false, uint16_t message_id = 0)
149+
150+
Publish a packet.
151+
152+
Return the packet ID (or 1 if QoS 0) or 0 if failed.
153+
154+
* **`topic`**: Topic
155+
* **`qos`**: QoS
156+
* **`retain`**: Retain flag
157+
* **`payload`**: Payload. If unset, the payload will be empty
158+
* **`length`**: Payload length. If unset or set to 0, the payload will be considered as a string and its size will be calculated using `strlen(payload)`
159+
* **`dup`**: ~~Duplicate flag. If set or set to 1, the payload will be flagged as a duplicate~~ Setting is not used anymore
160+
* **`message_id`**: ~~The message ID. If unset or set to 0, the message ID will be automtaically assigned. Use this with the DUP flag to identify which message is being duplicated~~ Setting is not used anymore
161+
162+
#### bool clearQueue()
163+
164+
When disconnected, clears all queued messages
165+
166+
Returns true on success, false on failure (client is no disconnected)

0 commit comments

Comments
 (0)