From 9c94411eeb2cfaa1afdd4e4d6273d67284ef5793 Mon Sep 17 00:00:00 2001 From: lorow Date: Wed, 10 Apr 2024 23:21:17 +0200 Subject: [PATCH 1/2] set setMinSecurity to WIFI_AUTH_WEP to fix boards not connecting to some networks, cleanup some logs and comments --- .../src/network/wifihandler/wifihandler.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ESP/lib/src/network/wifihandler/wifihandler.cpp b/ESP/lib/src/network/wifihandler/wifihandler.cpp index 0c85ed5..8693eb2 100644 --- a/ESP/lib/src/network/wifihandler/wifihandler.cpp +++ b/ESP/lib/src/network/wifihandler/wifihandler.cpp @@ -18,6 +18,13 @@ WiFiHandler::WiFiHandler(ProjectConfig& configManager, WiFiHandler::~WiFiHandler() {} void WiFiHandler::begin() { + + // just to be sure, we reeset everything before we do anything, some boards were having problems otherwise + WiFi.disconnect(); + // we purposefully set the lowest min required security level, some boards have problems connecting otherwise + // https://github.com/espressif/arduino-esp32/issues/8770 + WiFi.setMinSecurity(WIFI_AUTH_WEP); + log_i("Starting WiFi Handler \n\r"); if (this->_enable_adhoc || wifiStateManager.getCurrentState() == WiFiState_e::WiFiState_ADHOC) { @@ -40,8 +47,6 @@ void WiFiHandler::begin() { if (networks.empty()) { log_i("No networks found in config, trying the default one \n\r"); - // since networks may not have a password, we only need to check if we have an ssid - // bail if we don't if (this->iniSTA( this->ssid, this->password, @@ -135,6 +140,8 @@ bool WiFiHandler::iniSTA(const std::string& ssid, uint8_t channel, wifi_power_t power) { + // since networks may not have a password, we only need to check if we have an ssid + // bail if we don't if (ssid == ""){ log_d("ssid missing, bailing"); return false; @@ -148,13 +155,14 @@ bool WiFiHandler::iniSTA(const std::string& ssid, wifiStateManager.setState(WiFiState_e::WiFiState_Connecting); log_i("Trying to connect to: %s \n\r", ssid.c_str()); auto mdnsConfig = configManager.getMDNSConfig(); - - log_d("Setting hostname %s \n\r"); WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); // need to call before setting hostname + log_d("Setting hostname %s \n\r"); WiFi.setHostname(mdnsConfig.hostname.c_str()); + log_i("Setting TX power to: %d \n\r", (uint8_t)power); + WiFi.setTxPower(power); // https://github.com/espressif/arduino-esp32/issues/5698 WiFi.begin(ssid.c_str(), password.c_str(), channel); - WiFi.setTxPower(power); + log_d("Waiting for WiFi to connect... \n\r"); while (WiFi.status() != WL_CONNECTED) { progress++; @@ -169,7 +177,6 @@ bool WiFiHandler::iniSTA(const std::string& ssid, } wifiStateManager.setState(WiFiState_e::WiFiState_Connected); log_i("Successfully connected to %s \n\r", ssid.c_str()); - log_i("Setting TX power to: %d \n\r", (uint8_t)power); return true; } From 53a3d4bcd603e2fd07546621628e69de88e4139a Mon Sep 17 00:00:00 2001 From: lorow Date: Fri, 31 May 2024 17:07:21 +0200 Subject: [PATCH 2/2] feat: Move logging in serial streaming so that we at least attempt to get new frame --- ESP/lib/src/io/Serial/SerialManager.cpp | 46 ++++++++++++------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/ESP/lib/src/io/Serial/SerialManager.cpp b/ESP/lib/src/io/Serial/SerialManager.cpp index 70049a6..df7a15b 100644 --- a/ESP/lib/src/io/Serial/SerialManager.cpp +++ b/ESP/lib/src/io/Serial/SerialManager.cpp @@ -5,10 +5,6 @@ SerialManager::SerialManager(CommandManager* commandManager) #ifdef ETVR_EYE_TRACKER_USB_API void SerialManager::send_frame() { - // if we failed to capture the frame, we bail, but we still want to listen to commands - if (err != ESP_OK) - return; - if (!last_frame) last_frame = esp_timer_get_time(); @@ -21,14 +17,17 @@ void SerialManager::send_frame() { if (fb) { len = fb->len; buf = fb->buf; - } else { - log_e("Camera capture failed with response: %s", esp_err_to_name(err)); + } else err = ESP_FAIL; + + // if we failed to capture the frame, we bail, but we still want to listen to + // commands + if (err != ESP_OK) { + log_e("Camera capture failed with response: %s", esp_err_to_name(err)); + return; } - if (err == ESP_OK) - Serial.write(ETVR_HEADER, 2); - + Serial.write(ETVR_HEADER, 2); Serial.write(ETVR_HEADER_FRAME, 2); len_bytes[0] = len & 0xFF; len_bytes[1] = (len >> CHAR_BIT) & 0xFF; @@ -54,29 +53,28 @@ void SerialManager::send_frame() { void SerialManager::init() { Serial.begin(3000000); - if (SERIAL_FLUSH_ENABLED){ + if (SERIAL_FLUSH_ENABLED) { Serial.flush(); } } void SerialManager::run() { - if (Serial.available()) { - JsonDocument doc; - DeserializationError deserializationError = deserializeJson(doc, Serial); + if (Serial.available()) { + JsonDocument doc; + DeserializationError deserializationError = deserializeJson(doc, Serial); - if (deserializationError) { - log_e("Command deserialization failed: %s", - deserializationError.c_str()); - - return; - } + if (deserializationError) { + log_e("Command deserialization failed: %s", deserializationError.c_str()); - CommandsPayload commands = {doc}; - this->commandManager->handleCommands(commands); + return; } + + CommandsPayload commands = {doc}; + this->commandManager->handleCommands(commands); + } #ifdef ETVR_EYE_TRACKER_USB_API - else { - this->send_frame(); - } + else { + this->send_frame(); + } #endif }