# Help with Thingsboard.io and XIAO ESP32C3

**URL:** <https://forum.arduino.cc/t/help-with-thingsboard-io-and-xiao-esp32c3/1352200>\
**Category:** Programming\
**Created:** [February 10, 2025, 3:17am UTC](https://forum.arduino.cc/t/help-with-thingsboard-io-and-xiao-esp32c3/1352200 "2025-02-10T03:17:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdksolar](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cdksolar/32/1126423_2.png) [@cdksolar](https://forum.arduino.cc/u/cdksolar)\
**Post date:** [February 10, 2025, 3:17am UTC](https://forum.arduino.cc/t/help-with-thingsboard-io-and-xiao-esp32c3/1352200/1 "2025-02-10T03:17:27Z")

</div>

Hi There,

I am pulling my hair out on this one and cant get it to compile ! I am trying to create a simple sensor to send data to [thingsboard.io](http://thingsboard.io) ..... any help would be greatly apricated.

I have tried many library versions with no success

```arduino
#include <DHTesp.h>
#include <WiFi.h>
#include <ThingsBoard.h>
#include <ArduinoMqttClient.h>
#include <TBPubSubClient.h>
#define pinDht 15
DHTesp dhtSensor;

#define WIFI_AP "Wokwi-GUEST"
#define WIFI_PASS ""

#define TB_SERVER "thingsboard.cloud"
#define TOKEN "O7HuziT3C7PLIs1PQ8OX"

constexpr uint16_t MAX_MESSAGE_SIZE = 128U;

WiFiClient espClient;
ArduinoMqttClient mqttClient(espClient);
ThingsBoard tb(mqttClient, MAX_MESSAGE_SIZE);

void connectToWiFi() {
  Serial.println("Connecting to WiFi...");
  int attempts = 0;
  
  while (WiFi.status() != WL_CONNECTED && attempts < 20) {
    WiFi.begin(WIFI_AP, WIFI_PASS, 6);
    delay(500);
    Serial.print(".");
    attempts++;
  }
  
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("\nFailed to connect to WiFi.");
  } else {
    Serial.println("\nConnected to WiFi");
  }
}

void connectToThingsBoard() {
  if (!tb.connected()) {
    Serial.println("Connecting to ThingsBoard server");
    
    if (!tb.connect(TB_SERVER, TOKEN)) {
      Serial.println("Failed to connect to ThingsBoard");
    } else {
      Serial.println("Connected to ThingsBoard");
    }
  }
}

void sendDataToThingsBoard(float temp, int hum) {
  String jsonData = "{\"temperature\":" + String(temp) + ", \"humidity\":" + String(hum) + "}";
  tb.sendTelemetryJson(jsonData.c_str());
  Serial.println("Data sent");
}

void setup() {
  Serial.begin(115200);
  dhtSensor.setup(pinDht,DHTesp::DHT22);
  connectToWiFi();
  connectToThingsBoard();
}

void loop() {
  connectToWiFi();

  TempAndHumidity data =dhtSensor.getTempAndHumidity();
  float temp = data.temperature;
  int hum = data.humidity;

  Serial.println(temp);
  Serial.println(hum);

  if (!tb.connected()) {
    connectToThingsBoard();
  }

  sendDataToThingsBoard(temp, hum);

  delay(3000);

  tb.loop();
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 9, 2025, 3:17am UTC](https://forum.arduino.cc/t/help-with-thingsboard-io-and-xiao-esp32c3/1352200/2 "2025-08-09T03:17:30Z")

</div>

Closed on August 9, 2025, 3:17am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
