mirror of
https://github.com/gunner47/GyverLamp.git
synced 2025-08-09 01:40:59 +03:00
Добавлены библиотеки для работы с MQTT
This commit is contained in:
26
libraries/async-mqtt-client/docs/1.-Getting-started.md
Normal file
26
libraries/async-mqtt-client/docs/1.-Getting-started.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Getting started
|
||||
|
||||
To use AsyncMqttClient, you need:
|
||||
|
||||
* An ESP8266
|
||||
* The Arduino IDE for ESP8266 (version 2.2.0 minimum)
|
||||
* Basic knowledge of the Arduino environment (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: [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.
|
||||
|
||||
## 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).
|
160
libraries/async-mqtt-client/docs/2.-API-reference.md
Normal file
160
libraries/async-mqtt-client/docs/2.-API-reference.md
Normal file
@@ -0,0 +1,160 @@
|
||||
# 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 caracters>`.
|
||||
|
||||
* **`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
|
||||
* **`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
|
7
libraries/async-mqtt-client/docs/3.-Memory-management.md
Normal file
7
libraries/async-mqtt-client/docs/3.-Memory-management.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Memory management
|
||||
|
||||
AsyncMqttClient does not use an internal buffer, it uses the raw TCP buffer.
|
||||
|
||||
The max receive size is about 1460 bytes per call to your onMessage callback. But the amount of data you can receive is unlimited, as 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.
|
||||
|
||||
You can send data as long as you stay below the available TCP window (which is about 3-4kB on the ESP8266). The data is indeed held in memory by the async TCP code until ACK is received. If the TCP window was sufficient to send your packet, the `publish` method will return a packet ID indicating the packet was sent. Otherwise, a `0` will be returned, and it's your responsability to resend the packet with `publish`.
|
@@ -0,0 +1,19 @@
|
||||
# Limitations and known issues
|
||||
|
||||
* When the CleanSession is set to `false`, the implementation is not spec compliant. 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 failure.
|
||||
|
||||
* You cannot send payload larger that what can fit on RAM.
|
||||
|
||||
## SSL limitations
|
||||
|
||||
* SSL requires use of esp8266/Arduino 2.4.0, which is not yet released (platform = espressif8266_stage in PlatformIO).
|
||||
* 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.
|
3
libraries/async-mqtt-client/docs/5.-Troubleshooting.md
Normal file
3
libraries/async-mqtt-client/docs/5.-Troubleshooting.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Troubleshooting
|
||||
|
||||
To be completed when issues arise.
|
4
libraries/async-mqtt-client/docs/README.md
Normal file
4
libraries/async-mqtt-client/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
libraries/async-mqtt-client/docs/index.md
Normal file
11
libraries/async-mqtt-client/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