#define PIN_LM35 33
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* thingsboard_server = "demo.thingsboard.io";
const char* token = "FnmBebnjBsTvxtvGQapE";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
}
void loop() {
if(WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://" + String(thingsboard_server) + "/api/v1/" + String(token) + "/telemetry");
http.addHeader("Content-Type", "application/json");
int adcVal = analogRead(PIN_LM35);
double milliVolt = adcVal * (1.22);
double tempC = milliVolt / 10;
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println("°C");
int httpResponseCode = http.POST("{\"temperature\":" + String(tempC) + "}");
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
}
else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("Error in WiFi connection");
}
delay(5000);
}