From 94a5526b6636601caa2b022e74f2e9c5932c9565 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Mon, 2 Nov 2026 23:15:52 +0100 Subject: [PATCH] simple_repeater: RPT_BLE_DEFAULT_OFF -- BLE console starts off, `ble on` is saved Co-Authored-By: Claude Opus 5.5 --- examples/simple_repeater/main.cpp | 42 +++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index f96ddb05..8c891194 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -459,19 +459,45 @@ bool identHandleCommand(const char* command, char* reply) { // remote CLI). State is persistent (marker file in InternalFS), so BLE stays // off even across watchdog reboots on the mast; `ble on` sent over MC wakes // it up for OTA. + // + // RPT_BLE_DEFAULT_OFF (public builds): the console starts OFF and `ble on` + // is what gets saved (marker /ble_on). Those builds carry the placeholder PIN + // 123456, and a console that is on after a fresh flash would let anyone in + // range pair with it before the owner changes the PIN. #include #define BLE_OFF_MARKER "/ble_off" + #define BLE_ON_MARKER "/ble_on" +#ifdef RPT_BLE_DEFAULT_OFF + static bool ble_enabled = false; +#else static bool ble_enabled = true; +#endif static bool ble_toggle_target = true; static unsigned long ble_toggle_at = 0; // deferred apply so the reply can go out first - static void blePersist(bool on) { - if (on) { - InternalFS.remove(BLE_OFF_MARKER); - } else { - auto f = InternalFS.open(BLE_OFF_MARKER, Adafruit_LittleFS_Namespace::FILE_O_WRITE); - if (f) { f.write((uint8_t)'1'); f.close(); } + static void bleMarker(const char* path, bool present) { + if (!present) { + InternalFS.remove(path); + return; } + auto f = InternalFS.open(path, Adafruit_LittleFS_Namespace::FILE_O_WRITE); + if (f) { f.write((uint8_t)'1'); f.close(); } + } + + static void blePersist(bool on) { +#ifdef RPT_BLE_DEFAULT_OFF + bleMarker(BLE_ON_MARKER, on); +#else + bleMarker(BLE_OFF_MARKER, !on); +#endif + } + + static bool bleSavedOn() { +#ifdef RPT_BLE_DEFAULT_OFF + return InternalFS.exists(BLE_ON_MARKER); +#else + return !InternalFS.exists(BLE_OFF_MARKER); +#endif } // CUSTOM (TeTeHacko): `blepwr` survives a reboot (marker file like `ble off`). @@ -984,8 +1010,8 @@ void setup() { Bluefruit.ScanResponse.addName(); Bluefruit.Advertising.setInterval(RPT_BLE_ADV_FAST, RPT_BLE_ADV_SLOW); Bluefruit.Advertising.setFastTimeout(RPT_BLE_ADV_FAST_SECS); - // persistent BLE state: with the marker present keep BLE dark (see `ble on|off`) - ble_enabled = !InternalFS.exists(BLE_OFF_MARKER); + // persistent BLE state (see `ble on|off` and RPT_BLE_DEFAULT_OFF) + ble_enabled = bleSavedOn(); ble_conn_tx_power = bleConnTxPowerLoad(); // `blepwr` saved value, if any if (ble_enabled) { Bluefruit.Advertising.restartOnDisconnect(true);