![]() |
ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
|
Wrapper around the ArduinoHttpClient to allow connecting and sending / retrieving data from ThingsBoard over the HTTP or HTTPS protocol. More...
#include <ThingsBoardHttp.h>
Public Member Functions | |
| ThingsBoardHttpSized (IHTTP_Client &client, char const *access_token, char const *host, uint16_t port=80U, bool keep_alive=true, size_t const &max_stack_size=DEFAULT_MAX_STACK_SIZE) | |
| Constructs a instance with the given network client that should be used to establish the connection to ThingsBoard. More... | |
| void | Set_Maximum_Stack_Size (size_t const &max_stack_size) |
| Sets the maximum amount of bytes that we want to allocate on the stack, before the memory is allocated on the heap instead. More... | |
| size_t const & | Get_Maximum_Stack_Size () const |
| Returns the maximum amount of bytes that we want to allocate on the stack, before the memory is allocated on the heap instead. More... | |
| bool | Send_Json (char const *topic, JsonDocument const &source) |
| Sends key-value pairs from the given JsonDocument over the given topic. More... | |
| bool | Send_Json_String (char const *topic, char const *json) |
| Sends key-value pairs from the given json string over the given topic. More... | |
| template<typename T > | |
| bool | Send_Telemetry_Data (char const *key, T const &value) |
| Sends the given key-value pair as telemetry data. See https://thingsboard.io/docs/user-guide/telemetry/ for more information. More... | |
| template<size_t MaxKeyValuePairAmount, typename InputIterator > | |
| bool | Send_Telemetry (InputIterator const &first, InputIterator const &last) |
| Send aggregated key-value pair as telemetry data. More... | |
| bool | Send_Telemetry_String (char const *json) |
| Send string containing json as telemetry data. See https://thingsboard.io/docs/user-guide/telemetry/ for more information. More... | |
| bool | Send_Telemetry_Json (JsonDocument const &source) |
| Send key-value pairs as telemetry data. See https://thingsboard.io/docs/user-guide/telemetry/ for more information. More... | |
| template<typename T > | |
| bool | Send_Attribute_Data (char const *key, T const &value) |
| Sends the given key-value pair as attribute data. See https://thingsboard.io/docs/user-guide/attributes/ for more information. More... | |
| template<size_t MaxKeyValuePairAmount, typename InputIterator > | |
| bool | Send_Attributes (InputIterator const &first, InputIterator const &last) |
| Send aggregated key-value pair as attribute data. More... | |
| bool | Send_Attribute_String (char const *json) |
| Send string containing json as attribute data. See https://thingsboard.io/docs/user-guide/attribute/ for more information. More... | |
| bool | Send_Attribute_Json (JsonDocument const &source) |
| Send key-value pairs as attribute data. See https://thingsboard.io/docs/user-guide/attribute/ for more information. More... | |
| bool | Send_Get_Request (char const *path, std::string &response) |
| Attempts to send a GET request over HTTP or HTTPS. More... | |
| bool | Send_Post_Request (char const *path, char const *json) |
| Attempts to send a POST request over HTTP or HTTPS. More... | |
Wrapper around the ArduinoHttpClient to allow connecting and sending / retrieving data from ThingsBoard over the HTTP or HTTPS protocol.
| Logger | Implementation that should be used to print error messages generated by internal processes and additional debugging messages if THINGSBOARD_ENABLE_DEBUG is set, default = DefaultLogger |
|
inline |
Constructs a instance with the given network client that should be used to establish the connection to ThingsBoard.
| client | HTTP Client implementation that should be used to establish the connection to ThingsBoard |
| access_token | Non owning pointer to the access token used to verify the devices identity with the ThingsBoard server. Additionally it has to be kept alive by the user for the runtime of the HTTP or HTTPS connection |
| host | Non owning pointer to server instance name the client should connect too. Additionally it has to be kept alive by the user for the runtime of the HTTP client connection |
| port | Port that will be used to establish a connection and send / receive data. Should be either 80 for HTTP (unencrypted) or 443 for HTTPS (encrypted). The latter is recommended if relevant data is sent or if the client receives and handles Remote Procedure Calls or Shared Attribute Update Callbacks from the server, because using an unencrpyted connection, will allow 3rd parties to listen to the communication and impersonate the server sending payloads which might influence the device in unexpected ways. However if Over the Air udpates are enabled secure communication should definetly be enabled, because if that is not done a 3rd party might impersonate the server sending a malicious payload, which is then flashed onto the device instead of the real firmware. Which depeding on the payload might even be able to destroy the device or make it otherwise unusable. See https://stackoverflow.blog/2020/12/14/security-considerations-for-ota-software-updates-for-iot-gateway-devices/ for more information on the aforementioned security risk, default = 80 |
| keep_alive | Attempts to keep the establishes TCP connection alive to make sending data faster, default = true |
| max_stack_size | Maximum amount of bytes we want to allocate on the stack. Is used when sending a lot of data at once over HTTP, because to actually send the JsonDocument data it first has to be serialized into a json string payload. To achieve this the data contained in the JsonDocument is copied for the scope of the Send_Json method and is then copied into the outgoing HTTP buffer. This variable therefore decides the threshold where the JsonDocument is copied into the heap instead of a object on the stack. This is created to ensure no StackOverflow occurs because most supported boards run the actual sending code in a seperate FreeRTOS Task with limited stack space where even a stack allocation of 4 KiB might already cause a crash To circumvent this copy the alternative mentioned in the send_buffer_size argument can also be used because it skips the internal copy alltogether, because the JsonDocument is instead directly copied into the outgoing HTTP buffer, default = DEFAULT_MAX_STACK_SIZE (1024) |
|
inline |
Returns the maximum amount of bytes that we want to allocate on the stack, before the memory is allocated on the heap instead.
|
inline |
Sends the given key-value pair as attribute data. See https://thingsboard.io/docs/user-guide/attributes/ for more information.
| T | Type of the passed value |
| key | Non owning pointer to the key of the key-value pair. Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the key-value pair |
| value | Value of the key-value pair |
|
inline |
Send key-value pairs as attribute data. See https://thingsboard.io/docs/user-guide/attribute/ for more information.
| source | JsonDocument containing our json key-value pairs, is checked before usage for any possible occuring internal errors. See https://arduinojson.org/v6/api/jsondocument/ for more information |
|
inline |
Send string containing json as attribute data. See https://thingsboard.io/docs/user-guide/attribute/ for more information.
| json | Non owning pointer to the string containing our json key-value pairs Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the key-value pairs |
|
inline |
Send aggregated key-value pair as attribute data.
| InputIterator | Class that allows for forward incrementable access to data of the given data container, allows for using / passing either std::vector or std::array. See https://en.cppreference.com/w/cpp/iterator/input_iterator for more information on the requirements of the iterator |
| MaxKeyValuePairAmount | Maximum amount of key-value pairs, which will ever be sent with this method. Should simply be the biggest distance between first and last iterator this method is ever called with |
| first | Iterator pointing to the first element in the data container |
| last | Iterator pointing to the end of the data container (last element + 1) |
| MaxKeyValuePairAmount | Maximum amount of json key value pairs, which will ever be sent with this method to the cloud. Should simply be the biggest distance between first and last iterator this method is ever called with |
|
inline |
Attempts to send a GET request over HTTP or HTTPS.
| path | API path we want to get data from (example: /api/v1/$TOKEN/rpc) |
| response | String the GET response will be copied into, will not be changed if the GET request wasn't successful |
|
inline |
Sends key-value pairs from the given JsonDocument over the given topic.
| topic | Non owning pointer to topic that the message is sent over, where different HTTP topics expect a different kind of payload. Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the given payload |
| source | JsonDocument containing our json key-value pairs, is checked before usage for any possible occuring internal errors. See https://arduinojson.org/v6/api/jsondocument/ for more information |
|
inline |
Sends key-value pairs from the given json string over the given topic.
| topic | Non owning pointer to topic that the message is sent over, where different HTTP topics expect a different kind of payload. Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the given payload |
| json | Non owning pointer to the string containing serialized json key-value pairs that should be copied into the outgoing HTTP buffer. Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the given payload |
|
inline |
Attempts to send a POST request over HTTP or HTTPS.
| path | API path we want to send data to (example: /api/v1/$TOKEN/attributes) |
| json | String containing our json key value pairs we want to attempt to send |
|
inline |
Send aggregated key-value pair as telemetry data.
| InputIterator | Class that allows for forward incrementable access to data of the given data container, allows for using / passing either std::vector or std::array. See https://en.cppreference.com/w/cpp/iterator/input_iterator for more information on the requirements of the iterator |
| MaxKeyValuePairAmount | Maximum amount of key-value pairs, which will ever be sent with this method. Should simply be the biggest distance between first and last iterator this method is ever called with |
| first | Iterator pointing to the first element in the data container |
| last | Iterator pointing to the end of the data container (last element + 1) |
|
inline |
Sends the given key-value pair as telemetry data. See https://thingsboard.io/docs/user-guide/telemetry/ for more information.
| T | Type of the passed value |
| key | Non owning pointer to the key of the key-value pair. Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the key-value pair |
| value | Value of the key-value pair |
|
inline |
Send key-value pairs as telemetry data. See https://thingsboard.io/docs/user-guide/telemetry/ for more information.
| source | JsonDocument containing our json key-value pairs, is checked before usage for any possible occuring internal errors. See https://arduinojson.org/v6/api/jsondocument/ for more information |
|
inline |
Send string containing json as telemetry data. See https://thingsboard.io/docs/user-guide/telemetry/ for more information.
| json | Non owning pointer to the string containing our json key-value pairs Does not need to kept alive as the function copies the data into the outgoing HTTP buffer to publish the key-value pairs |
|
inline |
Sets the maximum amount of bytes that we want to allocate on the stack, before the memory is allocated on the heap instead.
| max_stack_size | Maximum amount of bytes we want to allocate on the stack |