Example program for BLE devices using updated Puck library.

Dependencies:   Puck mbed

Fork of location-puck by Nordic Pucks

Committer:
cristea
Date:
Thu Jun 19 10:40:25 2014 +0000
Revision:
5:8ccb1cd6694d
Parent:
4:4324d5acd5d8
Child:
6:306e898c274f
Add iBeacon payload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cristea 0:f4fbeaabdff5 1 #include <mbed.h>
cristea 4:4324d5acd5d8 2 #include <nRF51822n.h>
cristea 3:4cb285fb29e7 3 #define DEBUG 1
cristea 0:f4fbeaabdff5 4
cristea 3:4cb285fb29e7 5 #ifdef DEBUG
cristea 4:4324d5acd5d8 6 Serial pc(USBTX, USBRX);
cristea 3:4cb285fb29e7 7 #define LOG(args...) pc.printf(args)
cristea 3:4cb285fb29e7 8 #else
cristea 3:4cb285fb29e7 9 #define LOG(args...)
cristea 3:4cb285fb29e7 10 #endif
cristea 0:f4fbeaabdff5 11
cristea 5:8ccb1cd6694d 12 /*
cristea 5:8ccb1cd6694d 13 * The Beacon payload (encapsulated within the MSD advertising data structure)
cristea 5:8ccb1cd6694d 14 * has the following composition:
cristea 5:8ccb1cd6694d 15 * 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
cristea 5:8ccb1cd6694d 16 * Major/Minor = 0000 / 0000
cristea 5:8ccb1cd6694d 17 * Tx Power = C8
cristea 5:8ccb1cd6694d 18 */
cristea 5:8ccb1cd6694d 19 const static uint8_t beaconPayload[] = {
cristea 5:8ccb1cd6694d 20 0x4C, 0x00, // Company identifier code (0x004C == Apple)
cristea 5:8ccb1cd6694d 21 0x02, // ID
cristea 5:8ccb1cd6694d 22 0x15, // length of the remaining payload
cristea 5:8ccb1cd6694d 23 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // UUID
cristea 5:8ccb1cd6694d 24 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
cristea 5:8ccb1cd6694d 25 0x00, 0x00, // the major value to differenciate a location
cristea 5:8ccb1cd6694d 26 0x00, 0x00, // the minor value to differenciate a location
cristea 5:8ccb1cd6694d 27 0xC8 // 2's complement of the Tx power (-56dB)
cristea 5:8ccb1cd6694d 28 };
cristea 5:8ccb1cd6694d 29
cristea 3:4cb285fb29e7 30 nRF51822n nrf;
cristea 5:8ccb1cd6694d 31 DigitalOut led1(LED1);
cristea 5:8ccb1cd6694d 32 DigitalOut advertisingStateLed(LED2);
cristea 2:67d603617000 33
cristea 3:4cb285fb29e7 34 GapAdvertisingData advData;
cristea 3:4cb285fb29e7 35 GapAdvertisingData scanResponse;
cristea 5:8ccb1cd6694d 36 GapAdvertisingParams advParams(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
cristea 2:67d603617000 37
cristea 4:4324d5acd5d8 38 int main(void) {
cristea 3:4cb285fb29e7 39
cristea 3:4cb285fb29e7 40 nrf.init();
cristea 3:4cb285fb29e7 41 nrf.reset();
cristea 3:4cb285fb29e7 42
cristea 3:4cb285fb29e7 43 advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
cristea 5:8ccb1cd6694d 44 advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
cristea 5:8ccb1cd6694d 45 beaconPayload, sizeof(beaconPayload));
cristea 3:4cb285fb29e7 46 advData.addAppearance(GapAdvertisingData::UNKNOWN);
cristea 4:4324d5acd5d8 47 nrf.getGap().setAdvertisingData(advData, scanResponse);
cristea 3:4cb285fb29e7 48
cristea 3:4cb285fb29e7 49 nrf.getGap().startAdvertising(advParams);
cristea 3:4cb285fb29e7 50
cristea 3:4cb285fb29e7 51 for(;;) {
cristea 3:4cb285fb29e7 52 led1 = !led1;
cristea 3:4cb285fb29e7 53 wait(1);
cristea 0:f4fbeaabdff5 54 }
cristea 1:345039810771 55 }