From d8fe676c657c871efe97a0ca67fbccddf05878dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Martin?= Date: Fri, 2 Oct 2026 14:32:35 +0200 Subject: [PATCH] Add Wi-Fi/TLS heap probe; limit deep+ LDF to native tests The deep+ dependency finder broke the framework's WiFi -> Network include on the device build; only the native test env needs it. The probe serial command (probe TAB) measures heap with Wi-Fi connected and one TLS connection; credentials never touch the repo. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT --- platformio.ini | 2 +- src/main.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index fbd0c01..955384d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,7 +7,6 @@ default_envs = cardputer-adv [env] extra_scripts = pre:scripts/version.py test_framework = unity -lib_ldf_mode = deep+ [env:cardputer-adv] platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.312/platform-espressif32.zip @@ -25,4 +24,5 @@ test_ignore = * ; Host-side unit tests for pure logic (no hardware). [env:native] platform = native +lib_ldf_mode = deep+ build_flags = -std=gnu++17 diff --git a/src/main.cpp b/src/main.cpp index 0c67698..681c85c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ // roro9stack firmware entry point: wires Services, Apps and the UI loop together. #include +#include +#include #include "app_manager.h" #include "apps/demo_app.h" @@ -101,6 +103,41 @@ void setup() { Serial.printf("%s %s ready, free heap %u\n", kProductName, versionString(), ESP.getFreeHeap()); } +// Dev aid (M1 step 1): heap cost of Wi-Fi and one TLS connection. Credentials come over serial only. +static void memoryProbe(const String& ssid, const String& pass) { + auto heap = [](const char* stage) { + Serial.printf("probe %-18s heap %6u min %6u largest block %6u\n", stage, ESP.getFreeHeap(), + ESP.getMinFreeHeap(), heap_caps_get_largest_free_block(MALLOC_CAP_8BIT)); + }; + heap("before wifi"); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid.c_str(), pass.c_str()); + uint32_t start = millis(); + while (WiFi.status() != WL_CONNECTED && millis() - start < 20000) delay(100); + if (WiFi.status() != WL_CONNECTED) { + Serial.printf("probe wifi failed, status %d\n", WiFi.status()); + heap("wifi failed"); + WiFi.disconnect(true); + return; + } + Serial.printf("probe wifi connected, rssi %d, ip %s\n", WiFi.RSSI(), WiFi.localIP().toString().c_str()); + heap("wifi connected"); + { + NetworkClientSecure tls; + tls.setInsecure(); // measurement only; M1 verifies certificates + if (tls.connect("irc.libera.chat", 6697)) { + heap("tls connected"); + tls.stop(); + } else { + Serial.println("probe tls connect failed"); + } + } + heap("tls closed"); + WiFi.disconnect(true); + WiFi.mode(WIFI_OFF); + heap("wifi off"); +} + // Dev aid: serial commands to drive the UI without the keyboard. static void serialCommands() { static String line; @@ -120,6 +157,10 @@ static void serialCommands() { : k == "right" ? Key::Right : k == "back" ? Key::Back : k == "home" ? Key::Home : Key::Select; if (!power->onKey(millis())) apps->handleKey(KeyEvent::of(key)); } + if (line.startsWith("probe ")) { // probe \t + int tab = line.indexOf('\t'); + if (tab > 0) memoryProbe(line.substring(6, tab), line.substring(tab + 1)); + } if (line == "sound off") settings.setBool(Setting::Sound, false); if (line == "sound on") settings.setBool(Setting::Sound, true); if (line == "short") {