Skip to content

Commit 54ca7f0

Browse files
committed
Migrate local IRK value and update example.
1 parent 5fc6741 commit 54ca7f0

2 files changed

Lines changed: 231 additions & 59 deletions

File tree

examples/NimBLE_Bond_Migration/NimBLE_Bond_Migration.ino

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,46 @@
1010
#include <NimBLEDevice.h>
1111
#include <NimBLEBondMigration.h>
1212

13-
namespace NimBLE_Bond_Migration = NimBLEBondMigration;
14-
1513
#ifndef NIMBLE_BOND_MIGRATION_MODE
16-
#define NIMBLE_BOND_MIGRATION_MODE 0
14+
#define NIMBLE_BOND_MIGRATION_MODE 1
1715
#endif
1816

1917
#if (NIMBLE_BOND_MIGRATION_MODE < 0) || (NIMBLE_BOND_MIGRATION_MODE > 2)
2018
#error "NIMBLE_BOND_MIGRATION_MODE must be 0 (off), 1 (to current), or 2 (to v1)"
2119
#endif
2220

2321
void setup() {
22+
using namespace NimBLEBondMigration;
23+
2424
Serial.begin(115200);
2525
Serial.println("Starting NimBLE_Bond_Migration Demo");
2626

27+
bool success = false;
2728
#if NIMBLE_BOND_MIGRATION_MODE == 1
28-
{
29-
esp_err_t rc = NimBLE_Bond_Migration::migrateBondStoreToCurrent();
30-
Serial.printf("NimBLE_Bond_Migration to current rc=%d\n", static_cast<int>(rc));
31-
}
29+
success = migrateBondStoreToCurrent();
30+
Serial.printf("NimBLE_Bond_Migration to current %s\n", success ? "success" : "failed");
3231
#elif NIMBLE_BOND_MIGRATION_MODE == 2
33-
{
34-
esp_err_t rc = NimBLE_Bond_Migration::migrateBondStoreToV1();
35-
Serial.printf("NimBLE_Bond_Migration to v1 rc=%d\n", static_cast<int>(rc));
36-
if (rc == ESP_OK) {
37-
Serial.println("NimBLE_Bond_Migration completed to v1, upload v1 firmware to continue");
38-
while (true) {
39-
delay(1000);
40-
}
41-
} else {
42-
Serial.println("NimBLE_Bond_Migration to v1 failed");
32+
success = migrateBondStoreToV1();
33+
Serial.printf("NimBLE_Bond_Migration to v1 %s\n", success ? "success" : "failed");
34+
#endif
35+
36+
if (success) {
37+
Serial.println("NimBLE_Bond_Migration completed, upload target firmware to continue");
38+
while (true) {
39+
delay(1000);
4340
}
4441
}
45-
#endif
4642

4743
NimBLEDevice::init("NimBLE");
48-
NimBLEDevice::setPower(3); /** +3db */
49-
5044
NimBLEDevice::setSecurityAuth(true, true, false); /** bonding, MITM, don't need BLE secure connections as we are using passkey pairing */
5145
NimBLEDevice::setSecurityPasskey(123456);
5246
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); /** Display only passkey */
5347
NimBLEServer* pServer = NimBLEDevice::createServer();
5448
NimBLEService* pService = pServer->createService("ABCD");
55-
NimBLECharacteristic* pNonSecureCharacteristic = pService->createCharacteristic("1234", NIMBLE_PROPERTY::READ);
5649
NimBLECharacteristic* pSecureCharacteristic =
5750
pService->createCharacteristic("1235",
5851
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN);
5952

60-
pNonSecureCharacteristic->setValue("Hello Non Secure BLE");
6153
pSecureCharacteristic->setValue("Hello Secure BLE");
6254

6355
NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();

0 commit comments

Comments
 (0)