OTA bring-up fixes: loop-task jobs + PSRAM TLS, ESP-NOW survives Wi-Fi, wifi console
Firmware / build (push) Successful in 4m24s

- ota: internal RAM has 15.9 KB free / 7.6 KB largest block with Wi-Fi up, so
  jobs now run in the loop task (8 KB stack; 3.6 KB headroom measured on
  `ota check`) with mbedtls allocations routed to PSRAM during the job
- wifi_manager: WiFi.disconnect(true) powered the radio off and killed ESP-NOW
  whenever Wi-Fi was used; now disconnect() only. showConnectionResult() waits
  for the LVGL lock and null-checks widgets. New `wifi join|status|off` console
- espnow_link: send() re-initialises ESP-NOW if the driver dropped it
- wiki: ota-updates memory + bugs sections, open-questions #13 (internal RAM),
  log; CLAUDE.md notes

Verified on the board: `wifi join` connects, ESP-NOW 195 sent / 0 failed while
joined, `ota check` verifies v0.1.0's signature on-device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 22:37:08 +02:00
parent f5b7f43e7c
commit bb0895674a
9 changed files with 142 additions and 23 deletions
+51 -5
View File
@@ -3,6 +3,7 @@
*/
#include "wifi_manager.h"
#include "espnow_link.h"
#include "display/lvgl_v8_port.h"
// External UI element references (from ui_Settings_Screen.c)
@@ -91,10 +92,15 @@ static String formatNetworkName(const wifi_network_t& network) {
* @note Must be called with LVGL lock held OR will acquire lock internally
*/
static void showConnectionResult(bool success, const char* message) {
lvgl_port_lock(0);
// Wait for the lock (a 0 ms try-lock whose result was ignored used to race
// the LVGL task). Widgets are NULL whenever the Settings screen isn't
// loaded - e.g. a `wifi join` from the console - so check before touching.
lvgl_port_lock(-1);
// Hide loading spinner
lv_obj_add_flag(uic_Settings_Loading_Container, LV_OBJ_FLAG_HIDDEN);
if (uic_Settings_Loading_Container != NULL) {
lv_obj_add_flag(uic_Settings_Loading_Container, LV_OBJ_FLAG_HIDDEN);
}
if (success) {
// Connection successful
@@ -331,7 +337,7 @@ static void wifiTask(void* parameter) {
case WIFI_UI_EVENT_TOGGLE_OFF:
Serial.println("WiFi Task: Disabling WiFi...");
WiFi.disconnect(true);
WiFi.disconnect(); // NOT (true): that powers the radio off and kills ESP-NOW
// Radio stays in STA mode: the ESP-NOW link to Controller B
// rides on it. "WiFi off" here means scanning/association off.
g_wifi_state = WIFI_STATE_OFF;
@@ -358,7 +364,7 @@ static void wifiTask(void* parameter) {
g_wifi_state = WIFI_STATE_CONNECTED; // Will be updated based on result
// Attempt connection
WiFi.disconnect(true); // Clear any previous connection
WiFi.disconnect(); // Clear any previous connection (radio stays on: ESP-NOW rides on it)
delay(100);
if (strlen(creds->password) > 0) {
@@ -401,7 +407,7 @@ static void wifiTask(void* parameter) {
case WIFI_UI_EVENT_DISCONNECT:
Serial.println("WiFi Task: Disconnecting...");
WiFi.disconnect(true);
WiFi.disconnect(); // NOT (true): that powers the radio off and kills ESP-NOW
g_wifi_state = WIFI_STATE_SCANNING;
g_wifi_scan_requested = true;
break;
@@ -757,4 +763,44 @@ void onSelectSSID(lv_event_t *e) {
Serial.println("onSelectSSID() called - but dynamic buttons handle clicks now");
}
// ============================================================================
// CONSOLE (`wifi ...`) - join a network without the Settings screen, e.g. for OTA
// ============================================================================
bool handleCommand(const char* line) {
char buf[128];
strncpy(buf, line, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
char* argv[4] = {0};
int argc = 0;
for (char* t = strtok(buf, " \t"); t && argc < 4; t = strtok(NULL, " \t")) argv[argc++] = t;
if (argc == 0 || strcmp(argv[0], "wifi") != 0) return false;
if (argc >= 3 && !strcmp(argv[1], "join")) {
// SSIDs with spaces aren't supported here; use the Settings screen.
Serial.printf("[wifi] joining '%s'...\n", argv[2]);
connectToWiFi(argv[2], argc >= 4 ? argv[3] : NULL); // result logged by the WiFi task
} else if (argc == 2 && !strcmp(argv[1], "off")) {
wifi_queue_event_t evt = {WIFI_UI_EVENT_TOGGLE_OFF, NULL};
if (g_wifi_event_queue) xQueueSend(g_wifi_event_queue, &evt, 0);
Serial.println("[wifi] scanning/association off (radio stays up for ESP-NOW)");
} else if (argc == 2 && !strcmp(argv[1], "status")) {
if (WiFi.status() == WL_CONNECTED) {
Serial.printf("[wifi] connected to '%s', IP %s, RSSI %d dBm, channel %d\n",
WiFi.SSID().c_str(), WiFi.localIP().toString().c_str(),
(int)WiFi.RSSI(), (int)WiFi.channel());
} else {
Serial.printf("[wifi] not connected (state %d), channel %d\n", (int)g_wifi_state, (int)WiFi.channel());
}
Serial.printf("[wifi] ESP-NOW %s, sent %lu, failed %lu\n", EspNowLink::isReady() ? "ready" : "DOWN",
(unsigned long)EspNowLink::sentCount(), (unsigned long)EspNowLink::failCount());
} else {
Serial.println("wifi status connection, IP, channel, ESP-NOW health");
Serial.println("wifi join <ssid> [pass] join a network (no spaces in the SSID)");
Serial.println("wifi off stop scanning/association (radio stays on)");
}
return true;
}
} // namespace WiFiManager