#include #include const char* ssid = "PogodaESP"; const int sensorPin = 34; IPAddress local_IP(192, 168, 4, 1); IPAddress gateway(192, 168, 4, 1); IPAddress subnet(255, 255, 255, 0); WebServer server(80); const char* stronaHTML = R"rawliteral( Sensor Deszczu

Stan: Ładowanie...

Wartość sensora: --
)rawliteral"; void setup() { Serial.begin(115200); pinMode(sensorPin, INPUT); WiFi.softAPConfig(local_IP, gateway, subnet); WiFi.softAP(ssid); delay(500); Serial.println("\n--- SYSTEM URUCHOMIONY ---"); Serial.print("IP serwera: "); Serial.println(WiFi.softAPIP()); server.on("/", []() { server.send(200, "text/html", stronaHTML); }); server.on("/odczyt", []() { long suma = 0; for(int i = 0; i < 10; i++) { suma += analogRead(sensorPin); delay(5); } int srednia = suma / 10; Serial.print("Aktualna wartosc sensora: "); Serial.println(srednia); String status; if (srednia < 50) { status = "NIE PADA"; } else if (srednia < 3000) { status = "PADA"; } else { status = "NIE PADA"; } String json = "{\"status\":\"" + status + "\", \"wartosc\":" + String(srednia) + "}"; server.send(200, "application/json", json); }); server.begin(); } void loop() { server.handleClient(); }