diff --git a/src/main.cpp b/src/main.cpp index db908a5eb..544040ac0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -340,6 +340,9 @@ class ButtonThread : public OSThread { #ifndef NO_ESP32 clearNVS(); +#endif +#ifdef NRF52_SERIES + clearBonds(); #endif } diff --git a/src/main.h b/src/main.h index 2c90f34e3..2d93caebb 100644 --- a/src/main.h +++ b/src/main.h @@ -27,4 +27,4 @@ extern uint32_t shutdownAtMsec; // This will supress the current delay and instead try to run ASAP. extern bool runASAP; -void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); +void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), clearBonds(); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d7fefc88f..9647c7091 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -26,6 +26,11 @@ #include #endif +#ifdef NRF52_SERIES +#include +#include +#endif + NodeDB nodeDB; // we have plenty of ram so statically alloc this tempbuf (for now) @@ -90,6 +95,16 @@ bool NodeDB::resetRadioConfig() #ifndef NO_ESP32 // This will erase what's in NVS including ssl keys, persistant variables and ble pairing nvs_flash_erase(); +#endif +#ifdef NRF52_SERIES + Bluefruit.begin(); + + DEBUG_MSG("Clearing bluetooth bonds!\n"); + bond_print_list(BLE_GAP_ROLE_PERIPH); + bond_print_list(BLE_GAP_ROLE_CENTRAL); + + Bluefruit.Periph.clearBonds(); + Bluefruit.Central.clearBonds(); #endif didFactoryReset = true; } diff --git a/src/nrf52/NRF52Bluetooth.cpp b/src/nrf52/NRF52Bluetooth.cpp index 41e7fef29..e505e2104 100644 --- a/src/nrf52/NRF52Bluetooth.cpp +++ b/src/nrf52/NRF52Bluetooth.cpp @@ -5,6 +5,7 @@ #include "mesh/PhoneAPI.h" #include "mesh/mesh-pb-constants.h" #include +#include static BLEService meshBleService = BLEService(BLEUuid(MESH_SERVICE_UUID_16)); static BLECharacteristic fromNum = BLECharacteristic(BLEUuid(FROMNUM_UUID_16)); @@ -266,3 +267,13 @@ void updateBatteryLevel(uint8_t level) { blebas.write(level); } + +void NRF52Bluetooth::clearBonds() +{ + DEBUG_MSG("Clearing bluetooth bonds!\n"); + bond_print_list(BLE_GAP_ROLE_PERIPH); + bond_print_list(BLE_GAP_ROLE_CENTRAL); + + Bluefruit.Periph.clearBonds(); + Bluefruit.Central.clearBonds(); +} \ No newline at end of file diff --git a/src/nrf52/NRF52Bluetooth.h b/src/nrf52/NRF52Bluetooth.h index a10e07aba..d072cdfe7 100644 --- a/src/nrf52/NRF52Bluetooth.h +++ b/src/nrf52/NRF52Bluetooth.h @@ -5,5 +5,6 @@ class NRF52Bluetooth public: void setup(); void shutdown(); + void clearBonds(); }; diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index 88166e4fa..bcf354024 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -75,7 +75,7 @@ void setBluetoothEnable(bool on) else { nrf52Bluetooth = new NRF52Bluetooth(); nrf52Bluetooth->setup(); - + // We delay brownout init until after BLE because BLE starts soft device initBrownout(); } @@ -185,4 +185,12 @@ void cpuDeepSleep(uint64_t msecToWake) delay(5000); DEBUG_MSG("."); } +} + +void clearBonds() { + if (!nrf52Bluetooth) { + nrf52Bluetooth = new NRF52Bluetooth(); + nrf52Bluetooth->setup(); + } + nrf52Bluetooth->clearBonds(); } \ No newline at end of file