Initial commit of Arduino libraries
This commit is contained in:
28
AsyncMQTT_ESP32/docs/1.-Getting-started.md
Normal file
28
AsyncMQTT_ESP32/docs/1.-Getting-started.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Getting started
|
||||
|
||||
To use AsyncMqttClient, you need:
|
||||
|
||||
* An ESP8266 or ESP32
|
||||
* The Arduino IDE or equivalent IDE for ESP8266/32
|
||||
* Basic knowledge of the Arduino environment (use the IDE, upload a sketch, import libraries, ...)
|
||||
|
||||
## Installing AsyncMqttClient
|
||||
|
||||
There are two ways to install AsyncMqttClient.
|
||||
|
||||
### 1a. For the Arduino IDE
|
||||
|
||||
1. Download the [corresponding release](https://github.com/marvinroger/async-mqtt-client/releases/latest)
|
||||
2. Load the `.zip` with **Sketch → Include Library → Add .ZIP Library**
|
||||
|
||||
AsyncMqttClient has 1 dependency:
|
||||
* 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.
|
||||
* 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.
|
||||
|
||||
## Fully-featured sketch
|
||||
|
||||
See [examples/FullyFeatured-ESP8266.ino](../examples/FullyFeatured-ESP8266/FullyFeatured-ESP8266.ino)
|
||||
|
||||
**<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.
|
||||
|
||||
You can go to the [API reference](2.-API-reference.md).
|
||||
166
AsyncMQTT_ESP32/docs/2.-API-reference.md
Normal file
166
AsyncMQTT_ESP32/docs/2.-API-reference.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# API reference
|
||||
|
||||
#### AsyncMqttClient()
|
||||
|
||||
Instantiate a new AsyncMqttClient object.
|
||||
|
||||
### Configuration
|
||||
|
||||
#### AsyncMqttClient& setKeepAlive(uint16_t `keepAlive`)
|
||||
|
||||
Set the keep alive. Defaults to 15 seconds.
|
||||
|
||||
* **`keepAlive`**: Keep alive in seconds
|
||||
|
||||
#### AsyncMqttClient& setClientId(const char\* `clientId`)
|
||||
|
||||
Set the client ID. Defaults to `esp8266<chip ID on 6 hex characters>`.
|
||||
|
||||
* **`clientId`**: Client ID
|
||||
|
||||
#### AsyncMqttClient& setCleanSession(bool `cleanSession`)
|
||||
|
||||
Whether or not to set the CleanSession flag. Defaults to `true`.
|
||||
|
||||
* **`cleanSession`**: clean session wanted or not
|
||||
|
||||
#### AsyncMqttClient& setMaxTopicLength(uint16_t `maxTopicLength`)
|
||||
|
||||
Set the maximum allowed topic length to receive. If an MQTT packet is received
|
||||
with a topic longer than this maximum, the packet will be ignored. Defaults to `128`.
|
||||
|
||||
* **`maxTopicLength`**: Maximum allowed topic length to receive
|
||||
|
||||
#### AsyncMqttClient& setCredentials(const char\* `username`, const char\* `password` = nullptr)
|
||||
|
||||
Set the username/password. Defaults to non-auth.
|
||||
|
||||
* **`username`**: Username
|
||||
* **`password`**: Password
|
||||
|
||||
#### AsyncMqttClient& setWill(const char\* `topic`, uint8_t `qos`, bool `retain`, const char\* `payload` = nullptr, size_t `length` = 0)
|
||||
|
||||
Set the Last Will Testament. Defaults to none.
|
||||
|
||||
* **`topic`**: Topic of the LWT
|
||||
* **`qos`**: QoS of the LWT
|
||||
* **`retain`**: Retain flag of the LWT
|
||||
* **`payload`**: Payload of the LWT. If unset, the payload will be empty
|
||||
* **`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)`
|
||||
|
||||
#### AsyncMqttClient& setServer(IPAddress `ip`, uint16_t `port`)
|
||||
|
||||
Set the server.
|
||||
|
||||
* **`ip`**: IP of the server
|
||||
* **`port`**: Port of the server
|
||||
|
||||
#### AsyncMqttClient& setServer(const char\* `host`, uint16_t `port`)
|
||||
|
||||
Set the server.
|
||||
|
||||
* **`host`**: Host of the server
|
||||
* **`port`**: Port of the server
|
||||
|
||||
#### AsyncMqttClient& setSecure(bool `secure`)
|
||||
|
||||
Whether or not to use SSL. Defaults to `false`.
|
||||
|
||||
* **`secure`**: SSL wanted or not.
|
||||
|
||||
#### AsyncMqttClient& addServerFingerprint(const uint8_t\* `fingerprint`)
|
||||
|
||||
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.
|
||||
|
||||
* **`fingerprint`**: Fingerprint to add
|
||||
|
||||
### Events handlers
|
||||
|
||||
#### AsyncMqttClient& onConnect(AsyncMqttClientInternals::OnConnectUserCallback `callback`)
|
||||
|
||||
Add a connect event handler.
|
||||
|
||||
* **`callback`**: Function to call
|
||||
|
||||
#### AsyncMqttClient& onDisconnect(AsyncMqttClientInternals::OnDisconnectUserCallback `callback`)
|
||||
|
||||
Add a disconnect event handler.
|
||||
|
||||
* **`callback`**: Function to call
|
||||
|
||||
#### AsyncMqttClient& onSubscribe(AsyncMqttClientInternals::OnSubscribeUserCallback `callback`)
|
||||
|
||||
Add a subscribe acknowledged event handler.
|
||||
|
||||
* **`callback`**: Function to call
|
||||
|
||||
#### AsyncMqttClient& onUnsubscribe(AsyncMqttClientInternals::OnUnsubscribeUserCallback `callback`)
|
||||
|
||||
Add an unsubscribe acknowledged event handler.
|
||||
|
||||
* **`callback`**: Function to call
|
||||
|
||||
#### AsyncMqttClient& onMessage(AsyncMqttClientInternals::OnMessageUserCallback `callback`)
|
||||
|
||||
Add a publish received event handler.
|
||||
|
||||
* **`callback`**: Function to call
|
||||
|
||||
#### AsyncMqttClient& onPublish(AsyncMqttClientInternals::OnPublishUserCallback `callback`)
|
||||
|
||||
Add a publish acknowledged event handler.
|
||||
|
||||
* **`callback`**: Function to call
|
||||
|
||||
### Operation functions
|
||||
|
||||
#### bool connected()
|
||||
|
||||
Return if the client is currently connected to the broker or not.
|
||||
|
||||
#### void connect()
|
||||
|
||||
Connect to the server.
|
||||
|
||||
#### void disconnect(bool `force` = false)
|
||||
|
||||
Disconnect from the server.
|
||||
|
||||
* **`force`**: Whether to force the disconnection. Defaults to `false` (clean disconnection).
|
||||
|
||||
#### uint16_t subscribe(const char\* `topic`, uint8_t `qos`)
|
||||
|
||||
Subscribe to the given topic at the given QoS.
|
||||
|
||||
Return the packet ID or 0 if failed.
|
||||
|
||||
* **`topic`**: Topic
|
||||
* **`qos`**: QoS
|
||||
|
||||
#### uint16_t unsubscribe(const char\* `topic`)
|
||||
|
||||
Unsubscribe from the given topic.
|
||||
|
||||
Return the packet ID or 0 if failed.
|
||||
|
||||
* **`topic`**: Topic
|
||||
|
||||
#### 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)
|
||||
|
||||
Publish a packet.
|
||||
|
||||
Return the packet ID (or 1 if QoS 0) or 0 if failed.
|
||||
|
||||
* **`topic`**: Topic
|
||||
* **`qos`**: QoS
|
||||
* **`retain`**: Retain flag
|
||||
* **`payload`**: Payload. If unset, the payload will be empty
|
||||
* **`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)`
|
||||
* **`dup`**: ~~Duplicate flag. If set or set to 1, the payload will be flagged as a duplicate~~ Setting is not used anymore
|
||||
* **`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
|
||||
|
||||
#### bool clearQueue()
|
||||
|
||||
When disconnected, clears all queued messages
|
||||
|
||||
Returns true on success, false on failure (client is no disconnected)
|
||||
12
AsyncMQTT_ESP32/docs/3.-Memory-management.md
Normal file
12
AsyncMQTT_ESP32/docs/3.-Memory-management.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Memory management
|
||||
|
||||
AsyncMqttClient buffers outgoing messages in a queue. On sending data is copied to a raw TCP buffer. Received data is passed directly to the API.
|
||||
|
||||
## Outgoing messages
|
||||
|
||||
You can send data as long as memory permits. A minimum amount of free memory is set at 4096 bytes. You can lower (or raise) this value by setting `MQTT_MIN_FREE_MEMORY` to your desired value.
|
||||
If the free memory was sufficient to send your packet, the `publish` method will return a packet ID indicating the packet was queued. Otherwise, a `0` will be returned, and it's your responsibility to resend the packet with `publish`.
|
||||
|
||||
## Incoming messages
|
||||
|
||||
No incoming data is buffered by this library. Messages received by the TCP library is passed directly to the API. The max receive size is about 1460 bytes per call to your onMessage callback but the amount of data you can receive is unlimited. If you receive, say, a 300kB payload (such as an OTA payload), then your `onMessage` callback will be called about 200 times, with the according len, index and total parameters. Keep in mind the library will call your `onMessage` callbacks with the same topic buffer, so if you change the buffer on one call, the buffer will remain changed on subsequent calls.
|
||||
19
AsyncMQTT_ESP32/docs/4.-Limitations-and-known-issues.md
Normal file
19
AsyncMQTT_ESP32/docs/4.-Limitations-and-known-issues.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Limitations and known issues
|
||||
|
||||
* The library is spec compliant with one limitation. In case of power loss the following is not honored:
|
||||
|
||||
> Must be kept in memory:
|
||||
* All messages in a QoS 1 or 2 flow, which are not confirmed by the broker
|
||||
* All received QoS 2 messages, which are not yet confirmed to the broker
|
||||
|
||||
This means retransmission is not honored in case of a power failure. This behaviour is like explained in point 4.1.1 of the MQTT specification v3.1.1
|
||||
|
||||
* You cannot send payload larger that what can fit on RAM.
|
||||
|
||||
## SSL limitations
|
||||
|
||||
* SSL requires the build flag -DASYNC_TCP_SSL_ENABLED=1
|
||||
* SSL only supports fingerprints for server validation.
|
||||
* If you do not specify one or more acceptable server fingerprints, the SSL connection will be vulnerable to man-in-the-middle attacks.
|
||||
* Some server certificate signature algorithms do not work. SHA1, SHA224, SHA256, and MD5 are working. SHA384, and SHA512 will cause a crash.
|
||||
* TLS1.2 is not supported.
|
||||
11
AsyncMQTT_ESP32/docs/5.-Troubleshooting.md
Normal file
11
AsyncMQTT_ESP32/docs/5.-Troubleshooting.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Troubleshooting
|
||||
|
||||
* The payload of incoming messages contains **raw data**. You cannot just print out the data without formatting. This is because Arduino's `print` functions expect a C-string as input and a MQTT payload is not. A simple solution is to print each character of the payload:
|
||||
|
||||
```cpp
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
Serial.print(payload[i]);
|
||||
}
|
||||
```
|
||||
|
||||
Further reading: https://en.wikipedia.org/wiki/C_string_handling
|
||||
4
AsyncMQTT_ESP32/docs/README.md
Normal file
4
AsyncMQTT_ESP32/docs/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
AsyncMqttClient documentation
|
||||
=============================
|
||||
|
||||
See [index.md](index.md) to view it locally, or http://marvinroger.viewdocs.io/async-mqtt-client/ to view it online.
|
||||
11
AsyncMQTT_ESP32/docs/index.md
Normal file
11
AsyncMQTT_ESP32/docs/index.md
Normal file
@@ -0,0 +1,11 @@
|
||||
Welcome to the AsyncMqttClient for ESP8266 docs.
|
||||
|
||||
**<p align="center">This documentation is only valid for the AsyncMqttClient version in this repo/directory</p>**
|
||||
|
||||
-----
|
||||
|
||||
#### 1. [Getting started](1.-Getting-started.md)
|
||||
#### 2. [API reference](2.-API-reference.md)
|
||||
#### 3. [Memory management](3.-Memory-management.md)
|
||||
#### 4. [Limitations and known issues](4.-Limitations-and-known-issues.md)
|
||||
#### 5. [Troubleshooting](5.-Troubleshooting.md)
|
||||
Reference in New Issue
Block a user