#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const int LED_PIN = 2;
const int PIN_GAS = 34;
WebServer server(80);
void raiz() {
int ValorSensorGas = analogRead(PIN_GAS) ;
int ValorCalculado = map(ValorSensorGas, 843, 4041, 0, 100);
String html =
"<!doctype html><html><head>"
"<meta charset='utf-8'>"
"<meta name='viewport' content='width=device-width, initial-scale=1'>"
"<title>Servidor ESP32 - GAS</title>"
"<style>body{font-family:Arial;padding:20px;} .card{padding:16px;border:1px solid #ccc;border-radius:12px;max-width:420px;}</style>"
"</head><body>"
"<div class='card'>"
"<h2>Servidor ESP32 - GAS</h2><ul>";
html = html + "<li>Valor Obtido: " + String(ValorSensorGas) + "</li>";
html = html + "<li>Valor Calculado: " + String(ValorCalculado) + "</li>";
html = html + "</ul>"
"</div>"
"</body></html>";
server.send(200, "text/html; charset=utf-8", html);
}
void NaoEncontrado() {
server.send(404, "text/plain; charset=utf-8", "404 - Nao encontrado");
}
void setup() {
Serial.begin(115200);
delay(100);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Conectando ao Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConectado!");
Serial.print("IP do ESP32: ");
Serial.println(WiFi.localIP());
server.on("/", raiz);
server.onNotFound(NaoEncontrado);
server.begin();
Serial.println("Servidor HTTP iniciado!");
}
void loop() {
server.handleClient();
}