From dc20ed4874ae55dacb22a8c76865b5664e924b51 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Wed, 22 Jan 2025 23:10:28 +0100 Subject: [PATCH] Improvements & fixes (#178) - Fix for unPhone sleep: it would wake up every minute briefly (draining the battery over the course of 1-3 days) - Minor WiFi improvements (mainly added logging and improved filtering on connect .. the latter probably doesn't matter) --- Boards/UnPhone/Source/PowerOn.cpp | 3 ++- Documentation/ideas.md | 7 +++---- .../Source/service/wifi/WifiEsp.cpp | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Boards/UnPhone/Source/PowerOn.cpp b/Boards/UnPhone/Source/PowerOn.cpp index 64663250..8c4a1ba8 100644 --- a/Boards/UnPhone/Source/PowerOn.cpp +++ b/Boards/UnPhone/Source/PowerOn.cpp @@ -25,7 +25,8 @@ static void updatePowerSwitch() { } } else { // power switch off and usb plugged in we sleep unPhoneFeatures.wakeOnPowerSwitch(); - esp_sleep_enable_timer_wakeup(60000000); // ea min: USB? else->shipping + // Using UINT64_MAX leads to boot loops because of a bug in esp_sleep_start() converting it to int64_t before sleeping + esp_sleep_enable_timer_wakeup(UINT64_MAX / 2); // ea min: USB? else->shipping esp_deep_sleep_start(); // deep sleep, wait for wakeup on GPIO } diff --git a/Documentation/ideas.md b/Documentation/ideas.md index cec638fa..58e7af4b 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -12,9 +12,10 @@ - EventFlag: Fix return value of set/get/wait (the errors are weirdly mixed in) - Fix bug in T-Deck/etc: esp_lvgl_port settings has a large stack size (~9kB) to fix an issue where the T-Deck would get a stackoverflow. This sometimes happens when WiFi is auto-enabled and you open the app while it is still connecting. - M5Stack Core only shows 4MB of SPIRAM in use -- Oops crashlog site: Add copy-pasteable addr2line command (e.g. xtensa-esp32s3-elf-addr2line -pfiaC -e Tactility.elf 00000000) # TODOs +- Expose app::Paths to TactilityC +- Refactor ServiceManifest into C++ class-based design like the App class - Experiment with what happens when using C++ code in an external app (without using standard library!) - Boards' CMakeLists.txt manually declare each source folder. Update them all to do a recursive search of all folders. - We currently build all boards for a given platform (e.g. ESP32S3), but it's better to filter all irrelevant ones based on the Kconfig board settings: @@ -45,12 +46,10 @@ - Audio player app - Audio recording app - OTA updates -- Web flasher - T-Deck Plus: Create separate board config? - Support for displays with different DPI. Consider the layer-based system like on Android. -- Make firmwares available via web serial website - If present, use LED to show boot/wifi status -- T-Deck Power: capacity estimation uses linear voltage curve, but it should use some sort of battery discharge curve. +- Capacity based on voltage: estimation for various devices uses linear voltage curve, but it should use some sort of battery discharge curve. - Statusbar widget to show how much memory is in use? - Wrapper for Slider that shows "+" and "-" buttons, and also the value in a label. - Display app: Add toggle to display performance measurement overlay (consider showing FPS in statusbar!) diff --git a/TactilityHeadless/Source/service/wifi/WifiEsp.cpp b/TactilityHeadless/Source/service/wifi/WifiEsp.cpp index d9b6d59c..ebd8b531 100644 --- a/TactilityHeadless/Source/service/wifi/WifiEsp.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiEsp.cpp @@ -446,6 +446,12 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32 return; } + if (event_base == WIFI_EVENT) { + TT_LOG_I(TAG, "eventHandler: WIFI_EVENT (%ld)", event_id); + } else if (event_base == IP_EVENT) { + TT_LOG_W(TAG, "eventHandler: IP_EVENT (%ld)", event_id); + } + if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { TT_LOG_I(TAG, "eventHandler: sta start"); if (wifi->getRadioState() == RadioState::ConnectionPending) { @@ -708,6 +714,8 @@ static void dispatchConnect(std::shared_ptr context) { } } + wifi->setScanActive(false); + wifi->setRadioState(RadioState::ConnectionPending); publish_event_simple(wifi, EventType::ConnectionPending); @@ -729,7 +737,7 @@ static void dispatchConnect(std::shared_ptr context) { .sort_method = WIFI_CONNECT_AP_BY_SIGNAL, .threshold = { .rssi = 0, - .authmode = WIFI_AUTH_WPA2_WPA3_PSK, + .authmode = WIFI_AUTH_OPEN, }, .pmf_cfg = { .capable = false, @@ -762,6 +770,13 @@ static void dispatchConnect(std::shared_ptr context) { memcpy(wifi_config.sta.ssid, wifi_singleton->connection_target.ssid, sizeof(wifi_config.sta.ssid)); memcpy(wifi_config.sta.password, wifi_singleton->connection_target.password, sizeof(wifi_config.sta.password)); + if (wifi_singleton->connection_target.password[0] != 0x00U) { + wifi_config.sta.threshold.authmode = WIFI_AUTH_WPA2_WPA3_PSK; + } else { + wifi_config.sta.threshold.authmode = WIFI_AUTH_OPEN; + } + + TT_LOG_I(TAG, "esp_wifi_set_config()"); esp_err_t set_config_result = esp_wifi_set_config(WIFI_IF_STA, &wifi_config); if (set_config_result != ESP_OK) { wifi->setRadioState(RadioState::On); @@ -770,6 +785,7 @@ static void dispatchConnect(std::shared_ptr context) { return; } + TT_LOG_I(TAG, "esp_wifi_start()"); esp_err_t wifi_start_result = esp_wifi_start(); if (wifi_start_result != ESP_OK) { wifi->setRadioState(RadioState::On);