Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2c7b23f
Fix typo when using StreamUtils
MathewHDYT Dec 26, 2024
bd19f92
Fix wrong example #244
MathewHDYT Dec 30, 2024
b6dfafe
Fix invalid forwarded constructor call to std::vector
MathewHDYT Dec 30, 2024
03beab4
Merge branch 'thingsboard:master' into master
MathewHDYT Feb 8, 2025
74e70e7
Update deprecated version in workflow
MathewHDYT Feb 8, 2025
e63de1e
Fix disconnect on provision #248. Fix #245
MathewHDYT Feb 9, 2025
6516104
Add state information to MQTT connection
MathewHDYT Feb 10, 2025
07f4693
Adjust Arduino client to changes
MathewHDYT Feb 10, 2025
8defe06
Fix typo with missing semicolon
MathewHDYT Feb 10, 2025
eb90537
Fix typo
MathewHDYT Feb 10, 2025
f93c71f
Add missing class specifier to methods
MathewHDYT Feb 10, 2025
79c098f
Fix order of log messages
MathewHDYT Feb 11, 2025
d341e68
Fix possible array capacity of 0 #239.
MathewHDYT Feb 13, 2025
d1709fb
Adjust naming and comments and fix example #250
MathewHDYT Feb 17, 2025
5ca35ca
Add additional debug log messages to OTA
MathewHDYT Feb 21, 2025
14bcf71
Add virtual destructor to all base clases
MathewHDYT Feb 21, 2025
274d742
Bump version number
MathewHDYT Feb 28, 2025
eac8412
Fix OTA disconnect issue #253 and adjust examples to changes. Add new…
MathewHDYT Mar 16, 2025
5158ad6
Fix cmake for new example
MathewHDYT Mar 16, 2025
e84241f
Fix new example missing return
MathewHDYT Mar 16, 2025
295a73e
Add a nullptr check when OTA gets cancelled within progress callback
mwesenjak Apr 4, 2025
8a6038c
Improve implementation readability and start adjusting all comments.
MathewHDYT Apr 13, 2025
a30ad92
Fix compiler warnings
MathewHDYT Apr 13, 2025
20bf865
Readd arduinojson settings override
MathewHDYT Apr 13, 2025
2f71b47
Improve comments and HashGenerator API
MathewHDYT Jul 22, 2025
43b788a
Fix typo and remove c++ STL include
MathewHDYT Jul 22, 2025
6c1b0a8
Fix #261 memory leak, by calling destructor on container elements and…
MathewHDYT Jul 25, 2025
2ab16e3
Adjust new code to be compatible with non STL boards
MathewHDYT Jul 25, 2025
22374a2
Revert constness for Interface. Does nto work because getters are non…
MathewHDYT Jul 25, 2025
f4b6e59
Fix compilation issues
MathewHDYT Jul 25, 2025
115e4be
Update all remaning comments on classes
MathewHDYT Jul 27, 2025
163f2bc
Fix typo
MathewHDYT Jul 27, 2025
8adfe16
Move request timeout functionality into seperate class
MathewHDYT Jul 28, 2025
db239e1
Fix compilation issues
MathewHDYT Jul 28, 2025
b605fab
Fix missing adjustment to new class
MathewHDYT Jul 28, 2025
6182144
Fix typo
MathewHDYT Jul 28, 2025
912ce4e
Fix more typos
MathewHDYT Jul 28, 2025
b4506a6
Fix rpc timeout stop
MathewHDYT Jul 28, 2025
3f8eda5
Add missing source file to CMake
MathewHDYT Jul 28, 2025
9c00098
Remove unnecessary include
MathewHDYT Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/arduino-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
platform-name: avr:mega

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Compile examples
uses: arduino/compile-sketches@v1
Expand All @@ -65,7 +65,7 @@ jobs:

- name: Save memory usage change report as artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: ${{ env.SKETCHES_REPORTS_NAME }}
Expand All @@ -78,7 +78,7 @@ jobs:
steps:
# This step is needed to get the size data produced by the build jobs
- name: Download sketches reports artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: ${{ env.SKETCHES_REPORTS_NAME }}
path: ${{ env.SKETCHES_REPORTS_PATH }}/${{ env.SKETCHES_REPORTS_NAME }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/esp32-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install ESP32 platform dependencies
if: matrix.board.platform-name == 'esp32:esp32'
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:

- name: Save memory usage change report as artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: ${{ env.SKETCHES_REPORTS_NAME }}
Expand All @@ -90,7 +90,7 @@ jobs:
steps:
# This step is needed to get the size data produced by the build jobs
- name: Download sketches reports artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: ${{ env.SKETCHES_REPORTS_NAME }}
path: ${{ env.SKETCHES_REPORTS_PATH }}/${{ env.SKETCHES_REPORTS_NAME }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/esp8266-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
version: 3.1.1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Compile examples
uses: arduino/compile-sketches@v1
Expand All @@ -76,7 +76,7 @@ jobs:

- name: Save memory usage change report as artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: ${{ env.SKETCHES_REPORTS_NAME }}
Expand All @@ -89,7 +89,7 @@ jobs:
steps:
# This step is needed to get the size data produced by the build jobs
- name: Download sketches reports artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: ${{ env.SKETCHES_REPORTS_NAME }}
path: ${{ env.SKETCHES_REPORTS_PATH }}/${{ env.SKETCHES_REPORTS_NAME }}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/espidf-compile-v4.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Build send data example on v4.4
Expand Down Expand Up @@ -54,3 +54,9 @@ jobs:
esp_idf_version: v4.4
target: esp32
path: 'examples/0018-espressif_esp32_provision_device'
- name: Build process connection state example on v4.4
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v4.4
target: esp32
path: 'examples/0020-espressif_esp32_connection_state'
8 changes: 7 additions & 1 deletion .github/workflows/espidf-compile-v5.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Build send data example on v5.1
Expand Down Expand Up @@ -54,3 +54,9 @@ jobs:
esp_idf_version: v5.1
target: esp32
path: 'examples/0018-espressif_esp32_provision_device'
- name: Build process connection state example on v5.1
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.1
target: esp32
path: 'examples/0020-espressif_esp32_connection_state'
2 changes: 1 addition & 1 deletion .github/workflows/espressif_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
upload_components:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: "recursive"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Build doxygen documentation
uses: mattnotmitt/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Vscode settings
.vscode

# Prerequisites
*.d

Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(srcs
src/Provision_Callback.cpp
src/RPC_Request_Callback.cpp
src/Telemetry.cpp
src/Timeoutable_Request.cpp
)

set(dependencies
Expand All @@ -37,4 +38,4 @@ if(ESP_PLATFORM)
return()
endif()

project(ThingsBoardClientSDK VERSION 0.15.0)
project(ThingsBoardClientSDK VERSION 0.16.0)
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ All internal methods call attempt to utilize the stack as far as possible and co

### Too much data fields must be serialized

The `sendAttributes` and `sendTelemetry` methods, use the [`StaticJsonDocument`](https://arduinojson.org/v6/api/staticjsondocument/) this requires the `MaxKeyValuePairAmount` template argument to be passed in the method template list. If more key-value pairs are sent than specified, the `"Serial Monitor"` window will get a respective log showing an error:
The `Send_Attributes` and `Send_Telemetry` methods, use the [`StaticJsonDocument`](https://arduinojson.org/v6/api/staticjsondocument/) this requires the `MaxKeyValuePairAmount` template argument to be passed in the method template list. If more key-value pairs are sent than specified, the `"Serial Monitor"` window will get a respective log showing an error:

```
[TB] Unable to serialize key-value json
Expand Down Expand Up @@ -214,7 +214,7 @@ Alternatively to remove the need for the `MaxResponse`template argument in the c
The possible event subscription classes that are passed to internal methods, use arrays which reside on the stack those require the `MaxSubscriptions` template argument to be passed in the constructor template list. The default value is 1, if the method call attempts to subscribe more than that many events in total, the `"Serial Monitor"` window will get a respective log showing an error:

```
[TB] Too many shared attribute update subscriptions, increase MaxSubscriptions or unsubscribe
[TB] Too many (shared attribute update) subscriptions, increase (MaxSubscriptions) or unsubscribe"
```

Important is that both server-side RPC and request attribute values are temporary, meaning once the request has been received it is deleted, and it is therefore possible to subscribe another event again. However, all other subscriptions like client-side RPC or attribute update subscription are permanent meaning once the event has been subscribed we can only unsubscribe all events to make more room.
Expand Down Expand Up @@ -367,27 +367,29 @@ For that a `class` needs to inherit the `API_Implemenatation` class and `overrid

class Custom_API_Implementation : public IAPI_Implementation {
public:
~Custom_API_Implementation() override = default;

API_Process_Type Get_Process_Type() override {
return API_Process_Type::JSON;
}

void Process_Response(char const * topic, uint8_t * payload, unsigned int length) override {
void Process_Response(char const * topic, uint8_t * payload, uint32_t length) override {
// Nothing to do
}

void Process_Json_Response(char const * topic, JsonDocument const & data) override {
// Nothing to do
}

bool Compare_Response_Topic(char const * topic) const override {
bool Is_Response_Topic_Matching(char const * topic) const override {
return true;
}

bool Unsubscribe() override {
return true;
}

bool Resubscribe_Topic() override {
bool Resubscribe_Permanent_Subscriptions() override {
return true;
}

Expand All @@ -401,7 +403,7 @@ class Custom_API_Implementation : public IAPI_Implementation {
// Nothing to do
}

void Set_Client_Callbacks(Callback<void, IAPI_Implementation &>::function subscribe_api_callback, Callback<bool, char const * const, JsonDocument const &, size_t const &>::function send_json_callback, Callback<bool, char const * const, char const * const>::function send_json_string_callback, Callback<bool, char const * const>::function subscribe_topic_callback, Callback<bool, char const * const>::function unsubscribe_topic_callback, Callback<uint16_t>::function get_receive_size_callback, Callback<uint16_t>::function get_send_size_callback, Callback<bool, uint16_t, uint16_t>::function set_buffer_size_callback, Callback<size_t *>::function get_request_id_callback) override {
void Set_Client_Callbacks(Callback<void, IAPI_Implementation &>::function subscribe_api_callback, Callback<bool, char const * const, JsonDocument const &>::function send_json_callback, Callback<bool, char const * const, char const * const>::function send_json_string_callback, Callback<bool, char const * const>::function subscribe_topic_callback, Callback<bool, char const * const>::function unsubscribe_topic_callback, Callback<uint16_t>::function get_receive_size_callback, Callback<uint16_t>::function get_send_size_callback, Callback<bool, uint16_t, uint16_t>::function set_buffer_size_callback, Callback<size_t *>::function get_request_id_callback) override {
// Nothing to do
}
};
Expand Down Expand Up @@ -452,6 +454,10 @@ For that a `class` needs to inherit the `IUpdater` interface and `override` the

class Custom_Updater : public IUpdater {
public:
~Custom_Updater() override {
reset();
}

bool begin(size_t const & firmware_size) override {
return true;
}
Expand Down Expand Up @@ -497,6 +503,8 @@ For that a `class` needs to inherit the `IHTTP_Client` interface and `override`

class Custom_HTTP_Client : public IHTTP_Client {
public:
~Custom_HTTP_Client() override = default;

void set_keep_alive(bool keep_alive) override {
// Nothing to do
}
Expand Down Expand Up @@ -565,6 +573,8 @@ For that a `class` needs to inherit the `IMQTT_Client` interface and `override`

class Custom_MQTT_Client : public IMQTT_Client {
public:
~Custom_MQTT_Client() override = default;

void set_data_callback(Callback<void, char *, uint8_t *, unsigned int>::function callback) override {
// Nothing to do
}
Expand All @@ -577,7 +587,11 @@ class Custom_MQTT_Client : public IMQTT_Client {
return true;
}

uint16_t get_buffer_size() override {
uint16_t get_receive_buffer_size() override {
return 0U;
}

uint16_t get_send_buffer_size() override {
return 0U;
}

Expand Down Expand Up @@ -613,6 +627,18 @@ class Custom_MQTT_Client : public IMQTT_Client {
return true;
}

MQTT_Connection_State get_connection_state() override {
return MQTT_Connection_State::DISCONNECTED;
}

MQTT_Connection_Error get_last_connection_error() override {
return MQTT_Connection_Error::NONE;
}

void subscribe_connection_state_changed_callback(Callback<void, MQTT_Connection_State, MQTT_Connection_Error>::function callback) override;
// Nothing to do
}

#if THINGSBOARD_ENABLE_STREAM_UTILS

bool begin_publish(char const * topic, size_t const & length) override {
Expand Down Expand Up @@ -688,7 +714,7 @@ Arduino_MQTT_Client mqttClient(espClient);
// ThingsBoard tb(mqttClient);

// The SDK setup with 128 bytes for JSON payload and 32 fields for JSON object
ThingsBoardSized<32, Default_Response_Amount, CustomLogger> tb(mqttClient, 128, 128);
ThingsBoardSized<32, DEFAULT_RESPONSE_AMOUNT, CustomLogger> tb(mqttClient, 128, 128);
```

## Have a question or proposal?
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "ThingsBoard Client SDK"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.15.0
PROJECT_NUMBER = 0.16.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void loop() {
if (!tb.connected()) {
// Reconnect to the ThingsBoard server,
// if a connection was disrupted or has not yet been established
char message[Helper::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
char message[Helper::Calculate_Print_Size(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
snprintf(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
Serial.println(message);
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
Expand All @@ -128,8 +128,8 @@ void loop() {
// Uploads new telemetry to ThingsBoard using MQTT.
// See https://thingsboard.io/docs/reference/mqtt-api/#telemetry-upload-api
// for more details
tb.sendTelemetryData(TEMPERATURE_KEY, random(10, 31));
tb.sendTelemetryData(HUMIDITY_KEY, random(40, 90));
tb.Send_Telemetry_Data(TEMPERATURE_KEY, random(10, 31));
tb.Send_Telemetry_Data(HUMIDITY_KEY, random(40, 90));

tb.loop();
}
6 changes: 3 additions & 3 deletions examples/0001-arduino_send_batch/0001-arduino_send_batch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void loop() {
if (!tb.connected()) {
// Reconnect to the ThingsBoard server,
// if a connection was disrupted or has not yet been established
char message[Helper::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
char message[Helper::Calculate_Print_Size(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
snprintf(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
Serial.println(message);
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
Expand Down Expand Up @@ -144,7 +144,7 @@ void loop() {
// for more details
Telemetry* begin = data;
Telemetry* end = data + TELEMETRY_SIZE;
tb.sendTelemetry<TELEMETRY_SIZE>(begin, end);
tb.Send_Telemetry<TELEMETRY_SIZE>(begin, end);

Serial.println("Sending attributes data...");

Expand All @@ -168,7 +168,7 @@ void loop() {
// for more details
begin = attributes;
end = attributes + ATTRIBUTES_SIZE;
tb.sendAttributes<ATTRIBUTES_SIZE>(begin, end);
tb.Send_Attributes<ATTRIBUTES_SIZE>(begin, end);

tb.loop();
}
4 changes: 2 additions & 2 deletions examples/0002-arduino_rpc/0002-arduino_rpc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IAPI_Implementation* apis[1U] = {
&rpc
};
// Initialize ThingsBoard instance with the maximum needed buffer sizes
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, Default_Max_Stack_Size, apis + 0U, apis + 1U);
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, DEFAULT_MAX_STACK_SIZE, apis + 0U, apis + 1U);


// Statuses for subscribing to rpc
Expand Down Expand Up @@ -182,7 +182,7 @@ void loop() {
if (!tb.connected()) {
// Reconnect to the ThingsBoard server,
// if a connection was disrupted or has not yet been established
char message[Helper::detectSize(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
char message[Helper::Calculate_Print_Size(CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN)];
snprintf(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
Serial.println(message);
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,19 @@ Arduino_MQTT_Client mqttClient(espClient);
// Initialize used apis
const std::array<IAPI_Implementation*, 0U> apis = {};
// Initialize ThingsBoard instance with the maximum needed buffer size
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, Default_Max_Stack_Size, apis);
#if THINGSBOARD_ENABLE_DYNAMIC
#if THINGSBOARD_ENABLE_STREAM_UTILS
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, DEFAULT_MAX_STACK_SIZE, DEFAULT_BUFFERING_SIZE, DEFAULT_MAX_RESPONSE_SIZE, apis.cbegin(), apis.cend());
#else
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, DEFAULT_MAX_STACK_SIZE, DEFAULT_MAX_RESPONSE_SIZE, apis.cbegin(), apis.cend());
#endif
#else
#if THINGSBOARD_ENABLE_STREAM_UTILS
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, DEFAULT_MAX_STACK_SIZE, DEFAULT_BUFFERING_SIZE, apis.cbegin(), apis.cend());
#else
ThingsBoard tb(mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, DEFAULT_MAX_STACK_SIZE, apis.cbegin(), apis.cend());
#endif
#endif
#endif


Expand Down Expand Up @@ -207,10 +219,10 @@ void loop() {
// See https://thingsboard.io/docs/reference/http-api/#telemetry-upload-api
// for more details
Serial.println("Sending temperature data...");
tb.sendTelemetryData(TEMPERATURE_KEY, random(10, 31));
tb.Send_Telemetry_Data(TEMPERATURE_KEY, random(10, 31));

Serial.println("Sending humidity data...");
tb.sendTelemetryData(HUMIDITY_KEY, random(40, 90));
tb.Send_Telemetry_Data(HUMIDITY_KEY, random(40, 90));

#if !USING_HTTPS
tb.loop();
Expand Down
Loading
Loading