Skip to content

Commit

Permalink
Revert changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
Coscolin committed Feb 4, 2024
1 parent f7c42d1 commit 3e13680
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 50 deletions.
9 changes: 1 addition & 8 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,11 +107,6 @@ uint16_t co2RedRange = 1000;
#endif

#include <WiFi.h>
#include <WiFiMulti.h>
<<<<<<< HEAD

=======
>>>>>>> 56fa71210855b96b41690aad2566683b671c8fe7
#include <Wire.h>

#include "driver/adc.h"
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 9 additions & 42 deletions CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -707,7 +675,6 @@ void initWifi() {
}
}
}

if ((WiFiConnectionRetries > maxWiFiConnectionRetries) && (WiFi.status() != WL_CONNECTED)) {
disableWiFi();
troubledWIFI = true;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 3e13680

Please sign in to comment.