Giter Site home page Giter Site logo

thingsboard-arduino-sdk's Introduction

Arduino ThingsBoard SDK

Build Status

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

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.

thingsboard-arduino-sdk's People

Contributors

forgge avatar ashvayka avatar yuliia-vyl avatar imbeacon avatar ferchinas avatar r0g-dev avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.