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 12:27:54 2014 +0000
Revision:
6:306e898c274f
Parent:
5:8ccb1cd6694d
Child:
8:54535e2f4098
Add correct Apple iBeacon UUID

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cristea 0:f4fbeaabdff5 1 #include <mbed.h>
cristea 6:306e898c274f 2 #include "nRF51822n.h"
cristea 6:306e898c274f 3
cristea 3:4cb285fb29e7 4 #define DEBUG 1
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 6:306e898c274f 20 0x00, 0x4C, // 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 6:306e898c274f 25 0x13, 0x37, // the major value to differenciate a location
cristea 6:306e898c274f 26 0x13, 0x38, // 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 2:67d603617000 32
cristea 3:4cb285fb29e7 33 GapAdvertisingData advData;
cristea 3:4cb285fb29e7 34 GapAdvertisingData scanResponse;
cristea 5:8ccb1cd6694d 35 GapAdvertisingParams advParams(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
cristea 2:67d603617000 36
cristea 4:4324d5acd5d8 37 int main(void) {
cristea 6:306e898c274f 38 led1 = 1;
cristea 3:4cb285fb29e7 39
cristea 6:306e898c274f 40 LOG("Starting init\n");
cristea 3:4cb285fb29e7 41 nrf.init();
cristea 3:4cb285fb29e7 42 nrf.reset();
cristea 6:306e898c274f 43 LOG("Init and reset nrf done\n");
cristea 3:4cb285fb29e7 44
cristea 3:4cb285fb29e7 45 advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
cristea 5:8ccb1cd6694d 46 advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
cristea 5:8ccb1cd6694d 47 beaconPayload, sizeof(beaconPayload));
cristea 3:4cb285fb29e7 48 advData.addAppearance(GapAdvertisingData::UNKNOWN);
cristea 6:306e898c274f 49
cristea 4:4324d5acd5d8 50 nrf.getGap().setAdvertisingData(advData, scanResponse);
cristea 6:306e898c274f 51 LOG("Set advertising data done!\n");
cristea 3:4cb285fb29e7 52
cristea 3:4cb285fb29e7 53 nrf.getGap().startAdvertising(advParams);
cristea 6:306e898c274f 54 LOG("Starting advertising!\n");
cristea 3:4cb285fb29e7 55
cristea 3:4cb285fb29e7 56 for(;;) {
cristea 3:4cb285fb29e7 57 led1 = !led1;
cristea 3:4cb285fb29e7 58 wait(1);
cristea 0:f4fbeaabdff5 59 }
cristea 1:345039810771 60 }