From 45379ad742787245cadf59ed4b944ea55b0e6bc0 Mon Sep 17 00:00:00 2001 From: agessaman Date: Mon, 3 Aug 2026 11:27:36 -0700 Subject: [PATCH] fix(build): restore nRF52 builds broken by observer-only dependencies Three fork-introduced dependencies had leaked into non-ESP32 builds, breaking every nRF52 and RP2040 target since 7e4f75c9 (2026-04-10): - The `memory` CLI command called ESP.getFreeHeap()/heap_caps_* unguarded from shared CommonCLI.cpp. ESP32 output is unchanged; other platforms now report newlib arena stats, omitting min-ever-free and largest-free-block rather than substituting numbers that mean something different. - The vendored PsychicMqttClient (ESP-IDF esp-mqtt) was pulled in by the LDF on nRF52; nrf52_base now lib_ignores it, matching how RP2040 variants ignore BLE. - JWTHelper.cpp and MQTTMessageBuilder.cpp are excluded in arduino_base, but 22 variants re-glob helpers/*.cpp after inheriting it, which undoes the exclusion. Guarding the file contents on WITH_MQTT_BRIDGE is robust against any variant's filter, and matches helpers/esp32/WebConfigServer.cpp. Verified: RAK4631 repeater + room server, Heltec T114, T1000-E, Wio WM1110, Xiao nRF52 and ThinkNode M1 all build. ESP32 observer builds are byte-identical to before (RAM and flash), and the native suite stays at 267/267. RP2040 still fails separately: four boards declare the pre-force_ap startOTAUpdate signature. Not addressed here. --- platformio.ini | 2 ++ src/helpers/CommonCLI.cpp | 13 +++++++++++++ src/helpers/JWTHelper.cpp | 6 ++++++ src/helpers/MQTTMessageBuilder.cpp | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/platformio.ini b/platformio.ini index 763f0ead3..c320db6dc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -104,6 +104,8 @@ build_flags = ${arduino_base.build_flags} lib_deps = ${arduino_base.lib_deps} https://github.com/oltaco/CustomLFS#0.2.2 +; Vendored ESP-IDF MQTT client; the LDF otherwise pulls it into non-ESP builds. +lib_ignore = PsychicMqttClient ; ----------------- RP2040 --------------------- [rp2040_base] diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index cecec0647..df1514d7b 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -15,6 +15,8 @@ #include #include #include +#else +#include // mallinfo() for the `memory` command on nRF52/RP2040 #endif #ifdef WITH_MQTT_BRIDGE #include "bridges/MQTTBridge.h" @@ -842,6 +844,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re strcpy(reply, "ERR: clock cannot go backwards"); } } else if (memcmp(command, "memory", 6) == 0) { +#ifdef ESP_PLATFORM sprintf(reply, "Free: %d, Min: %d, Max: %d, Queue: %d, IntFree: %d, IntMax: %d, PSRAM: %d/%d", ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap(), _callbacks->getQueueSize(), @@ -849,6 +852,16 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re (int)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL), (int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM), (int)heap_caps_get_total_size(MALLOC_CAP_SPIRAM)); +#else + // newlib arena stats — the portable equivalent on nRF52/RP2040. There is + // no min-ever-free or largest-free-block counterpart, so those fields are + // left out rather than filled with numbers that mean something different. + // Frags is the free-chunk count, the closest available fragmentation hint. + struct mallinfo mi = mallinfo(); + sprintf(reply, "Free: %d, Used: %d, Arena: %d, Frags: %d, Queue: %d", + (int)mi.fordblks, (int)mi.uordblks, (int)mi.arena, (int)mi.ordblks, + _callbacks->getQueueSize()); +#endif } else if (memcmp(command, "start ota", 9) == 0) { // Manual OTA: bring up the ElegantOTA web UI for a hand-uploaded binary. // Plain "start ota" serves on the station IP when joined to WiFi, else diff --git a/src/helpers/JWTHelper.cpp b/src/helpers/JWTHelper.cpp index 0b73d87ec..4e411e12b 100644 --- a/src/helpers/JWTHelper.cpp +++ b/src/helpers/JWTHelper.cpp @@ -1,3 +1,8 @@ +// MQTT-only translation unit. 22 variants re-glob helpers/*.cpp past the +// arduino_base exclusion, so the contents are guarded here rather than in +// the build filter — same idiom as helpers/esp32/WebConfigServer.cpp. +#ifdef WITH_MQTT_BRIDGE + #include "JWTHelper.h" #include #include @@ -196,3 +201,4 @@ size_t JWTHelper::createPayload( return base64UrlEncode((uint8_t*)jsonBuffer, len, output, outputSize); } +#endif // WITH_MQTT_BRIDGE diff --git a/src/helpers/MQTTMessageBuilder.cpp b/src/helpers/MQTTMessageBuilder.cpp index 743ab393a..3ec13277e 100644 --- a/src/helpers/MQTTMessageBuilder.cpp +++ b/src/helpers/MQTTMessageBuilder.cpp @@ -1,3 +1,8 @@ +// MQTT-only translation unit. 22 variants re-glob helpers/*.cpp past the +// arduino_base exclusion, so the contents are guarded here rather than in +// the build filter — same idiom as helpers/esp32/WebConfigServer.cpp. +#ifdef WITH_MQTT_BRIDGE + #include "MQTTMessageBuilder.h" #include "MQTTPayloadBuilder.h" #include @@ -361,3 +366,5 @@ void MQTTMessageBuilder::packetToHex(mesh::Packet* packet, char* hex, size_t hex // Convert serialized packet to hex bytesToHex(raw_buf, raw_len, hex, hex_size); } + +#endif // WITH_MQTT_BRIDGE