PUBLISH HelloBlue
Dependencies: BLE_API mbed nRF51822
Fork of HelloBlue by
main.cpp@0:a89b73f690c1, 2015-01-28 (annotated)
- Committer:
- waynek
- Date:
- Wed Jan 28 17:35:34 2015 +0000
- Revision:
- 0:a89b73f690c1
- Child:
- 1:b84d6e0b404e
init Hello world minimal BLE app to test FOTA
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
waynek | 0:a89b73f690c1 | 1 | #include "mbed.h" |
waynek | 0:a89b73f690c1 | 2 | #include "BLEDevice.h" |
waynek | 0:a89b73f690c1 | 3 | |
waynek | 0:a89b73f690c1 | 4 | #include "DFUService.h" |
waynek | 0:a89b73f690c1 | 5 | |
waynek | 0:a89b73f690c1 | 6 | const static char DEVICE_NAME[] = "HelloBlue"; |
waynek | 0:a89b73f690c1 | 7 | |
waynek | 0:a89b73f690c1 | 8 | BLEDevice ble; |
waynek | 0:a89b73f690c1 | 9 | |
waynek | 0:a89b73f690c1 | 10 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
waynek | 0:a89b73f690c1 | 11 | { |
waynek | 0:a89b73f690c1 | 12 | ble.startAdvertising(); // restart advertising |
waynek | 0:a89b73f690c1 | 13 | } |
waynek | 0:a89b73f690c1 | 14 | |
waynek | 0:a89b73f690c1 | 15 | int main(void) |
waynek | 0:a89b73f690c1 | 16 | { |
waynek | 0:a89b73f690c1 | 17 | ble.init(); |
waynek | 0:a89b73f690c1 | 18 | ble.onDisconnection(disconnectionCallback); |
waynek | 0:a89b73f690c1 | 19 | |
waynek | 0:a89b73f690c1 | 20 | DFUService dfu(ble); |
waynek | 0:a89b73f690c1 | 21 | |
waynek | 0:a89b73f690c1 | 22 | /* Setup advertising. */ |
waynek | 0:a89b73f690c1 | 23 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
waynek | 0:a89b73f690c1 | 24 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
waynek | 0:a89b73f690c1 | 25 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
waynek | 0:a89b73f690c1 | 26 | ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000)); |
waynek | 0:a89b73f690c1 | 27 | ble.startAdvertising(); |
waynek | 0:a89b73f690c1 | 28 | |
waynek | 0:a89b73f690c1 | 29 | while (true) { |
waynek | 0:a89b73f690c1 | 30 | ble.waitForEvent(); |
waynek | 0:a89b73f690c1 | 31 | } |
waynek | 0:a89b73f690c1 | 32 | } |
waynek | 0:a89b73f690c1 | 33 |