diff --git a/src/main.cpp b/src/main.cpp index 1556283..4f6afd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define RELAY 4 // GPIO4 #define WIFI_NAME "TechInc" @@ -18,6 +19,7 @@ boolean automatic = true; // ----- // void ensureWiFiConnection(); +void testInternet(); void relayOn(); void relayOff(); @@ -73,9 +75,12 @@ void webSetup() { server.on("/auto", []() { server.send(200, "text/plain", "automatic mode"); automatic = true; + ensureWiFiConnection(); + testInternet(); }); server.begin(); + if (MDNS.begin("internot")) { Serial.println("MDNS responder started"); } } void setup() @@ -83,9 +88,6 @@ void setup() Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); pinMode(RELAY, OUTPUT); - relayOn(); - delay(2000); - relayOff(); ensureWiFiConnection(); setupOTA(); webSetup(); @@ -119,7 +121,7 @@ void ensureWiFiConnection() if(status == WL_CONNECTED) return; else { - relayOff(); + if(!automatic) relayOff(); Serial.print("WiFi is disconnected, now connecting"); WiFi.begin(WIFI_NAME, WIFI_PASSWORD); while(WiFi.status() != WL_CONNECTED) { @@ -162,9 +164,10 @@ void loop() { ensureWiFiConnection(); testInternet(); - for(size_t i = 0; i < 5; i++) { + for(size_t i = 0; i < 20; i++) { ArduinoOTA.handle(); - delay(1000); + delay(250); server.handleClient(); + MDNS.update(); } }