Skip to content
Stand with Ukraine flag

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.

FeatureAPI class
Telemetry uploadThingsBoardSized
Device attribute publishThingsBoardSized
Server-side RPCServer_Side_RPC
Client-side RPCClient_Side_RPC
Request attribute valuesAttribute_Request_Callback
Attribute update subscriptionShared_Attribute_Update
Device provisioningProvision
Device claimingThingsBoardSized
Firmware OTA updateOTA_Firmware_Update
  • Telemetry upload
  • Device attribute publish

Other HTTP features can be implemented manually with sendGetRequest or sendPostRequest. See the HTTP API reference.

FrameworkMQTT clientNotes
ArduinoArduino_MQTT_ClientWorks with ESP32, ESP8266, Arduino boards
Espressif IDFEspressif_MQTT_ClientESP-IDF v4.4+ and v5.1+

The only always-required dependency is ArduinoJson v6.x.x (v7 not yet supported).

Open Tools > Manage Libraries, search for ThingsBoard, and install.

Add to platformio.ini:

lib_deps=
thingsboard/ThingsBoard
Terminal window
idf.py add-dependency "thingsboard/ThingsBoard"

For ESP IDF versions prior to v3.2.0, add as a git submodule:

Terminal window
git submodule add https://github.com/thingsboard/thingsboard-client-sdk.git components/ThingsBoard

Installed automatically:

Manual installation (if needed):

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.eu.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);
}

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 fields
ThingsBoardSized<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.

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>
#define THINGSBOARD_ENABLE_DEBUG 1
#include <ThingsBoard.h>

See the examples folder in the thingsboard-client-sdk repository, including the ESP32 Pico Kit GPIO control and DHT22 sensor tutorial.