Coder Social home page Coder Social logo

thingsboard / thingsboard-client-sdk Goto Github PK

View Code? Open in Web Editor NEW
134.0 11.0 114.0 753 KB

Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)

License: MIT License

C++ 96.25% C 3.43% CMake 0.32%
thingsboard mqtt arduino iot embedded mcu esp32 esp8266 arduino-library arduino-nano-rp2040

thingsboard-client-sdk's Introduction

Client SDK to connect with ThingsBoard IoT Platform from various IoT devices (Arduino, Espressif, etc.)

MIT license ESP32 ESP8266 GitHub release GitHub downloads Arduino actions status Espressif IDF v4.4 actions status Espressif IDF v5.1 actions status ESP32 actions status ESP8266 actions status GitHub stars

This library provides access to the ThingsBoard platform over the MQTT or HTTP(S) protocols.

Examples

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

Supported Frameworks

ThingsBoardArduinoSDK does not directly depend on any specific MQTT Client or HTTP Client implementation, instead any implementation of the IMQTT_Client or IHTTP Client can be used. Because there are no further dependencies on Arduino, besides the client that communicates it allows us to use this library with Arduino, when using the Arduino_MQTT_Client or with Espressif IDF when using the Espressif_MQTT_Client.

Example usage for Espressif can be found in the examples/0014-espressif_esp32_send_data folder, all other code portions can be implemented the same way only initialization of the needed dependencies is slightly different. Meaning internal call to ThingsBoard works the same on both Espressif and Arduino.

This is also the case, because the only always used dependency that is remaining, is ArduinoJson, which despite its name does not require any Arduino component.

Installation

This project can be built with either PlatformIO, ESP IDF Extension or Arduino IDE.

The project can be found in the PlatformIO Registry, ESP Component registry or the Arduino libraries.

A description on how to include the library in you project can be found below for each of the aforementioned possible methods of integrating the project.

PlatformIO

To add an external library, the most important portion is the lib_deps specification, simply add thingsboard/ThingsBoard. There are multiple ways to define the version that should be fetched, but the most basic is simply getting the last released version, with the aforementioned line, to learn more see Package Specifications.

lib_deps=
    thingsboard/ThingsBoard

ESP IDF Extension

To add an external library, what needs to be done differs between versions. If an ESP-IDF version after and including v3.2.0 is used then the project can simply be added over the Component Manager.

To do that we can simply call idf.py add-dependency <DEPENDENCY>, with the name of the dependency as an argument. Similar to PlatformIO there are a multiple way to define the version that should be fetched, but the method below is the most basic to simply get the last released version, to learn more see Using Component Manager with a Project.

idf.py add-dependency "thingsboard/ThingsBoard"

If an ESP-IDF version prior to v3.2.0 is used then the component has to be added as a git submodule. Meaning the repository has to first be a git project, if that is not the case already simply install git and call git init in the folder containing your project.

Similar to the other call there are a multiple way to define the version that should be fetched, but the method below is the most basic to simply get the last released version, to learn more see Git Submodule Help page.

git submodule add https://github.com/thingsboard/thingsboard-arduino-sdk.git components/ThingsBoard

Arduino IDE

To add an external library, we simply have to open Tools -> Manage Libraries and then search for ThingsBoard then press the install button for the wanted version. See how to install library on Arduino IDE for more detailed information and some troubleshooting if the aforementioned method does not work.

Dependencies

Following dependencies are installed automatically or must be installed, too:

Installed automatically:

  • ArduinoJSON — needed for dealing with the JSON payload that is sent to and received by ThingsBoard Installed automatically, but you can remove them if you don't need them:
  • MQTT PubSub Client — for interacting with MQTT, when using the Arduino_MQTT_Client instance as an argument to ThingsBoard.
  • Arduino Http Client — for interacting with HTTP/S when using the Arduino_HTTP_Client instance as an argument to ThingsBoardHttp. Needs to be installed manually:
  • MbedTLS Library — needed to create hashes for the OTA update (ESP8266 only, already included in ESP32 base firmware).
  • WiFiEsp Client — needed when using a Arduino Uno with a ESP8266.
  • StreamUtils — needed if #define THINGSBOARD_ENABLE_STREAM_UTILS 1 is set, it allows sending arbitrary amount of payload even if the buffer size is too small to hold that complete payload

Supported ThingsBoard Features

Over MQTT:

All possible features are implemented over MQTT:

Over HTTP(S):

The remaining features have to be implemented by hand with the sendGetRequest or sendPostRequest method. See the ThingsBoard Documentation on how these features could be implemented.

Example implementations for all base features, mentioned above, can be found in the examples folder. See the according README.md, to see which boards are supported and which functionality the example shows.

Troubleshooting

This troubleshooting guide contains common issues that are well known and can occur if the library is used wrongly. Ensure to read this section before creating a new GitHub Issue.

No PROGMEM support causing crashes

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 add a #define THINGSBOARD_ENABLE_PROGMEM 0 before including the ThingsBoard header file.

// If not set otherwise the value is 1 per default if the pgmspace include exists,
// set to 0 if the board has problems with PROGMEM variables and does not seem to work correctly.
#define THINGSBOARD_ENABLE_PROGMEM 0
#include <ThingsBoard.h>

Dynamic ThingsBoard usage

The received JSON payload, as well as the sendAttributes and sendTelemetry methods, use the StaticJsonDocument by default, this furthermore requires the MaxFieldsAmt template argument passed in the constructor. To set the size the buffer should have, where bigger messages will cause not sent/received key-value pairs or failed de-/serialization.

To remove the need for the MaxFieldsAmt template argument in the constructor and ensure the size the buffer should have is always enough to hold the sent or received messages, instead #define THINGSBOARD_ENABLE_DYNAMIC 1 can be set before including the ThingsBoard header file. This makes the library use the DynamicJsonDocument instead of the default StaticJsonDocument.

// If not set otherwise the value is 0 per default,
// set to 1 if the MaxFieldsAmt template argument should not be required.
#define THINGSBOARD_ENABLE_DYNAMIC 1
#include <ThingsBoard.h>

Not enough space for JSON serialization

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:

[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

If that's the case, the buffer size for serialization should be increased. To do so, setBufferSize() method can be used or the bufferSize passed to the constructor can be increased as illustrated below:

// For the sake of example
WiFiEspClient espClient;

// Initalize the Mqtt client instance
Arduino_MQTT_Client mqttClient(espClient);

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

// The SDK setup with 128 bytes for JSON buffer
ThingsBoard tb(mqttClient, 128);

void setup() {
  // Increase internal buffer size after inital creation.
  tb.setBufferSize(128);
}

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.

// Enable skipping usage of the buffer for sends that are bigger than the internal buffer size
#define THINGSBOARD_ENABLE_STREAM_UTILS 1

// For the sake of example
WiFiEspClient espClient;

// Initalize the Mqtt client instance
Arduino_MQTT_Client mqttClient(espClient);

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

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 a respective log showing an error in the "Serial Monitor" window:

[TB] Too many JSON fields passed (26), increase MaxFieldsAmt (8) accordingly

The solution is to use ThingsBoardSized class instead of ThingsBoard. Note that the serialized JSON buffer size must be specified explicitly, as described here. See Dynamic ThingsBoard Usage above if the usage of MaxFieldsAmt, should be replaced with automatic detection of the needed size.

// For the sake of example
WiFiEspClient espClient;

// Initalize the Mqtt client instance
Arduino_MQTT_Client mqttClient(espClient);

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

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

Tips and Tricks

Custom Updater Instance

When using the ThingsBoard class instance, the class used to flash the binary data onto the device is not hard coded, but instead the OTA_Update_Callback class expects an optional argument, the IUpdater implementation.

Thanks to it being a interface it allows an arbitrary implementation, meaning as long as the device can flash binary data and supports the C++ STL it supports OTA updates, with the ThingsBoard library.

Currently, implemented in the library itself are the ESP32_Updater, which is used for flashing the binary data when using a ESP32 and the ESP8266_Updater which is used with the ESP8266. If another device wants to be supported, a custom interface implementation needs to be created. For that a class that inherits the IUpdater interface needs to be created and override the needed methods.

#include <IUpdater.h>

class Custom_Updater : public IUpdater {
  public:
    bool begin(const size_t& firmware_size) override {
        return true;
    }
  
    size_t write(uint8_t* payload, const size_t& total_bytes) override {
        return total_bytes;
    }
  
    void reset() override {
        // Nothing to do
    }
  
    bool end() override {
        return true;
    }
};

Custom HTTP Instance

When using the ThingsBoardHttp class instance, the protocol used to send the data to the HTTP broker is not hard coded, but instead the ThingsBoardHttp class expects the argument to a IHTTP_Client implementation.

Thanks to it being a interface it allows an arbitrary implementation, meaning the underlying HTTP client can be whatever the user decides, so it can for example be used to support platforms using Arduino or even Espressif IDF.

Currently, implemented in the library itself is the Arduino_HTTP_Client, which is simply a wrapper around the ArduinoHttpClient, see dependencies for whether the board you are using is supported or not. If another device wants to be supported, a custom interface implementation needs to be created. For that a class that inherits the IHTTP_Client interface needs to be created and override the needed methods.

#include <IHTTP_Client.h>

class Custom_HTTP_Client : public IHTTP_Client {
  public:
    void set_keep_alive(const bool& keep_alive) override {
        // Nothing to do
    }

    int connect(const char *host, const uint16_t& port) override {
        return 0;
    }

    void stop() override {
        // Nothing to do
    }

    int post(const char *url_path, const char *content_type, const char *request_body) override {
        return 0;
    }

    int get_response_status_code() override {
        return 200;
    }

    int get(const char *url_path) override{
        return 0;
    }

    String get_response_body() override{
        return String();
    }
};

Custom MQTT Instance

When using the ThingsBoard class instance, the protocol used to send the data to the MQTT broker is not hard coded, but instead the ThingsBoard class expects the argument to a IMQTT_Client implementation.

Thanks to it being a interface it allows an arbitrary implementation, meaning the underlying MQTT client can be whatever the user decides, so it can for example be used to support platforms using Arduino or even Espressif IDF.

Currently, implemented in the library itself is the Arduino_MQTT_Client, which is simply a wrapper around the TBPubSubClient, see compatible Hardware for whether the board you are using is supported or not. If another device wants to be supported, a custom interface implementation needs to be created. For that a class that inherits the IMQTT_Client interface needs to be created and override the needed methods.

#include <IMQTT_Client.h>

class Custom_MQTT_Client : public IMQTT_Client {
  public:
    void set_callback(function cb) override {
        // Nothing to do
    }

    bool set_buffer_size(const uint16_t& buffer_size) override{
        return true;
    }

    uint16_t get_buffer_size() override  {
        return 0U;
    }

    void set_server(const char *domain, const uint16_t& port) override {
        // Nothing to do
    }

    bool connect(const char *client_id, const char *user_name, const char *password) override {
        return true;
    }

    void disconnect() override {
        // Nothing to do
    }

    bool loop() override {
        return true;
    }

    bool publish(const char *topic, const uint8_t *payload, const size_t& length) override {
        return true;
    }

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

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

    bool connected() override {
        return true;
    }

#if THINGSBOARD_ENABLE_STREAM_UTILS

    bool begin_publish(const char *topic, const size_t& length) override {
        return true;
    }

    bool end_publish() override {
        return true;
    }

    //----------------------------------------------------------------------------
    // Print interface
    //----------------------------------------------------------------------------

    size_t write(uint8_t payload_byte) override {
        return 1U;
    }

    size_t write(const uint8_t *buffer, size_t size) override {
        return size;
    }

#endif // THINGSBOARD_ENABLE_STREAM_UTILS
};

Custom Logger Instance

To use your own logger you have to create a class and pass it as second template 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 the method log with the same prototype as in the example. It will be called if the library needs to print any log messages.

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

// For the sake of example
WiFiEspClient espClient;

// Initalize the Mqtt client instance
Arduino_MQTT_Client mqttClient(espClient);

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

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

Have a question or proposal?

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

License

This code is released under the MIT License.

thingsboard-client-sdk's People

Contributors

adrienadb avatar ashvayka avatar chrschultz avatar ferchinas avatar forgge avatar imbeacon avatar mathewhdyt avatar nhuhs1887 avatar oekosolvemg avatar r0g-dev avatar spirosbond avatar traceyflanders avatar yuliia-vyl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thingsboard-client-sdk's Issues

A number of problems when compiling the library version 0.7.0

Hi!
I tried to compile my program with version 0.7.0 of the library, but it didn't work because I got a number of errors.
Since the program is quite large, I tried to compile one of the examples. When compiling the OTA example, I got some of the same errors as when compiling my program.

An example is this one:
https://github.com/thingsboard/thingsboard-arduino-sdk/tree/master/examples/0009-esp8266_esp32_process_OTA_MQTT
I am using VSCode and PlatformIO

Full compilation log:

Processing mhetesp32devkit (platform: espressif32; board: mhetesp32devkit; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/mhetesp32devkit.html
PLATFORM: Espressif 32 (4.4.0) > MH ET LIVE ESP32DevKIT
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20003.220619 (2.0.3)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 35 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ThingsBoard @ 0.6.0+sha.c6bb284
|   |-- ArduinoJson @ 6.19.4+sha.7c2ca77
|   |-- PubSubClient @ 2.8.0+sha.2d228f2
|   |-- Update @ 2.0.0
|-- PubSubClient @ 2.8.0+sha.2d228f2
|-- ArduinoJson @ 6.19.4+sha.7c2ca77
|-- WiFi @ 2.0.0
Building in release mode
Compiling .pio\build\mhetesp32devkit\src\main.cpp.o
Generating partitions .pio\build\mhetesp32devkit\partitions.bin
Compiling .pio\build\mhetesp32devkit\lib9fc\PubSubClient\PubSubClient.cpp.o
Compiling .pio\build\mhetesp32devkit\libe4f\Update\HttpsOTAUpdate.cpp.o
Compiling .pio\build\mhetesp32devkit\libe4f\Update\Updater.cpp.o
Compiling .pio\build\mhetesp32devkit\lib674\ThingsBoard\ThingsBoard.cpp.o
Compiling .pio\build\mhetesp32devkit\lib674\ThingsBoard\ThingsBoardDefaultLogger.cpp.o
Compiling .pio\build\mhetesp32devkit\libcf7\WiFi\WiFi.cpp.o
Compiling .pio\build\mhetesp32devkit\libcf7\WiFi\WiFiAP.cpp.o
Compiling .pio\build\mhetesp32devkit\libcf7\WiFi\WiFiClient.cpp.o
In file included from src/main.cpp:9:
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h: In instantiation of 'const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::Start_Firmware_Update(const char*, const char*, const std::function<void(const bool&)>&) [with unsigned int PayloadSize = 64; unsigned int 
MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]':
src/main.cpp:100:95:   required from here
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:688:11: error: no matching function for call to 'ThingsBoardSized<>::Shared_Attributes_Request(std::array<const char*, 5>::const_iterator, std::array<const char*, 5>::const_iterator, Shared_Attribute_Request_Callback)'       
       if (!Shared_Attributes_Request(fwSharedKeys.cbegin(), fwSharedKeys.cend(), Shared_Attribute_Request_Callback(std::bind(&ThingsBoardSized::Firmware_Shared_Attribute_Received, this, std::placeholders::_1)))) {
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:869:23: note: candidate: 'template<class InputIterator> const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::Shared_Attributes_Request(const InputIterator&, const InputIterator&, Shared_Attribute_Request_Callback&) [with InputIterator = InputIterator; unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]'       
     inline const bool Shared_Attributes_Request(const InputIterator& first_itr, const InputIterator& last_itr, Shared_Attribute_Request_Callback& callback) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:869:23: note:   template argument deduction/substitution failed:
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:688:11: note:   cannot convert 'Shared_Attribute_Request_Callback(std::function<void(const ArduinoJson6194_F1::ObjectConstRef&)>(std::bind(_Func&&, _BoundArgs&& ...) [with _Func = void (ThingsBoardSized<>::*)(const ArduinoJson6194_F1::ObjectConstRef&); _BoundArgs = {ThingsBoardSized<64, 8, ThingsBoardDefaultLogger>*, const std::_Placeholder<1>&}; typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type = std::_Bind<void (ThingsBoardSized<>::*(ThingsBoardSized<>*, std::_Placeholder<1>))(const ArduinoJson6194_F1::ObjectConstRef&)>](((ThingsBoardSized<>*)this), std::placeholders::_1)))' (type 'Shared_Attribute_Request_Callback') to type 'Shared_Attribute_Request_Callback&'
       if (!Shared_Attributes_Request(fwSharedKeys.cbegin(), fwSharedKeys.cend(), Shared_Attribute_Request_Callback(std::bind(&ThingsBoardSized::Firmware_Shared_Attribute_Received, this, std::placeholders::_1)))) {
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:695:27: error: no match for 'operator=' (operand types are 'const std::function<void(const bool&)>' and 'const std::function<void(const bool&)>')
       m_fwUpdatedCallback = updatedCallback;
       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\functional:59,
                 from C:/Users/andre/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:49,
                 from C:/Users/andre/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:167,
                 from src/main.cpp:1:
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:461:7: note: candidate: 'std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(const std::function<_Res(_ArgTypes ...)>&) 
[with _Res = void; _ArgTypes = {const bool&}]' <near match>
       operator=(const function& __x)
       ^~~~~~~~
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:461:7: note:   passing 'const std::function<void(const bool&)>*' as 'this' argument discards qualifiers
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:479:7: note: candidate: 'std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::function<_Res(_ArgTypes ...)>&&) [with _Res = void; _ArgTypes = {const bool&}]' <near match>
       operator=(function&& __x) noexcept
       ^~~~~~~~
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:479:7: note:   conversion of argument 1 would be ill-formed:
In file included from src/main.cpp:9:
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:695:27: error: cannot bind rvalue reference of type 'std::function<void(const bool&)>&&' to lvalue of type 'const std::function<void(const bool&)>'
       m_fwUpdatedCallback = updatedCallback;
       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\functional:59,
                 from C:/Users/andre/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:49,
                 from C:/Users/andre/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:167,
                 from src/main.cpp:1:
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:493:7: note: candidate: 'std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::nullptr_t) [with _Res = void; _ArgTypes = {const bool&}; std::nullptr_t = std::nullptr_t]'
       operator=(nullptr_t) noexcept
       ^~~~~~~~
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:493:7: note:   no known conversion for argument 1 from 'const std::function<void(const bool&)>' to 'std::nullptr_t'
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:522:2: note: candidate: 'template<class _Functor> std::function<_Res(_ArgTypes ...)>::_Requires<std::function<_Res(_ArgTypes ...)>::_Callable<typename std::decay<_U1>::type>, std::function<_Res(_ArgTypes ...)>&> std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = _Functor; _Res = void; _ArgTypes = {const bool&}]'
  operator=(_Functor&& __f)
  ^~~~~~~~
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:522:2: note:   template argument deduction/substitution failed:
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:531:2: note: candidate: 'template<class _Functor> std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::reference_wrapper<_Functor>) [with _Functor = _Functor; _Res = void; _ArgTypes = {const bool&}]'
  operator=(reference_wrapper<_Functor> __f) noexcept
  ^~~~~~~~
c:\users\andre\.platformio\packages\[email protected]+2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\std_function.h:531:2: note:   template argument deduction/substitution failed:
In file included from src/main.cpp:9:
.pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:695:27: note:   'std::function<void(const bool&)>' is not derived from 'std::reference_wrapper<_Tp>'
       m_fwUpdatedCallback = updatedCallback;
       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
Archiving .pio\build\mhetesp32devkit\lib9fc\libPubSubClient.a
Compiling .pio\build\mhetesp32devkit\libcf7\WiFi\WiFiGeneric.cpp.o
*** [.pio\build\mhetesp32devkit\src\main.cpp.o] Error 1
========================================================= [FAILED] Took 7.98 seconds =========================================================

Question re hardcoded num of RPC callbacks causing return false in RPC_Subscribe()

Hi there, thanks for all your work on this repo.

My question is some what related to issue #9. In the ThingsBoardSized class, the array of callbacks RPC_Callback m_rpcCallbacks[8] has the hardcoded size of 8.

This causes the RPC_Subscribe(const RPC_Callback *callbacks, size_t callbacks_size) function to return false if callbacks_size > 8, preventing the registration of the callbacks into m_rpcCallbacks.

I was just wondering if we could consider parameterizing the number of callbacks. Going with the current design, we could perhaps

  • Place a #define Default_NumRPCCallbacks 8 at the beginning
  • Add a template parameter in ThingsBoardSized like size_t NumRPCCallbacks
  • Set a default value of size_t NumRPCCallbacks = Default_NumRPCCallbacks in the friend class declaration inside Telemetry.
  • Additionally insert of size_t NumRPCCallbacks or just NumRPCCallbacks where needed.
  • Replace m_rpcCallbacks[8] with m_rpcCallbacks[NumRPCCallbacks].

Would parameterizing the number of callbacks in the above manner be reasonable?

Control widget error? RPC getValue method not functional using ThingsBoard Arduino SDK

Am I missing something here?

I'm using the control know widget to change a timing variable. The setValue method works allowing me to change the variable from the dashboard. Cool.

What does not work is the getValue method. This method is apparently only called when you do a browser refresh on a dashboard or come into a dashboard. Although not deal breaker, it is an obvious deficit. This method never will get into your code because it get short circuited. My workaround is using attribute card to double check against control widget values.

By inspection, using the New RPC debug terminal (v2.3), the getValue method apparently does not issue the "params" portion of the RPC call. Hence, the Thingsboard Arduino SDK library returns nothing. See ThingsBoard.cpp line 183.

The New RPC debug terminal does let me add a params value. This DOES allow my getValue code to fully execute. What I expected to happen was that the new value would update the widget value. Sadly, no.

I'm not clever enough to know how to go further, make corrections or submit options. Can anyone provide direction for me on this issue? Is it user error? ThingsBoard issue?

Below is relevant output

Arduino code:

// set value on delay control
RPC_Response processSetInterval(const RPC_Data &data){
  Serial.println("Received the setDelay method");
  Delaysec = data;
  Serial.print("SetInterval value: ");
  Serial.println(Delaysec);
  Delaymillis = Delaysec * 1000;
  return RPC_Response(NULL, Delaysec);
}

// get value of delay control
RPC_Response processGetInterval(const RPC_Data &data){
  float getval = data;
  Serial.print("Received the getInterval method");
  Serial.println(getval);
  return RPC_Response(NULL, Delaysec);  // trying to return current variable value to update widget here

**Serial Monitor output:**

{"method":"setInterval","params":"92"}    **<-------- COMPARE THIS TO SIX LINES BELOW**
15:22:19.604 -> [SDK] received RPC setInterval
15:22:19.604 -> [SDK] calling RPC setInterval
15:22:19.604 -> Received the setDelay method
15:22:19.604 -> SetInterval value: 92
15:22:19.604 -> [SDK] response 92
{"method":"getInterval"}    <----------------- COMPARE TO ABOVE
15:22:22.493 -> [SDK] received RPC getInterval
15:22:22.493 -> [SDK] response {}  **<------------------ NOTHING GETS RETURNED**


**Entire code**

#include "ThingsBoard.h"
#include <ESP8266WiFi.h>

#ifdef ESP32
#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!)
#error Select ESP8266 board.
#endif

#define ssid "xxxx"
#define WIFI_PASSWORD "xxxxxxx"
#define node_name "test8266"

#define TOKEN "RASPBERRY_PI_DEMO_TOKEN" // attribute test
#define TOKEN "xxxx" // Test8266
#define THINGSBOARD_SERVER  "192.168.1.107"

// Baud rate for debug serial
#define SERIAL_DEBUG_BAUD   115200

// Initialize ThingsBoard client
WiFiClient espClient;

long rssi;
int ipaddr;

// Initialize ThingsBoard instance
ThingsBoard tb(espClient);

// the Wifi radio's status
int status = WL_IDLE_STATUS;
long currentMillis;
bool subscribed = false;

const size_t callbacks_size = 2;
long Delaymillis = 5000;
int Delaysec = Delaymillis / 1000;

void setup() {
  Serial.begin(SERIAL_DEBUG_BAUD);
//  WiFi.hostname(node_name);
  InitWiFi();
  Serial.println("going into loop");
}  // end of setup

// set value on delay control
RPC_Response processSetInterval(const RPC_Data &data){
  Serial.println("Received the setDelay method");
  Delaysec = data;
  Serial.print("SetInterval value: ");
  Serial.println(Delaysec);
  Delaymillis = Delaysec * 1000;
  return RPC_Response(NULL, Delaysec);
}

// get value of delay control
RPC_Response processGetInterval(const RPC_Data &data){
  float getval = data;
  Serial.print("Received the getInterval method");
  Serial.println(getval);
  return RPC_Response(NULL, Delaysec);
}

RPC_Callback callbacks[] = {
  { "setInterval", processSetInterval },
  { "getInterval", processGetInterval },
};

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    reconnect();
  }

  if (!tb.connected()) {
    subscribed = false;
    Serial.print("Connecting to: ");
    Serial.print(THINGSBOARD_SERVER);
    Serial.print(" with token ");
    Serial.println(TOKEN);
    if (!tb.connect(THINGSBOARD_SERVER, TOKEN)) {
      Serial.println("Failed to connect. retrying...");
      return;
    }
   }

  if (!subscribed) {
    Serial.println("Subscribing to RPC...");
    if (!tb.RPC_Subscribe(callbacks, callbacks_size)) {
      Serial.println("Failed to subscribe to RPC");
      return;
    }
    Serial.println("Subscribing done");
    subscribed = true;
  }
    
  if (millis() - currentMillis >= Delaymillis) {
    Serial.println("loop");
    delay(200);
    currentMillis = millis();
  }

   tb.loop();
   
} // end of loop

void InitWiFi()
{
  WiFi.mode(WIFI_STA);
  // attempt to connect to WiFi network
  WiFi.begin(ssid, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
}

void reconnect() {
  // Loop until we're reconnected
  status = WiFi.status();
  if ( status != WL_CONNECTED) {
    WiFi.begin(ssid, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
  }
}

EDITED by @forGGe : formatted a code

Is there a way to send timestamp along with telemetry data?

I need to send telemetry with timestamp for data that has been stored, from the API I get this format " {"ts":1451649600512, "values":{"key1":"value1", "key2":"value2"}} " but I coudn't implement it in firmware.
I'm using an ESP32-WROOM-32UE
I would appreciate any help, thanks!

Request: set PubSub MQTT buffersize automatically

v2.8 of the PubSubClient.h library (Olleary) now allows the MQTT_MAX_PACKET_SIZE value to be changed with the setBufferSize() command.

Can the authors please update the ThingsBoard-Arduino-MQTT-SDK library to use the JSON buffer size specified in
ThingsBoardSized<buffer,fields> class to automatically execute the PubSubClient.h setBufferSize() command?

See my suggested one line solution in my comment to this post.

Thank you.

GetAttributes

The API allows sending attributes, but not reading them. How can I use at least part of the API to read the attributes?

RPC errors on ESP32

I have downloaded the lastes version and checked that the return true; statements are there however i still seem to be getting the following error.

ThingsBoard.h:336:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
return false;

I did see someone saying there was a version 0.5 of the library that had the fix however dont seem to be able to find it.
Arduino IDE even after manually downloading and installing the lates lib is reporting
Using library ThingsBoard at version 0.4 in folder: Using library ThingsBoard at version 0.4 in folder:

FOTA updating

I am trying to update the firmware using a GSM modem SIM7600G to esp32. But the connection is not always cut off.
How to fix it?

[25233] Subscribe to OTA
[25509] Check update
[TB] Callback on_message from topic: v1/devices/me/attributes/response/1
[TB] Received shared attribute update request
[TB] =================================
[TB] A new Firmware is available :
[TB] 0.0.0 => 1.0.0
[TB] Try to download it...
[TB] Callback on_message from topic: v2/fw/response/0/chunk/0
[TB] Receive chunk 0, size 4096 bytes
[TB] Callback on_message from topic: v2/fw/response/0/chunk/1
[TB] Receive chunk 1, size 4096 bytes
[67309] ### Unhandled: +CIPCLOSE: 0,0
[TB] Unable to download firmware

Compile Issue with

I am trying to send data to thingsboard.cloud.

I've included "ThingsBoard.h" in my .cpp file

I am successfully connected via the THINGSBOARD_SERVER and TOKEN

When I execute the following as a test
tb.sendTelemetryInt("temperature", 22);

I get the following compile errors:

sketch\test.cpp.o:(.literal._ZN9test4initEv+0x4c): undefined reference to Telemetry::serializeKeyval(ArduinoJson6185_D1::VariantRef&) const' sketch\test.cpp.o: In function bool ThingsBoardSized<64u, 8u, ThingsBoardDefaultLogger>::sendKeyval(char const*, int, bool)':
E:\test.cpp:635: undefined reference to `Telemetry::serializeKeyval(ArduinoJson6185_D1::VariantRef&) const'

Can you please tell me what is wrong..

I eventually want to send a JSON string

Thanks

Also I have tried this:

const int data_items = 2;
Telemetry data[data_items] = {
{ "temperature", 42.2 },
{ "humidity", 80 },
};

tb.sendTelemetry(data, data_items);

and get compile issues:
undefined reference to Telemetry::serializeKeyval(ArduinoJson6185_D1::VariantRef&) const' In function ThingsBoardSized<64u, 8u, ThingsBoardDefaultLogger>::sendDataArray(Telemetry const*, unsigned int, bool)':
undefined reference to Telemetry::serializeKeyval(ArduinoJson6185_D1::VariantRef&) const' undefined reference to Telemetry::serializeKeyval(ArduinoJson6185_D1::VariantRef&) const'

Increasing ThingsBoardSized does not increase PubSubClient BufferSize

Problem

Currently if I change the payload size via. the ThingsBoardSized Class.

// Increase the size to max. 16 fields with a total max. character amount of 430 - 5 - 2  - 23 = 400,
// meaning max. 400 / 16 = 25 characters per field.
ThingsBoardSized<430U, 16U, ThingsBoardDefaultLogger> things_board_client(wifi_client);

The PubSubClient.bufferSize does not get adjusted accordingly but stays at the default value of 256. This results in the payload being to long even if it was increased with the ThingsBoardSized Class previously.

image
image

If there is already a way to set the PubSubClient.bufferSize outside of changing the ThingsBoard Class. I would be glad to adjust my own code, but sadly I could currently not find a way to increase it. Therefore I am proposing 3 possible solutions of increasing the PubSubClient.bufferSize in the ThingsBoard Class.

Possible Solutions

It would be highly appreciated if it were either possible that the ThingsBoardSized constructor methods sets the BufferSize to the given value in PayloadSize.

Example Implementation

// ThingsBoardSized client class
template<size_t PayloadSize = Default_Payload,
         size_t MaxFieldsAmt = Default_Fields_Amt,
         typename Logger = ThingsBoardDefaultLogger>
class ThingsBoardSized
{

    bool provision_mode = false;

  public:
    // Initializes ThingsBoardSized class with network client.
#if defined(ESP8266) || defined(ESP32)
    inline ThingsBoardSized(Client &client)
      : m_client(client)
      , m_requestId(0)
      , m_fwVersion("")
      , m_fwTitle("")
      , m_fwChecksum("")
      , m_fwChecksumAlgorithm("")
      , m_fwState("")
      , m_fwSize(0)
      , m_fwChunkReceive(-1)
    {
      m_client.setBufferSize(PayloadSize); // Addition for setting the bufferSize.
    }
#else
    inline ThingsBoardSized(Client &client)
      : m_client(client)
      , m_requestId(0)
    {
      m_client.setBufferSize(PayloadSize); // Addition for setting the bufferSize.
    }
#endif

or alternatively a method to increase the BufferSize could be added.

Example Implementation

inline bool increaseBufferSize(uint16_t buffer_size) {
    return m_client.setBufferSize(buffer_size);
}

or the m_client instance could be put into the public section of the ThingsBoard Class to be then accessed by the user itself. I doubt this would be a clean way to solve the issue tough as the two other solutions don't require much effort either.

Compile error

ThingsBoard.h:22:49: fatal error: ArduinoJson/Polyfills/type_traits.hpp: No such file or directory

unable to get MQTT Telemetry Data in Thingsboard with and Wemos D1 Mini (ESP8266)

The following is my code to read a Soil Sensor value from Analog pin and send it to the locally hosted Thingsboard on a Raspberry Pi using MQTT

Somehow the code compiles and runs successfully in the Visual Studio Code Terminal but I am unable to receive data in the Thingsboard portal.

Am I going wrong anywhere??

**CODE START


#include <Arduino.h>
#include "ESP8266WiFi.h" // Enables the ESP8266 to connect to the local network (via WiFi)
#include "PubSubClient.h" // Allows us to connect to, and publish to the MQTT broker

#define SensorPin A0 

// WiFi
const char* ssid = "Hoola";
const char* wifi_password = "password";

// MQTT
// Make sure to update this for your own MQTT Broker!
const char* mqtt_server = "10.10.1.110";
const char* plant_topic = "v1/devices/me/telemetry";
//const char* plant_topic = "plant";
const char* mqtt_username = "soil1";
const char* mqtt_password = "soil1";
// The client id identifies the ESP8266 device. Think of it a bit like a hostname (Or just a name, like Greg).
const char* clientID = "phatak";


// Initialise the WiFi and MQTT Client objects
WiFiClient wifiClient;
PubSubClient client(mqtt_server, 1883, wifiClient); // 1883 is the listener port for the Broker


void connect_MQTT(){
  Serial.print("Connecting to ");
  Serial.println(ssid);

  // Connect to the WiFi
  WiFi.begin(ssid, wifi_password);

  // Wait until the connection has been confirmed before continuing
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  // Debugging - Output the IP Address of the ESP8266
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Connect to MQTT Broker
  // client.connect returns a boolean value to let us know if the connection was successful.
  // If the connection is failing, make sure you are using the correct MQTT Username and Password (Setup Earlier in the Instructable)
  if (client.connect(clientID, mqtt_username, mqtt_password)) {
    Serial.println("Connected to MQTT Broker!");
  }
  else {
    Serial.println("Connection to MQTT Broker failed...");
  }
}


void setup() { 
  Serial.begin(9600);
  connect_MQTT();
  Serial.setTimeout(2000);

  float sensorValue = analogRead(SensorPin);
  Serial.println(sensorValue);

  // PUBLISH to the MQTT Broker
  if (client.publish(plant_topic, String(sensorValue).c_str())) {
    Serial.println("Moisture sent!");
    Serial.println(plant_topic);
  }
  // Again, client.publish will return a boolean value depending on whether it succeded or not.
  // If the message failed to send, we will try again, as the connection may have broken.
  else {
    Serial.println("Moisture failed to send. Reconnecting to MQTT Broker and trying again");
    client.connect(clientID, mqtt_username, mqtt_password);
    delay(10); // This delay ensures that client.publish doesn't clash with the client.connect call
    client.publish(plant_topic, String(sensorValue).c_str());
  }
  
  delay(1000);
  //ESP.deepSleep(30e6);
  ESP.deepSleep(0.2*60e6);
}

void loop() {
} 

**CODE END

The output in the VS Code terminal window is shown below...

--- Available ports:
---  1: COM3                 'Sierra Wireless EM7355 - Gobi(TM) 5000 HS-USB Diagnostics 901F (COM3)'
---  2: COM4                 'Sierra Wireless EM7355 - Gobi(TM) 5000 HS-USB NMEA 901F (COM4)'
---  3: COM5                 'Sierra Wireless EM7355 - Gobi(TM) 5000 HS-USB Modem 901F'
---  4: COM11                'USB-SERIAL CH340 (COM11)'
--- Enter port index or full name: 4
--- Miniterm on COM11  9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
�En��b$���ld␆␘Yִp�h�Connecting to Hoola
...........WiFi connected
IP address: 10.10.1.107
Connected to MQTT Broker!
758.00
Moisture sent!
v1/devices/me/telemetry

how to make the rpc call example to work with nodemcu

Hello guys. i have a nodemcu that i want to connect to the thingsboard cloud and use the switch widget. when i try to upload the 0002-arduino_rpc.ino sketch on the a Arduino it compiles correctly but when i try to change the board to nodemcu it gives me this error
In file included from C:\Users\hoovd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Arduino.h:29:0, from sketch\switch_with_new_library.ino.cpp:1: C:\Users\hoovd\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h: In instantiation of 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_message(char*, uint8_t*, unsigned int) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; uint8_t = unsigned char]': C:\Users\hoovd\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:387:5: required from 'static void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::on_message(char*, uint8_t*, unsigned int) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; uint8_t = unsigned char]' C:\Users\hoovd\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:247:5: required from 'bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::RPC_Subscribe(const RPC_Callback*, size_t) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; size_t = unsigned int]' C:\Users\hoovd\Documents\Arduino\ThingsBoard\switch_with_new_library\switch_with_new_library.ino:145:52: required from here C:\Users\hoovd\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:329:16: error: return-statement with a value, in function returning 'void' [-fpermissive] return false; ^ C:\Users\hoovd\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:334:16: error: return-statement with a value, in function returning 'void' [-fpermissive] return false; ^ exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Could someone tell me how to edit my code to work with my nodemcu?

mkr wifi 1010

This is more of a request, I've been trying very hard to learn about IoT and im using the arduino mkr wifi 1010 and I would like to have some example sketches to work with. I'm not sure how else to post this sorry if this is invalid.

Shared_Attributes_Request method unable to use.

I have updated my arduino sdk to the latest version 0.7 and having some issues getting the existing code to build using the Shared_Attributes_Request method.

Is there an example of how to use the method?

Currently I am doing:

void processSystemTimebaseAttributeUpdate(const Shared_Attribute_Data &data) {
    for (JsonObjectConst::iterator it = data.begin(); it != data.end(); ++it) {
        santrack_dln(it->key().c_str());
        santrack_dln(it->value().as<const char*>()); // We have to parse data by it's type in the current example we will show here only char data
        if (strcmp("system_on_timebase", it->key().c_str()) == 0) {
            SetpOnSampleTime(it->value().as<const char*>());
        }
        if (strcmp("system_off_timebase", it->key().c_str()) == 0) {
            SetpOffSampleTime(it->value().as<const char*>());
        }
        if (strcmp("system_measurement_time", it->key().c_str()) == 0) {
            SetpMeasureTime(it->value().as<const char*>());
        }
        if (strcmp("system_reporting_cycle", it->key().c_str()) == 0) {
            SetpReportCycle(it->value().as<const char*>());
        }
    }

    saveParameters();
}
const std::array<const char*, 4U> systemTimebaseKeys {"system_on_timebase","system_off_timebase","system_measurement_time","system_reporting_cycle"};

currTB->Shared_Attributes_Request(systemTimebaseKeys .cbegin(), systemTimebaseKeys .cend(), Shared_Attribute_Request_Callback(&processSystemTimebaseAttributeUpdate));

Compiler error reported:
cannot convert 'Shared_Attribute_Request_Callback(std::function<void(const ArduinoJson6192_F1::ObjectConstRef&)>(processSharedAttributeUpdate))' (type 'Shared_Attribute_Request_Callback') to type 'Shared_Attribute_Request_Callback&'

How to make Shared_Attribute_Request_Callback be correct ?

Thank you
Marc

Arduino IDE Not compiling

Hi all!
Recently decided to change from the Arduino library inbuilt and directly download from GitHub as I want to take advantage of the logger as having some issues. But compiling my code just gives tons of errors. Tried compiling for Seeduinio XAIO, Teensy & Generica ESP module. Also loaded example code and no luck there either. Any help would be greatly appreciated!
Thingsboard 0.6.0 compiles perfectly and runs. Github SDK doesn't.

ArduinoJSON - 6.19.4
MQTT PubSub Client - 0.1.3
Arduino HTTP Client - 0.4.0

In file included from /var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:8:0:
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:269:28: error: 'function' in namespace 'std' does not name a template type
using processFn = std::function<RPC_Response(const RPC_Data &data)>;
^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:277:49: error: 'processFn' has not been declared
inline RPC_Callback(const char* methodName, processFn cb)
^~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:282:5: error: 'processFn' does not name a type
processFn m_cb; // Callback to call
^~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In constructor 'RPC_Callback::RPC_Callback()':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:273:19: error: class 'RPC_Callback' does not have any field named 'm_cb'
: m_name(), m_cb(nullptr) { }
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In constructor 'RPC_Callback::RPC_Callback(const char*, int)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:278:29: error: class 'RPC_Callback' does not have any field named 'm_cb'
: m_name(methodName), m_cb(cb) { }
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: At global scope:
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:292:34: error: ISO C++ forbids declaration of 'type name' with no type [-fpermissive]
using processFn = const std::function<void(const Shared_Attribute_Data &data)>;
^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:292:29: error: expected ';'
using processFn = const std::function<void(const Shared_Attribute_Data &data)>;
^~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:301:101: error: 'processFn' has not been declared
inline Shared_Attribute_Callback(const InputIterator& first_itr, const InputIterator& last_itr, processFn cb)
^~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:306:48: error: expected ')' before 'cb'
inline Shared_Attribute_Callback(processFn cb)
^~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:311:5: error: 'processFn' does not name a type
processFn m_cb; // Callback to call
^~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In constructor 'Shared_Attribute_Callback::Shared_Attribute_Callback()':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:296:18: error: class 'Shared_Attribute_Callback' does not have any field named 'm_cb'
: m_att(), m_cb(nullptr) { }
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In constructor 'Shared_Attribute_Callback::Shared_Attribute_Callback(const InputIterator&, const InputIterator&, int)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:302:37: error: class 'Shared_Attribute_Callback' does not have any field named 'm_cb'
: m_att(first_itr, last_itr), m_cb(cb) { }
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: At global scope:
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:321:28: error: 'function' in namespace 'std' does not name a template type
using processFn = std::function<void(const Shared_Attribute_Data &data)>;
^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:328:56: error: expected ')' before 'cb'
inline Shared_Attribute_Request_Callback(processFn cb)
^~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:333:5: error: 'processFn' does not name a type
processFn m_cb; // Callback to call
^~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In constructor 'Shared_Attribute_Request_Callback::Shared_Attribute_Request_Callback()':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:325:27: error: class 'Shared_Attribute_Request_Callback' does not have any field named 'm_cb'
: m_request_id(0U), m_cb(nullptr) { }
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In member function 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::setClient(arduino::Client&)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:410:33: error: 'bind' is not a member of 'std'
m_client.setCallback(std::bind(&ThingsBoardSized::on_message, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:410:33: note: suggested alternative: 'find'
m_client.setCallback(std::bind(&ThingsBoardSized::on_message, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
^~~~
find
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:410:80: error: 'std::placeholders' has not been declared
m_client.setCallback(std::bind(&ThingsBoardSized::on_message, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
^~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:410:103: error: 'std::placeholders' has not been declared
m_client.setCallback(std::bind(&ThingsBoardSized::on_message, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
^~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:410:126: error: 'std::placeholders' has not been declared
m_client.setCallback(std::bind(&ThingsBoardSized::on_message, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
^~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In member function 'const uint8_t ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::detect_size(const char*, ...)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:979:7: error: there are no arguments to 'va_start' that depend on a template parameter, so a declaration of 'va_start' must be available [-fpermissive]
va_start(args, msg);
^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:979:7: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
In file included from /Users/andy_shepshep/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:7:0,
from /Users/andy_shepshep/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/SlotFunctions.hpp:8,
from /Users/andy_shepshep/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp:7,
from /Users/andy_shepshep/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp:8,
from /Users/andy_shepshep/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.hpp:24,
from /Users/andy_shepshep/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:9,
from /Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:21,
from /var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:8:
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:983:47: error: there are no arguments to 'vsnprintf_P' that depend on a template parameter, so a declaration of 'vsnprintf_P' must be available [-fpermissive]
const int32_t result = JSON_STRING_SIZE(vsnprintf_P(nullptr, 0U, msg, args));
^
In file included from /var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:8:0:
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:984:7: error: there are no arguments to 'assert' that depend on a template parameter, so a declaration of 'assert' must be available [-fpermissive]
assert(result >= 0);
^~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:985:7: error: there are no arguments to 'va_end' that depend on a template parameter, so a declaration of 'va_end' must be available [-fpermissive]
va_end(args);
^~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In member function 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_rpc_message(char*, uint8_t*, uint32_t)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1058:24: error: 'const class RPC_Callback' has no member named 'm_cb'
if (callback.m_cb == nullptr || callback.m_name == nullptr) {
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1086:26: error: 'const class RPC_Callback' has no member named 'm_cb'
r = callback.m_cb(param);
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1092:26: error: 'const class RPC_Callback' has no member named 'm_cb'
r = callback.m_cb(param);
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In member function 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_shared_attribute_update_message(char*, uint8_t*, uint32_t)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1218:52: error: '__gnu_cxx::__alloc_traits<std::allocator<Shared_Attribute_Callback> >::value_type {aka class Shared_Attribute_Callback}' has no member named 'm_cb'
if (m_sharedAttributeUpdateCallbacks.at(i).m_cb == nullptr) {
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1225:50: error: '__gnu_cxx::__alloc_traits<std::allocator<Shared_Attribute_Callback> >::value_type {aka class Shared_Attribute_Callback}' has no member named 'm_cb'
m_sharedAttributeUpdateCallbacks.at(i).m_cb(data);
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1260:48: error: '__gnu_cxx::__alloc_traits<std::allocator<Shared_Attribute_Callback> >::value_type {aka class Shared_Attribute_Callback}' has no member named 'm_cb'
m_sharedAttributeUpdateCallbacks.at(i).m_cb(data);
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In member function 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_shared_attribute_request_message(char*, uint8_t*, uint32_t)':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1292:53: error: '__gnu_cxx::__alloc_traits<std::allocator<Shared_Attribute_Request_Callback> >::value_type {aka class Shared_Attribute_Request_Callback}' has no member named 'm_cb'
if (m_sharedAttributeRequestCallbacks.at(i).m_cb == nullptr) {
^~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1305:49: error: '__gnu_cxx::__alloc_traits<std::allocator<Shared_Attribute_Request_Callback> >::value_type {aka class Shared_Attribute_Request_Callback}' has no member named 'm_cb'
m_sharedAttributeRequestCallbacks.at(i).m_cb(data);
^~~~
^~~~~~~~~
/var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:20:16: note: suggested alternative: 'HttpClient'
ThingsBoard tb(espClient);
^~~~~~~~~
HttpClient
In file included from /var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:8:0:
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In instantiation of 'const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendKeyval(const char*, T, bool) [with T = int; unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:505:24: required from 'const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendTelemetryInt(const char*, int) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]'
/var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:44:40: required from here
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1032:43: error: call of overloaded 'sendTelemetryJson(ArduinoJson::JsonVariant&)' is ambiguous
return telemetry ? sendTelemetryJson(object) : sendAttributeJSON(object);
~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:529:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendTelemetryJson(const char*) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]
inline const bool sendTelemetryJson(const char json) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:545:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendTelemetryJson(const JsonObject&) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger; ArduinoJson::JsonObject = ArduinoJson6194_F1::ObjectRef]
inline const bool sendTelemetryJson(const JsonObject& jsonObject) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1032:71: error: call of overloaded 'sendAttributeJSON(ArduinoJson::JsonVariant&)' is ambiguous
return telemetry ? sendTelemetryJson(object) : sendAttributeJSON(object);
~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:594:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendAttributeJSON(const char
) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]
inline const bool sendAttributeJSON(const char json) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:610:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendAttributeJSON(const JsonObject&) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger; ArduinoJson::JsonObject = ArduinoJson6194_F1::ObjectRef]
inline const bool sendAttributeJSON(const JsonObject& jsonObject) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h: In instantiation of 'const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendKeyval(const char
, T, bool) [with T = float; unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]':
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:515:24: required from 'const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendTelemetryFloat(const char*, float) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]'
/var/folders/3h/k85zg0y13zn0fh1mp3fnpwvc0000gp/T/arduino_modified_sketch_35148/0000-arduino_send_telemetry.ino:45:41: required from here
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1032:43: error: call of overloaded 'sendTelemetryJson(ArduinoJson::JsonVariant&)' is ambiguous
return telemetry ? sendTelemetryJson(object) : sendAttributeJSON(object);
~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:529:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendTelemetryJson(const char*) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]
inline const bool sendTelemetryJson(const char json) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:545:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendTelemetryJson(const JsonObject&) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger; ArduinoJson::JsonObject = ArduinoJson6194_F1::ObjectRef]
inline const bool sendTelemetryJson(const JsonObject& jsonObject) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:1032:71: error: call of overloaded 'sendAttributeJSON(ArduinoJson::JsonVariant&)' is ambiguous
return telemetry ? sendTelemetryJson(object) : sendAttributeJSON(object);
~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:594:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendAttributeJSON(const char
) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]
inline const bool sendAttributeJSON(const char *json) {
^~~~~~~~~~~~~~~~~
/Users/andy_shepshep/Documents/Arduino/libraries/thingsboard-arduino-sdk-master/src/ThingsBoard.h:610:23: note: candidate: const bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::sendAttributeJSON(const JsonObject&) [with unsigned int PayloadSize = 64; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger; ArduinoJson::JsonObject = ArduinoJson6194_F1::ObjectRef]
inline const bool sendAttributeJSON(const JsonObject& jsonObject) {
^~~~~~~~~~~~~~~~~

SSL MQTT

Hey folks thanks for such an awesome library. I set it up in a recent project and it worked great.

Now I’m worried about security. I see MQTT sends credentials and other messages in plaintext by default.

The thingsboard platform supports MQTT SSL though. Is there a way to force this library to use MQTT over SSL? That’d be huge :)

'ThingsBoard' does not name a type; did you mean 'ThingsBoard_h'?

I was using the thingsboard library perfectly fine but then all of a sudden I started getting this error.
I tried all solutions including moving the .h and .cpp fies up a folder but issue is not resolved.
I tried to use an example code for thingsboard but still the error remains.

Below is the complete error:

In file included from C:\Users\username\AppData\Local\Temp\arduino_modified_sketch_445642\0003-esp8266_send_data.ino:1:
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:28:16: error: default template arguments may not be used in template friend declarations
   28 |   friend class ThingsBoardSized;
      |                ^~~~~~~~~~~~~~~~
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h: In member function 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_message(char*, uint8_t*, unsigned int)':
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:329:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
  329 |         return false;
      |                ^~~~~
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:334:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
  334 |         return false;
      |                ^~~~~
In file included from C:\Users\username\AppData\Local\Temp\arduino_modified_sketch_445642\0003-esp8266_send_data.ino:1:
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h: At global scope:
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:582:38: error: wrong number of template arguments (0, should be 3)
  582 | using ThingsBoard = ThingsBoardSized<>;
      |                                      ^
In file included from C:\Users\username\AppData\Local\Temp\arduino_modified_sketch_445642\0003-esp8266_send_data.ino:1:
C:\Users\username\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:28:16: note: provided for 'template<unsigned int PayloadSize, unsigned int MaxFieldsAmt, class Logger> class ThingsBoardSized'
   28 |   friend class ThingsBoardSized;
      |                ^~~~~~~~~~~~~~~~
0003-esp8266_send_data:20:1: error: 'ThingsBoard' does not name a type; did you mean 'ThingsBoard_h'?
   20 | ThingsBoard tb(espClient);
      | ^~~~~~~~~~~
      | ThingsBoard_h
C:\Users\username\AppData\Local\Temp\arduino_modified_sketch_445642\0003-esp8266_send_data.ino: In function 'void loop()':
0003-esp8266_send_data:38:8: error: 'tb' was not declared in this scope; did you mean 'tm'?
   38 |   if (!tb.connected()) {
      |        ^~
      |        tm
0003-esp8266_send_data:56:3: error: 'tb' was not declared in this scope; did you mean 'tm'?
   56 |   tb.sendTelemetryInt("temperature", 22);
      |   ^~
      |   tm
exit status 1
'ThingsBoard' does not name a type; did you mean 'ThingsBoard_h'?

RPC client-server

Hi,
Is it implemented the function to send rpc from client to server?
There are sendTelemetry and sendAttribute and not sendRPC?

Any how on subscribing RPC Callback and Shared Attributes Update Simultaneously?

Hi, i'm facing a big issue. If i use more than one callback (for shared attributes update, RPC call, and OTA Update), only one and the first one is working, the rest is failed.

const size_t RPCCallbacksSize = 2;
RPC_Callback RPCCallbacks[RPCCallbacksSize] = {
  { "saveConfig", processSaveConfig },
  { "saveSettings", processSaveSettings }
};

const size_t SharedAttributesCallbacksSize = 1;
Shared_Attribute_Callback SharedAttributesCallbacks[SharedAttributesCallbacksSize] = {
  processSharedAttributesUpdate
};

and on the loop

if(tb.connected())
  {
    if (tb.Firmware_OTA_Subscribe() && FLAG_IOT_OTA_UPDATE_SUBSCRIBE)
    {
      if (tb.Firmware_Update(CURRENT_FIRMWARE_TITLE, CURRENT_FIRMWARE_VERSION))
      {
        sprintf_P(logBuff, PSTR("Firmware update complete. Rebooting now..."));
        recordLog(4, PSTR(__FILE__), __LINE__, PSTR(__func__));
      }
      else
      {
        sprintf_P(logBuff, PSTR("Firmware is up to date."));
        recordLog(4, PSTR(__FILE__), __LINE__, PSTR(__func__));
        tb.Firmware_OTA_Unsubscribe();
      }
      FLAG_IOT_OTA_UPDATE_SUBSCRIBE = false;
    }

    if (FLAG_IOT_SHARED_ATTRIBUTES_SUBSCRIBE)
    {
      if(tb.Shared_Attributes_Subscribe(SharedAttributesCallbacks, SharedAttributesCallbacksSize))
      {
        sprintf_P(logBuff, PSTR("Shared attributes update callbacks subscribed successfuly!"));
        recordLog(4, PSTR(__FILE__), __LINE__, PSTR(__func__));
        FLAG_IOT_SHARED_ATTRIBUTES_SUBSCRIBE = false;
      }
    }

    if (FLAG_IOT_RPC_SUBSCRIBE)
    {
      if(tb.RPC_Subscribe(RPCCallbacks, RPCCallbacksSize))
      {
        sprintf_P(logBuff, PSTR("RPC callbacks subscribed successfuly!"));
        recordLog(4, PSTR(__FILE__), __LINE__, PSTR(__func__));
        FLAG_IOT_RPC_SUBSCRIBE = false;
      }
    }

  }

Any how to resolve this issue? As in the example folder, in the real case, we also need to subscribe an attribute change while also listening for RPC call and OTA update. Now i'm stuck and don't want to refactor all the code. Any help is much appreciated!

Arduino MKR GSM 1400

Hi folks,

I have an Arduino MKR GSM 1400 that
I would like to use. unfortunately the ThingsBoard library does not work with this board.
I would be happy if it is updated to be able to run ThingsBoard with demanding boards.

I would also like to thank you for the great community and thank you to the ThinsBoard team for the great IoT cloud.
Greetings from Germany
Markus

RPC getValue problem.

I've same problem here

Where to modify this code?
{"method":"getInterval", "params": {} }

In the widget settings or arduino' code?

My RPC method:

RPC_Response setValve(const RPC_Data &data)
{
  //Serial.println("Received the set switch method");
  valve_override = data;
  return RPC_Response(NULL, valve_override);
}
RPC_Response getValve(const RPC_Data &data)
{
  //Serial.println("Received the get switch method");
    return RPC_Response(NULL, sensor.valve_override);
}

Thank you.

Device provisioning

I'm just starting to dig into this now, but I'd like to see device provisioning added into this library as well. Looking at potentially deploying this as part of the code for several hundred units, and I really don't want to have to manually provision and hand program every unit....

using tb.sendAttribute within RPC callback brakes response

A strange behaviour: When I add a tb.sendAttribute to a RPC callback function, to let's say publish some client attributes before returning the RPC, the PRC response gets lost. I'm still investigation and not sure where.

Here a minimal example:
0002-arduino-esp32-rpc3.zip

Any clues?

Edit 1: Updated minimal example. tb.sendAttributeBool("example_temperature", example_temperature); must be tb.sendAttributeFloat("example_temperature", example_temperature);

not compatible with esp32 v2 core

ThingsBoard.h:34:18: error: default template arguments may not be used in template friend declarations
friend class ThingsBoardSized;
ThingsBoard.h:39:18: error: default template arguments may not be used in template friend declarations
friend class ThingsBoardHttpSized;
ThingsBoard.h:1180:38: error: wrong number of template arguments (0, should be 3)
using ThingsBoard = ThingsBoardSized<>;
ThingsBoard.h:34:18: note: provided for 'template<unsigned int PayloadSize, unsigned int MaxFieldsAmt, class Logger> class ThingsBoardSized'
friend class ThingsBoardSized;

ThingsBoard-Arduino-MQTT-SDK not compatible with esp8266 board library v3.0.0 (Arduino IDE)

I found upgrading to the v3.0.0 esp8266 board library in Arduino IDE broke the latest version of ThingsBoard-Arduino-MQQTT-SDK v0.4.0

There are numerous errors related to

ThingsBoardSized
Telemetry [ tb.sendAttributes() ]
tb.loop()
tb.connected()
tb.RPC_Subscribe()

I'm not a good enough coder to understand what has changed to cause these problems. I do, however, use this Thingsboard library extensively and would appreciate any help to update it to be compatible with the latest stable release of the esp8266 board library in the Arduino IDE. Thank you.

Below is output from the Arduino IDE after attempting to compile and flash a program using ThingsBoard-Arduino-MQTT-SDK on an ESP8266.

In file included from G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino:59:
C:\Users\ferguson\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:30:16: error: default template arguments may not be used in template friend declarations
30 | friend class ThingsBoardSized;
| ^~~~~~~~~~~~~~~~
In file included from G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino:59:
C:\Users\ferguson\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:595:38: error: wrong number of template arguments (0, should be 4)
595 | using ThingsBoard = ThingsBoardSized<>;
| ^
In file included from G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino:59:
C:\Users\ferguson\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:30:16: note: provided for 'template<unsigned int PayloadSize, unsigned int MaxFieldsAmt, class Logger, unsigned int NumRPCCallbacks> class ThingsBoardSized'
30 | friend class ThingsBoardSized;
| ^~~~~~~~~~~~~~~~
thingsboard-park-assist-subaru-ferguson-v12:143:24: error: wrong number of template arguments (2, should be 4)
143 | ThingsBoardSized<600,26> tb(espClient); // Initialize ThingsBoard instance
| ^
In file included from G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino:59:
C:\Users\ferguson\Documents\Arduino\libraries\ThingsBoard\src/ThingsBoard.h:30:16: note: provided for 'template<unsigned int PayloadSize, unsigned int MaxFieldsAmt, class Logger, unsigned int NumRPCCallbacks> class ThingsBoardSized'
30 | friend class ThingsBoardSized;
| ^~~~~~~~~~~~~~~~
G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino: In function 'void setup()':
thingsboard-park-assist-subaru-ferguson-v12:254:8: error: request for member 'sendAttributes' in 'tb', which is of non-class type 'int'
254 | tb.sendAttributes(attributesSetup, 8);
| ^~~~~~~~~~~~~~
G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino: In function 'void loop()':
thingsboard-park-assist-subaru-ferguson-v12:397:8: error: request for member 'loop' in 'tb', which is of non-class type 'int'
397 | tb.loop();
| ^~~~
G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino: In function 'void subscribeThingsboard()':
thingsboard-park-assist-subaru-ferguson-v12:954:11: error: request for member 'connected' in 'tb', which is of non-class type 'int'
954 | if (!tb.connected()) {
| ^~~~~~~~~
thingsboard-park-assist-subaru-ferguson-v12:960:16: error: request for member 'connect' in 'tb', which is of non-class type 'int'
960 | while (!tb.connect(THINGSBOARD_SERVER, TOKEN)) { // wait for TB to be available
| ^~~~~~~
G:\workdir\Microcontrollers\Production Projects\ferguson_production\thingsboard-park-assist-subaru-ferguson-v12\thingsboard-park-assist-subaru-ferguson-v12.ino: In function 'void subscribeRPC()':
thingsboard-park-assist-subaru-ferguson-v12:972:13: error: request for member 'RPC_Subscribe' in 'tb', which is of non-class type 'int'
972 | if (!tb.RPC_Subscribe(callbacks, callbacksize)) {
| ^~~~~~~~~~~~~
exit status 1
wrong number of template arguments (2, should be 4)

MQTT Gateway API

Currently ThingsBoard support such feature, that the "connected" node might be working as a gateway. As in - single instance connected but sends information to server node for all other sensors/devices.
The API is here - https://thingsboard.io/docs/reference/gateway-mqtt-api/

Can this library be updated to include MQTT Gateway API feature?

or should we just use m_client.publish() with a different endpoint? /gateway/telemetry

Thingsboard keeps disconnecting and reconnecting

Hi!

I'm using ESP32 and following examples from the Arduino Thingsboard SDK. My code usually runs fine after a while, it keeps getting disconnected from Thingsboard and attempting to connect again and again. What is the possible reasons this? Does anyone have this issue like me?

Thank you for the amazing library though! 😄

My serial.println results...

[DONE] Subscribing for RPC... Subscribe done Connecting to ThingsBoard node... [DONE] Subscribing for RPC... Subscribe done Connecting to ThingsBoard node... [DONE] Subscribing for RPC... Subscribe done Connecting to ThingsBoard node... [DONE] Subscribing for RPC... Subscribe done Connecting to ThingsBoard node... ....

ESP32/8266 - MQTT - http

Is there a reason, why I can't use the http client with an ESP?

I don't nee the additional functionality. And I'm restricted to http with our installation.

sendTelemetry & sendAttributes batch only sends last value to ThingsBoard

Hello, I'm using an ESP32 and am able to successfully use tb.sendTelemetryInt, but when I try the example code for batch sending, only the last value appears in ThingsBoard. IE, in the below section of code from the example sketch, only "humidity" shows up under Latest Telemetry in ThingsBoard, and only "active" shows up under attributes.:

const int data_items = 2;
Telemetry data[data_items] = {
{ "temperature", 42.2 },
{ "humidity", 80 },
};
const int attribute_items = 2;
Attribute attributes[attribute_items] = {
{ "device_type", "sensor" },
{ "active", true },
};
tb.sendTelemetry(data,data_items);
tb.sendAttributes(attributes, attribute_items);
tb.loop();

I'm kind of new to this and I can't figure out what the problem is. If I change data_items to 1 then only "temperature" will show up in the Latest Telemetry.

Using the ThingsBoard library 0.4.0, Arduino IDE 1.8.12.

Unable to get RPC request->response from Client

Hi

I am sending RPC request to server but unable to get RPC request->response from server. In Server logs, i can see my request forward to requesting client and response from requesting client but server was unable to return the response back to requested client.

//send RPC request to server

jsonDoc["params"] = "";
jsonDoc["method"] = "getLedStatus";

String strPayload;
serializeJson(jsonDoc, strPayload); //Store JSON in String variable
client.publish("v1/devices/me/rpc/request/1", strPayload.c_str())

// Subscribing to receive RPC requests->response
client.subscribe("v1/devices/me/rpc/response/+");

Can you please share any sample related to it.
Thanks in advance for all your cooperation.

cannot connect to thingsboard demo server

Hello!
I was connected and capable of tranfering data few days ago.Without changing anything in my code, i am unable to connect now.
The demo server and TOKEN is being given correctly, although the tb.connect(host,token) returns false.
The only thing that changed those days, is that i was transfered in a new location with a different netwotk.Is there any issues with security policies etc and if yes, how can i overcome this?

Thingsboard Server On RPI3 connection issue

Hi,

I couldn't connect my ESP32 MCU with Thingsboard server running on RPI with hostname ( RPI IP address ) & token with sample code. The same code connects with demo server (demo live server & token) fine and I could see data coming in.

Any inputs on this ?

Thanks in advance.

Fatal error: PubSubClient.h: No such file or directory

Good evening everyone, I'm trying to use Wemos D1 mini (ESP8266) to send data to Thingsboard. When I try to upload the library example on the board there is the following error:

C:\Users\edoma\Desktop\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h:20:10: fatal error: PubSubClient.h: No such file or directory
20 | #include <PubSubClient.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

I try different versions of the library and I try also to use different versions of the board but the results that I've had are the same. I've also manually deleted the folder and try again but the error doesn't allow me to upload the sketch on the board. Thank you so much for the help.

Error with RPC response for setting GPIO

Hi,

The following code is from ESP32 Example
https://thingsboard.io/docs/samples/esp32/gpio-control-pico-kit-dht22-sensor/

RPC_Response processSetGpioState(const RPC_Data &data)
{
  Serial.println("Received the set GPIO RPC method");

  int pin = data["pin"];
  bool enabled = data["enabled"];

  if (pin < COUNT_OF(leds_control)) {
    Serial.print("Setting LED ");
    Serial.print(pin);
    Serial.print(" to state ");
    Serial.println(enabled);

    digitalWrite(leds_control[pin], enabled);
  }

  return RPC_Response(data["pin"], (bool)data["enabled"]);
}

When the GPIO control widget is used on the dashboard, it send the setGpioStatus RPC call, but the response contains the value for the pin switched only. This response cannot be interpreted by the widget and the pin control on the widget stays at the default position.

How to send the proper response which includes the status of all pins using ThingsBoard library?
This can help in implementing a getGpioStatus callback as well.

The following example for ESP8266 works perfectly because the response to the RPC call contains all the pins, however, this example does not use the the ThingsBoard library.
https://thingsboard.io/docs/samples/esp8266/gpio/

Thank you.

@forGGe @ferchinas

Version number error

For version 0.7 the files library.json and library.properties contain version 0.6
Apparently that's why I'm getting version 0.7 instead of 0.6, although I specify in platform.ini that version 0.6 is needed?

Hard coded MQTT payload buffer size cause data lost

In ThingsBoard.cpp, there are many hard coded mqtt payload buffer size, such as
line 76: char payload[64];
etc...
In ThingsBoard.h
line 224:char payload[64];
etc...
Which causes data lost when payload size exceed the size.
Should we define some CONST and got the opportunity to send more data?

sendTelemetry and tb.loop and workflow

I have a function that sends the telelberty data such as
tb.sendTelemetryFloat("obj_t",obj_t);
tb.sendTelemetryFloat("tmp_t",tmp_t);
...... etc.

after this I call
tb.loop();
then have to create a delay to ensure the data is sent before putting the device back to sleep.

Is there a way to send the data directly without having to use tb.loop() and preferably with the return of something to let you know the data has been sent?

Running example code for ESP32 with RPC creates build error

/Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h: In instantiation of 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_message(char*, uint8_t*, unsigned int) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; uint8_t = unsigned char]': /Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h:387:5: required from 'static void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::on_message(char*, uint8_t*, unsigned int) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; uint8_t = unsigned char]' /Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h:247:5: required from 'bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::RPC_Subscribe(const RPC_Callback*, size_t) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; size_t = unsigned int]' /Users/rami/Documents/Arduino/portalneli/portalneli.ino:176:57: required from here /Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h:329:16: error: return-statement with a value, in function returning 'void' [-fpermissive] return false;

When I took the all the code related to RPC and only kept the sending part. Then the code compiled and worked. So it is related somehow to RPC code.

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.