#include<WiFi.h>
#include<HTTPClient.h>
const char* ssid = "TIM ULTRAFIBRA_2B08";
const char* password = "VLav!31AHu";
// Configuração do pino e resistor do NTC
const int ntcPin = 34; // Pino onde o NTC está conectado
const int seriesResistor = 10000; // Resistor em série com o NTC (em Ohms)
// Configuração do servidor
const char* serverName = "http://192.168.1.5:5000/receber_dados";
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, password);
// Esperar a conexão Wi-Fi
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Conectando ao WiFi...");
}
Serial.println("Conectado ao WiFi!");
}
void loop(){
int rawValue = analogRead(ntcPin);
float voltage = rawValue / 4095.0 * 3.3; // Conversão de ADC para tensão
float resistance = seriesResistor * (3.3 / voltage - 1.0); // Calcula a resistência do NTC
float temperature = 1.0 / (log(resistance / seriesResistor) / 3950 + 1 / 298.15) - 273.15; // Conversão para temperatura
Serial.print("Temperatura: ");
Serial.print(temperature);
Serial.println(" C");
// Enviar dados para o servidor
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String serverPath = String(serverName) + "?temperature=" + String(temperature);
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Erro na solicitação: ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(1000);
}