From 3e1368063720b2d7aa77f62212812fef0912c440 Mon Sep 17 00:00:00 2001 From: Coscolin Date: Sun, 4 Feb 2024 18:11:16 +0100 Subject: [PATCH] Revert changes to master --- CO2_Gadget.ino | 9 +-------- CO2_Gadget_WIFI.h | 51 +++++++++-------------------------------------- 2 files changed, 10 insertions(+), 50 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index ad873da0..4a1dd17f 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -25,8 +25,6 @@ String mqttUser = ""; String mqttPass = ""; String wifiSSID = WIFI_SSID_CREDENTIALS; String wifiPass = WIFI_PW_CREDENTIALS; -String wifiSSID2 = ""; -String wifiPass2 = ""; String mDNSName = "Unset"; String MACAddress = "Unset"; uint8_t peerESPNowAddress[] = ESPNOW_PEER_MAC_ADDRESS; @@ -109,11 +107,6 @@ uint16_t co2RedRange = 1000; #endif #include -#include -<<<<<<< HEAD - -======= ->>>>>>> 56fa71210855b96b41690aad2566683b671c8fe7 #include #include "driver/adc.h" @@ -422,7 +415,7 @@ void setCpuFrequencyAndReinitSerial(int16_t newCpuFrequency) { while (Serial.available()) { Serial.read(); } - delay(100); // time to write all data to serial + delay(100); // time to write all data to serial #if defined(CONFIG_IDF_TARGET_ESP32) Serial.end(); setCpuFrequencyMhz(newCpuFrequency); diff --git a/CO2_Gadget_WIFI.h b/CO2_Gadget_WIFI.h index ab059adb..44025088 100644 --- a/CO2_Gadget_WIFI.h +++ b/CO2_Gadget_WIFI.h @@ -15,12 +15,8 @@ #endif WiFiClient espClient; -WiFiMulti wifiMulti; AsyncWebServer server(80); -// WiFi connect timeout per AP. Increase when connecting takes longer. -const uint32_t connectTimeoutMs = 10000; - void printSmallChar(char c, int row) { switch (c) { case '0': @@ -646,12 +642,13 @@ void initWifi() { troubledWIFI = false; WiFiConnectionRetries = 0; displayNotification("Init WiFi", notifyInfo); - Serial.println("-->[WiFi] Initializing WiFi..."); -// WiFi.disconnect(true); // disconnect form wifi to set new wifi connection -// delay(500); + Serial.print("-->[WiFi] Initializing WiFi...\n"); + WiFi.disconnect(true); // disconnect form wifi to set new wifi connection + delay(500); WiFi.mode(WIFI_STA); WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); - Serial.printf("-->[WiFi] Setting hostname %s: %d\n", hostName.c_str(), WiFi.setHostname(hostName.c_str())); + Serial.printf("-->[WiFi] Setting hostname %s: %d\n", hostName.c_str(), + WiFi.setHostname(hostName.c_str())); WiFi.onEvent(WiFiStationConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED); WiFi.onEvent(WiFiStationGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); @@ -662,39 +659,10 @@ void initWifi() { // WiFi.setSleep(true); // WiFi.setSleep(WIFI_PS_NONE); - String connectMessage = "-->[WiFi] Connecting to WiFi (SSID: " + String(wifiSSID) + " - PASS: " + String(wifiPass) - +" OR SSID2: " + String(wifiSSID2) + " - PASS2: " + String(wifiPass2) +")\n"; + String connectMessage = "-->[WiFi] Connecting to WiFi (SSID: " + String(wifiSSID) + ")\n"; Serial.print(connectMessage); -// WiFi.begin(wifiSSID.c_str(), wifiPass.c_str()); - - if(wifiSSID != "") wifiMulti.addAP(wifiSSID.c_str(), wifiPass.c_str()); - if(wifiSSID2 != "") wifiMulti.addAP(wifiSSID2.c_str(), wifiPass2.c_str()); - - // WiFi.scanNetworks will return the number of networks found - /* - Serial.println("Scanning WiFi networks..."); - int n = WiFi.scanNetworks(); - if (n == 0) { - Serial.println("no networks found"); - } else { - Serial.print(n); - Serial.println(" networks found"); - for (int i = 0; i < n; ++i) { - // Print SSID and RSSI for each network found - Serial.print(i + 1); - Serial.print(": "); - Serial.print(WiFi.SSID(i)); - Serial.print(" ("); - Serial.print(WiFi.RSSI(i)); - Serial.print(")"); - Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); - delay(10); - } - } - */ - // Connect to Wi-Fi using wifiMulti (connects to the SSID with strongest connection) - Serial.println("Connecting Wifi..."); - wifiMulti.run(connectTimeoutMs); + WiFi.begin(wifiSSID.c_str(), wifiPass.c_str()); + // Wait for connection while (WiFi.status() != WL_CONNECTED && WiFiConnectionRetries < maxWiFiConnectionRetries) { yield(); // very important to execute yield to make it work @@ -707,7 +675,6 @@ void initWifi() { } } } - if ((WiFiConnectionRetries > maxWiFiConnectionRetries) && (WiFi.status() != WL_CONNECTED)) { disableWiFi(); troubledWIFI = true; @@ -753,7 +720,7 @@ void wifiClientLoop() { if (activeWIFI && troubledWIFI && (millis() - timeTroubledWIFI >= timeToRetryTroubledWIFI * 1000)) { initWifi(); } - + // This is a workaround until I can directly determine whether the Wi-Fi data has been changed via BLE // Only checks for SSID changed (not password) if ((WiFi.SSID() != wifiSSID) && (!inMenu)) {