// Load Wi-Fi library
#include <WiFi.h>
#include <HTTPClient.h>
const char* WIFI_SSID = "Wokwi-GUEST";
const char* WIFI_PASSWORD = "";
const int LM35Pin = 34;
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void sendDataToThingsBoard(String device, String value) {
HTTPClient http;
String url = "http://thingsboard.cloud/api/v1/slFmIBsxbfLHcIzOeUxH/telemetry";
String payload = "{"+device+":" + value + "}";
http.begin(url);
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
Serial.println("Data sent to ThingsBoard successfully");
} else {
Serial.println("Error sending data to ThingsBoard");
}
http.end();
}
void loop(){
int sensorValue = analogRead(LM35Pin);
float temperatureC = (sensorValue / 4095.0) * 330.0;
Serial.println("Temperature : "+String(temperatureC)+"°C");
// Send data to IOT Website
sendDataToThingsBoard("Temperature",String(temperatureC));
delay(2000);
}