/thingsboard-arduino-sdk

Arduino libarary to connect with ThingsBoard IoT Platform

Primary LanguageC++MIT LicenseMIT

Arduino ThingsBoard SDK

MIT license ESP32 ESP8266 Build Status GitHub release GitHub downloads

This library provides access to ThingsBoard platform over MQTT protocol.

Examples

The SDK comes with a number of example sketches. See File > Examples > ThingsBoard within the Arduino application. Please review the complete guide for ESP32 Pico Kit GPIO control and DHT22 sensor monitoring available here.

Installation

ThingsBoard SDK can be installed directly from the Arduino Library manager. Following dependencies must be installed, too:

Supported ThingsBoard Features

Example implementations for all features can be found in the examples folder.

Troubleshooting

Not enough space for JSON serialization

The buffer size for the serialized JSON is fixed to 64 bytes. The SDK will reject a data, if there is more data to be sent. Respective logs in the "Serial Monitor" window will indicate the condition:

[TB] too small buffer for JSON data

If that's a case, the buffer size for serialization should be increased. To do so, ThingsBoardSized class can be used in place of ThingsBoard as illustrated below:

// For the sake of example
WiFiEspClient espClient;

// The SDK setup with 64 bytes for JSON buffer
// ThingsBoard tb(espClient);

// The SDK setup with 128 bytes for JSON buffer
ThingsBoardSized<128> tb(espClient);

Too much data fields must be serialized

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 an error in the "Serial Monitor" window of the Arduino IDE:

[TB] too much JSON fields passed

The solution is to use ThingsBoardSized class instead of ThingsBoard. Note that the serialized JSON buffer size must be specified explicitly, as described here.

// For the sake of example
WiFiEspClient espClient;

// The SDK setup with 8 fields for JSON object
// ThingsBoard tb(espClient);

// The SDK setup with 128 bytes for JSON payload and 32 fields for JSON object.
ThingsBoardSized<128, 32> tb(espClient);

Tips and Tricks

To use your own logger you have to create a class and pass it as third parameter Logger to your ThingsBoardSized class instance.

For example:

class CustomLogger {
public:
  static void log(const char *error) {
    Serial.print("[Custom Logger] ");
    Serial.println(error);
  }
};

Your class must have method log with the same prototype as in the example. It will be called if some error occurs.

After that, you can use it in place of regular ThingsBoard class. Note that the serialized JSON buffer size must be specified explicitly, as described here.

// For the sake of example
WiFiEspClient espClient;

// The SDK setup with 8 fields for JSON object
// ThingsBoard tb(espClient);

// The SDK setup with 128 bytes for JSON payload and 32 fields for JSON object.
ThingsBoardSized<128, 32, CustomLogger> tb(espClient);

Have a question or proposal?

You are welcomed in our issues and Q&A forum.

License

This code is released under the MIT License.