|
10 | 10 | #include <NimBLEDevice.h> |
11 | 11 | #include <NimBLEBondMigration.h> |
12 | 12 |
|
13 | | -namespace NimBLE_Bond_Migration = NimBLEBondMigration; |
14 | | - |
15 | 13 | #ifndef NIMBLE_BOND_MIGRATION_MODE |
16 | | -#define NIMBLE_BOND_MIGRATION_MODE 0 |
| 14 | +#define NIMBLE_BOND_MIGRATION_MODE 1 |
17 | 15 | #endif |
18 | 16 |
|
19 | 17 | #if (NIMBLE_BOND_MIGRATION_MODE < 0) || (NIMBLE_BOND_MIGRATION_MODE > 2) |
20 | 18 | #error "NIMBLE_BOND_MIGRATION_MODE must be 0 (off), 1 (to current), or 2 (to v1)" |
21 | 19 | #endif |
22 | 20 |
|
23 | 21 | void setup() { |
| 22 | + using namespace NimBLEBondMigration; |
| 23 | + |
24 | 24 | Serial.begin(115200); |
25 | 25 | Serial.println("Starting NimBLE_Bond_Migration Demo"); |
26 | 26 |
|
| 27 | + bool success = false; |
27 | 28 | #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"); |
32 | 31 | #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); |
43 | 40 | } |
44 | 41 | } |
45 | | -#endif |
46 | 42 |
|
47 | 43 | NimBLEDevice::init("NimBLE"); |
48 | | - NimBLEDevice::setPower(3); /** +3db */ |
49 | | - |
50 | 44 | NimBLEDevice::setSecurityAuth(true, true, false); /** bonding, MITM, don't need BLE secure connections as we are using passkey pairing */ |
51 | 45 | NimBLEDevice::setSecurityPasskey(123456); |
52 | 46 | NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); /** Display only passkey */ |
53 | 47 | NimBLEServer* pServer = NimBLEDevice::createServer(); |
54 | 48 | NimBLEService* pService = pServer->createService("ABCD"); |
55 | | - NimBLECharacteristic* pNonSecureCharacteristic = pService->createCharacteristic("1234", NIMBLE_PROPERTY::READ); |
56 | 49 | NimBLECharacteristic* pSecureCharacteristic = |
57 | 50 | pService->createCharacteristic("1235", |
58 | 51 | NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN); |
59 | 52 |
|
60 | | - pNonSecureCharacteristic->setValue("Hello Non Secure BLE"); |
61 | 53 | pSecureCharacteristic->setValue("Hello Secure BLE"); |
62 | 54 |
|
63 | 55 | NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising(); |
|
0 commit comments