Arduino Client SDK
The ThingsBoard Arduino SDK connects Arduino, ESP32, ESP8266, and other embedded devices to ThingsBoard over MQTT or HTTP(S).
The SDK does not depend on a specific MQTT or HTTP client — any implementation of IMQTT_Client or IHTTP_Client can be used,
making it compatible with both Arduino and Espressif IDF frameworks.
Supported features
Section titled “Supported features”Over MQTT
Section titled “Over MQTT”| Feature | API class |
|---|---|
| Telemetry upload | ThingsBoardSized |
| Device attribute publish | ThingsBoardSized |
| Server-side RPC | Server_Side_RPC |
| Client-side RPC | Client_Side_RPC |
| Request attribute values | Attribute_Request_Callback |
| Attribute update subscription | Shared_Attribute_Update |
| Device provisioning | Provision |
| Device claiming | ThingsBoardSized |
| Firmware OTA update | OTA_Firmware_Update |
Over HTTP(S)
Section titled “Over HTTP(S)”- Telemetry upload
- Device attribute publish
Other HTTP features can be implemented manually with sendGetRequest or sendPostRequest. See the HTTP API reference.
Supported frameworks
Section titled “Supported frameworks”| Framework | MQTT client | Notes |
|---|---|---|
| Arduino | Arduino_MQTT_Client | Works with ESP32, ESP8266, Arduino boards |
| Espressif IDF | Espressif_MQTT_Client | ESP-IDF v4.4+ and v5.1+ |
The only always-required dependency is ArduinoJson v6.x.x (v7 not yet supported).
Installation
Section titled “Installation”Arduino IDE
Section titled “Arduino IDE”Open Tools > Manage Libraries, search for ThingsBoard, and install.
PlatformIO
Section titled “PlatformIO”Add to platformio.ini:
lib_deps= thingsboard/ThingsBoardESP IDF (v3.2.0+)
Section titled “ESP IDF (v3.2.0+)”idf.py add-dependency "thingsboard/ThingsBoard"For ESP IDF versions prior to v3.2.0, add as a git submodule:
git submodule add https://github.com/thingsboard/thingsboard-client-sdk.git components/ThingsBoardDependencies
Section titled “Dependencies”Installed automatically:
- ArduinoJson v6.x.x — JSON serialization/deserialization
- MQTT PubSub Client — MQTT transport (Arduino framework)
- Arduino HTTP Client — HTTP(S) transport (Arduino framework)
Manual installation (if needed):
- MbedTLS Library — OTA update hashes (non-Espressif boards)
- Arduino Timer — non-blocking timers (non-Espressif boards)
- WiFiEsp Client — Arduino Uno with ESP8266
- StreamUtils — send payloads larger than the internal buffer
Getting started
Section titled “Getting started”Basic telemetry upload with an ESP32:
#include <WiFi.h>#include <Arduino_MQTT_Client.h>#include <ThingsBoard.h>
constexpr char WIFI_SSID[] = "YOUR_SSID";constexpr char WIFI_PASSWORD[] = "YOUR_PASSWORD";constexpr char TB_SERVER[] = "mqtt.thingsboard.cloud";constexpr char TOKEN[] = "YOUR_ACCESS_TOKEN";constexpr uint16_t TB_PORT = 1883U;
WiFiClient espClient;Arduino_MQTT_Client mqttClient(espClient);ThingsBoard tb(mqttClient);
void setup() {Serial.begin(115200);WiFi.begin(WIFI_SSID, WIFI_PASSWORD);while (WiFi.status() != WL_CONNECTED) { delay(500);}tb.connect(TB_SERVER, TOKEN, TB_PORT);}
void loop() {tb.sendTelemetryData("temperature", 25.5);tb.loop();delay(1000);}Buffer size configuration
Section titled “Buffer size configuration”The default JSON buffer is 64 bytes. Increase it if your payloads are larger:
WiFiClient espClient;Arduino_MQTT_Client mqttClient(espClient);
// 128-byte buffer, 32 JSON fieldsThingsBoardSized<32> tb(mqttClient, 128, 128);
void setup() { // Or increase after creation tb.setBufferSize(128, 128);}Alternatively, install the StreamUtils library to send payloads larger than the buffer without increasing buffer size.
Dynamic mode
Section titled “Dynamic mode”To avoid specifying template arguments for buffer sizes, enable dynamic mode. This uses heap allocation instead of stack:
#define THINGSBOARD_ENABLE_DYNAMIC 1#include <ThingsBoard.h>Enabling debug logs
Section titled “Enabling debug logs”#define THINGSBOARD_ENABLE_DEBUG 1#include <ThingsBoard.h>More examples
Section titled “More examples”See the examples folder in the thingsboard-client-sdk repository, including the ESP32 Pico Kit GPIO control and DHT22 sensor tutorial.