#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String payload;
WiFiClient IOT;
HTTPClient http;
const char* serverURL = "https://eff1-187-182-196-183.ngrok-free.app/Energia";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Conectando ao WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConectado ao WiFi!");
}
void loop() {
// valores para teste
float temperature = 25.0;
float humidity = 60.0;
if (WiFi.status() == WL_CONNECTED) {
http.begin(serverURL);
http.addHeader("Content-Type", "application/json");
String httpRequestData = "{\"Nome\": \"" + String(temperature) + "\",\"Produzido\": \"" + String(humidity) + "\",\"Gasto\": \"" + String(humidity) + "\",\"Armazenado\": \"" + String(humidity) + "\",\"Distribuido\": \"" + String(humidity) + "\"}";
int httpResponseCode = http.POST(httpRequestData);
Serial.println(httpResponseCode);
Serial.println(httpRequestData);
String response = http.getString();
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String response = http.getString();
Serial.println("Resposta do servidor:");
Serial.println(response);
} else {
Serial.print("Erro no envio da requisição, código: ");
Serial.println(httpResponseCode);
}
http.end();
} else {
Serial.println("Falha na conexão WiFi.");
}
delay(10000);
}