BLE heartRate demo with security
Dependencies: BLE_API mbed nRF51822
Diff: main.cpp
- Revision:
- 1:52c48814da8e
- Parent:
- 0:4f367a344480
- Child:
- 2:2d9d4b271af8
--- a/main.cpp Tue Jun 02 08:09:51 2015 +0000 +++ b/main.cpp Tue Jun 02 08:14:51 2015 +0000 @@ -46,16 +46,38 @@ * heavy-weight sensor polling from the main thread. */ triggerSensorPolling = true; } +uint8_t KEY[6] = {0x01, 0x02, 0x00, 0x00, 0x00, 0x00}; + +void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t peerAddrType, const Gap::Address_t peerAddr, + Gap::addr_type_t ownAddrType, const Gap::Address_t ownAddr, + const Gap::ConnectionParams_t * pParam) +{ + printf("connected!\r\n"); +} + +void passkeyDisplayCallback(Gap::Handle_t handle, const Gap::Passkey_t passkey) +{ + uint8_t i; + + printf("Input passKey: "); + for(i = 0; i < 6; i++) { + printf("%d ", passkey[i]); + } +} + int main(void) { led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); // blink LED every second - +printf("Started\r\n"); ble.init(); + ble.initializeSecurity(true, true, Gap::IO_CAPS_DISPLAY_ONLY, NULL); + //ble.initializeSecurity(); + ble.onConnection(connectionCallback); ble.onDisconnection(disconnectionCallback); - + ble.onPasskeyDisplay(passkeyDisplayCallback); /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); @@ -70,6 +92,7 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(1000); + ble.startAdvertising(); // infinite loop