From ca771e536b66e8fc596785ef71776eb65b9cd921 Mon Sep 17 00:00:00 2001 From: Alex Alvarado <931857-alexb737@users.noreply.gitlab.com> Date: Tue, 10 May 2022 09:35:24 +0200 Subject: [PATCH] Add WiFi management voids --- include/ESP32_WIFI.hpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 include/ESP32_WIFI.hpp diff --git a/include/ESP32_WIFI.hpp b/include/ESP32_WIFI.hpp new file mode 100644 index 0000000..96c4f74 --- /dev/null +++ b/include/ESP32_WIFI.hpp @@ -0,0 +1,45 @@ +/**********************************************/ +void configWiFi(){ + /************ AP ************************/ + WiFi.setHostname(deviceID().c_str()); + WiFi.softAP(nameap, passwordap); + log("\nInfo: WiFi AP " + deviceID() + " - IP " + ipStr(WiFi.softAPIP())); + //dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure); + //dnsServer.start(DNSSERVER_PORT, "*", WiFi.softAPIP()); + + ///************ CLIENTE *******************/ + //WiFi.begin(ssid, pw); + //log("\nInfo: Conectando WiFi " + String(ssid)); + //byte b = 0; + //while (WiFi.status() != WL_CONNECTED && b < 60){ + // b++; + // delay(500); + // //para parpadear led WIFI cuando esta conectandose al wifi no bloqueante + // unsigned long currentMillis = millis(); + // if (currentMillis - previousMillis >= interval){ + // // * Guarda la última vez que parpadeó el LED. + // previousMillis = currentMillis; + // // * Si el LED está apagado, enciéndalo y viceversa: + // ledState = not(ledState); + // // * configurar el LED con el ledState de la variable: + // digitalWrite(WIFILED, ledState); + // } + //} +// + //if (WiFi.status() == WL_CONNECTED){ + // // WiFi Station conectado + // log("\nInfo: WiFi conectado (" + String(WiFi.RSSI()) + ") IP " + ipStr(WiFi.localIP())); + // digitalWrite(WIFILED, HIGH); + //}else{ + // log(F("\nError: WiFi no conectado")); + // digitalWrite(MQTTLED, LOW); + //} +} + +void WiFiStationDisconnected(WiFiEvent_t event, WiFiEventInfo_t info){ + Logger::Log(Logger::INFO, "WiFI Desconectado"); + Logger::Log(Logger::ERROR, "Código de error: " + info.disconnected.reason); + Logger::Log(Logger::INFO, "Intentando reconectar"); + WiFi.disconnect(); + WiFi.begin(ssid, pw); +} \ No newline at end of file