Skip to content

Commit 5a5d27a

Browse files
authored
Merge pull request #142 from MathewHDYT/master
Implement non blocking OTA update over MQTT
2 parents 8f34b12 + 120f60a commit 5a5d27a

71 files changed

Lines changed: 2439 additions & 2106 deletions

File tree

Some content is hidden

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

.github/workflows/arduino-compile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- name: ArduinoJson
3434
- name: WiFiEsp
3535
- name: TinyGSM
36+
- name: StreamUtils
3637
3738
steps:
3839
- uses: actions/checkout@v3

.github/workflows/esp32-compile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- name: TBPubSubClient
3232
- name: ArduinoHttpClient
3333
- name: ArduinoJson
34+
- name: StreamUtils
3435
3536
strategy:
3637
matrix:

.github/workflows/esp8266-compile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- name: ArduinoHttpClient
3333
- name: ArduinoJson
3434
- name: Seeed_Arduino_mbedtls
35+
- name: StreamUtils
3536
3637
strategy:
3738
matrix:

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Example implementations for all base features, mentioned above, can be found in
5959

6060
### No PROGMEM support causing crashes
6161

62-
All constant variables are per default in flash memory to decrease the memory footprint of the library, if the libraries used or the board itself don't support `PROGMEM`. This can cause crashes to mitigate that simply add a `#define THINGSBOARD_ENABLE_PROGMEM 0` before including the ThingsBoard header file.
62+
If the device is crashing with an `Exception` especially `Exception (3)`, more specifically `LoadStoreError` or `LoadStoreErrorCause` this might be because, all constant variables are per default in flash memory to decrease the memory footprint of the library, if the libraries used or the board itself don't support `PROGMEM`. This can cause crashes to mitigate that simply add a `#define THINGSBOARD_ENABLE_PROGMEM 0` before including the ThingsBoard header file.
6363

6464
```c++
6565
// If not set otherwise the value is 1 per default if the pgmspace include exists,
@@ -86,7 +86,7 @@ To remove the need for the `MaxFieldsAmt` template argument in the constructor a
8686
The buffer size for the serialized JSON is fixed to 64 bytes. The SDK will not send data, if the size of it is bigger than the size originally passed in the constructor as a template argument (`PayLoadSize`). Respective logs in the `"Serial Monitor"` window will indicate the condition:
8787

8888
```
89-
[TB] Buffer size (64) to small for the given payloads size (83), increase with setBufferSize accordingly
89+
[TB] Buffer size (64) to small for the given payloads size (83), increase with setBufferSize accordingly or set THINGSBOARD_ENABLE_STREAM_UTILS to 1 before including ThingsBoard
9090
```
9191
9292
If that's a case, the buffer size for serialization should be increased. To do so, `setBufferSize()` method can be used or alternatively the `bufferSize` passed to the constructor can be increased as illustrated below:
@@ -107,6 +107,19 @@ void setup() {
107107
}
108108
```
109109

110+
Alternatively it is possible to enable the mentioned `THINGSBOARD_ENABLE_STREAM_UTILS` option, which sends messages that are bigger than the given buffer size with a method that skips the internal buffer, be aware tough this only works for sent messages. The internal buffer size still has to be big enough to receive the biggest possible message received by the client that is sent by the server.
111+
112+
```cpp
113+
// Enable skipping usage of the buffer for sends that are bigger than the internal buffer size
114+
#define THINGSBOARD_ENABLE_STREAM_UTILS 1
115+
116+
// For the sake of example
117+
WiFiEspClient espClient;
118+
119+
// The SDK setup with 64 bytes for JSON buffer
120+
ThingsBoard tb(espClient);
121+
```
122+
110123
### Too much data fields must be serialized
111124
112125
A buffer allocated internally by `ArduinoJson` library is fixed and is capable for processing not more than 8 fields. If you are trying to send more than that, you will get a respective log showing an error in the `"Serial Monitor"` window:

examples/0000-arduino_send_telemetry/0000-arduino_send_telemetry.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ constexpr uint16_t THINGSBOARD_PORT = 1883U;
4545
// Maximum size packets will ever be sent or received by the underlying MQTT client,
4646
// if the size is to small messages might not be sent or received messages will be discarded
4747
#if THINGSBOARD_ENABLE_PROGMEM
48-
constexpr uint32_t MAX_MESSAGE_SIZE PROGMEM = 128U;
48+
constexpr uint16_t MAX_MESSAGE_SIZE PROGMEM = 128U;
4949
#else
50-
constexpr uint32_t MAX_MESSAGE_SIZE = 128U;
50+
constexpr uint16_t MAX_MESSAGE_SIZE = 128U;
5151
#endif
5252

5353
// Baud rate for the debugging serial connection
@@ -90,7 +90,7 @@ void InitWiFi() {
9090
// Attempting to establish a connection to the given WiFi network
9191
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
9292
while (WiFi.status() != WL_CONNECTED) {
93-
// Delay 500ms until a connection has been succesfully established
93+
// Delay 500ms until a connection has been successfully established
9494
delay(500);
9595
#if THINGSBOARD_ENABLE_PROGMEM
9696
Serial.print(F("."));
@@ -159,7 +159,7 @@ void loop() {
159159
if (!tb.connected()) {
160160
// Reconnect to the ThingsBoard server,
161161
// if a connection was disrupted or has not yet been established
162-
char message[ThingsBoard::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
162+
char message[Helper::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
163163
snprintf_P(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
164164
Serial.println(message);
165165
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
@@ -180,8 +180,8 @@ void loop() {
180180
// Uploads new telemetry to ThingsBoard using MQTT.
181181
// See https://thingsboard.io/docs/reference/mqtt-api/#telemetry-upload-api
182182
// for more details
183-
tb.sendTelemetryInt(TEMPERATURE_KEY, random(10, 31));
184-
tb.sendTelemetryInt(HUMIDITY_KEY, random(40, 90));
183+
tb.sendTelemetryData(TEMPERATURE_KEY, random(10, 31));
184+
tb.sendTelemetryData(HUMIDITY_KEY, random(40, 90));
185185

186186
tb.loop();
187187
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Sending telemetry data
22

33
## Devices
4-
| Supported Devcies |
4+
| Supported Devices |
55
|-------------------|
66
| Arduino Uno |
77
| ESP8266 |
@@ -10,6 +10,6 @@
1010
[Telemetry](https://thingsboard.io/docs/user-guide/telemetry/)
1111

1212
## Feature
13-
Allows to upload telemetry values to the cloud, compared to attributes
13+
Allows uploading telemetry values to the cloud, compared to attributes
1414
these values keep track of their previous values meaning we can draw graphs with them.
15-
Meant for values wich change over time and where a history might be useful (temperature, humidity, ...)
15+
Meant for values which change over time and where a history might be useful (temperature, humidity, ...)

examples/0001-arduino_send_batch/0001-arduino_send_batch.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ constexpr uint16_t THINGSBOARD_PORT = 1883U;
4545
// Maximum size packets will ever be sent or received by the underlying MQTT client,
4646
// if the size is to small messages might not be sent or received messages will be discarded
4747
#if THINGSBOARD_ENABLE_PROGMEM
48-
constexpr uint32_t MAX_MESSAGE_SIZE PROGMEM = 128U;
48+
constexpr uint16_t MAX_MESSAGE_SIZE PROGMEM = 128U;
4949
#else
50-
constexpr uint32_t MAX_MESSAGE_SIZE = 128U;
50+
constexpr uint16_t MAX_MESSAGE_SIZE = 128U;
5151
#endif
5252

5353
// Baud rate for the debugging serial connection
@@ -96,7 +96,7 @@ void InitWiFi() {
9696
// Attempting to establish a connection to the given WiFi network
9797
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
9898
while (WiFi.status() != WL_CONNECTED) {
99-
// Delay 500ms until a connection has been succesfully established
99+
// Delay 500ms until a connection has been successfully established
100100
delay(500);
101101
#if THINGSBOARD_ENABLE_PROGMEM
102102
Serial.print(F("."));
@@ -160,7 +160,7 @@ void loop() {
160160
if (!tb.connected()) {
161161
// Reconnect to the ThingsBoard server,
162162
// if a connection was disrupted or has not yet been established
163-
char message[ThingsBoard::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
163+
char message[Helper::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
164164
snprintf_P(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
165165
Serial.println(message);
166166
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Sending telemetry / attribute data
22

33
## Devices
4-
| Supported Devcies |
4+
| Supported Devices |
55
|-------------------|
66
| Arduino Uno |
77
| ESP8266 |
@@ -11,7 +11,7 @@
1111
[Attributes](https://thingsboard.io/docs/user-guide/attributes/)
1212

1313
## Feature
14-
Allows to upload telemetry values to the cloud, as well as attributes.
14+
Allows uploading telemetry values to the cloud, as well as attributes.
1515
Telemetry values keep track of their previous values meaning we can draw graphs with them.
16-
Meant for values wich change over time and where a history might be useful (temperature, humidity, ...)
17-
Where as attributes are meant for data, which does not require a history and is more seldomly updated (version, settings, ...)
16+
Meant for values which change over time and where a history might be useful (temperature, humidity, ...)
17+
Whereas attributes are meant for data, which does not require a history and is more seldom updated (version, settings, ...)

examples/0002-arduino_rpc/0002-arduino_rpc.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ constexpr uint16_t THINGSBOARD_PORT = 1883U;
4545
// Maximum size packets will ever be sent or received by the underlying MQTT client,
4646
// if the size is to small messages might not be sent or received messages will be discarded
4747
#if THINGSBOARD_ENABLE_PROGMEM
48-
constexpr uint32_t MAX_MESSAGE_SIZE PROGMEM = 128U;
48+
constexpr uint16_t MAX_MESSAGE_SIZE PROGMEM = 128U;
4949
#else
50-
constexpr uint32_t MAX_MESSAGE_SIZE = 128U;
50+
constexpr uint16_t MAX_MESSAGE_SIZE = 128U;
5151
#endif
5252

5353
// Baud rate for the debugging serial connection
@@ -99,7 +99,7 @@ void InitWiFi() {
9999
// Attempting to establish a connection to the given WiFi network
100100
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
101101
while (WiFi.status() != WL_CONNECTED) {
102-
// Delay 500ms until a connection has been succesfully established
102+
// Delay 500ms until a connection has been successfully established
103103
delay(500);
104104
#if THINGSBOARD_ENABLE_PROGMEM
105105
Serial.print(F("."));
@@ -221,7 +221,7 @@ void loop() {
221221
if (!tb.connected()) {
222222
// Reconnect to the ThingsBoard server,
223223
// if a connection was disrupted or has not yet been established
224-
char message[ThingsBoard::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
224+
char message[Helper::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
225225
snprintf_P(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
226226
Serial.println(message);
227227
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {

examples/0002-arduino_rpc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Calling methods from the cloud on this device (Server-side RPC)
22

33
## Devices
4-
| Supported Devcies |
4+
| Supported Devices |
55
|-------------------|
66
| Arduino Uno |
77
| ESP8266 |

0 commit comments

Comments
 (0)