#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);
}

esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
LM35Breakout
chip1:VCC
chip1:OUT
chip1:GND