simple_repeater: RPT_BLE_DEFAULT_OFF -- BLE console starts off, ble on is saved

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-02 23:15:52 +01:00
1 parent ea1cf46cf4
commit 94a5526b66
1 file changed
+34 -8
+34 -8
View File
@@ -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 <InternalFileSystem.h>
#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);