Example program for BLE devices using updated Puck library.

Dependencies:   Puck mbed

Fork of location-puck by Nordic Pucks

Committer:
stiaje
Date:
Thu Jul 03 12:51:28 2014 +0000
Revision:
8:54535e2f4098
Parent:
6:306e898c274f
Child:
9:28eb877be5f8
Switch to new BLE API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cristea 0:f4fbeaabdff5 1 #include <mbed.h>
stiaje 8:54535e2f4098 2 #include "BLEDevice.h"
cristea 6:306e898c274f 3
stiaje 8:54535e2f4098 4 #define DEBUG 0
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
stiaje 8:54535e2f4098 16 * Major/Minor = 1337 / XXXX
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,
stiaje 8:54535e2f4098 25 0x13, 0x37, // the major value to differenciate a location (Our app requires 1337 as major number)
stiaje 8:54535e2f4098 26 0x13, 0x38, // the minor value to differenciate a location (Change this to differentiate location pucks)
cristea 5:8ccb1cd6694d 27 0xC8 // 2's complement of the Tx power (-56dB)
cristea 5:8ccb1cd6694d 28 };
cristea 5:8ccb1cd6694d 29
stiaje 8:54535e2f4098 30 BLEDevice ble;
cristea 5:8ccb1cd6694d 31 DigitalOut led1(LED1);
cristea 2:67d603617000 32
cristea 4:4324d5acd5d8 33 int main(void) {
cristea 6:306e898c274f 34 led1 = 1;
cristea 3:4cb285fb29e7 35
stiaje 8:54535e2f4098 36 LOG("Initializing ble beacon\n");
stiaje 8:54535e2f4098 37 ble.init();
cristea 3:4cb285fb29e7 38
stiaje 8:54535e2f4098 39 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
stiaje 8:54535e2f4098 40 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
cristea 5:8ccb1cd6694d 41 beaconPayload, sizeof(beaconPayload));
stiaje 8:54535e2f4098 42
stiaje 8:54535e2f4098 43 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
stiaje 8:54535e2f4098 44 ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
cristea 6:306e898c274f 45
stiaje 8:54535e2f4098 46 ble.startAdvertising();
cristea 6:306e898c274f 47 LOG("Starting advertising!\n");
cristea 3:4cb285fb29e7 48
cristea 3:4cb285fb29e7 49 for(;;) {
cristea 3:4cb285fb29e7 50 led1 = !led1;
cristea 3:4cb285fb29e7 51 wait(1);
cristea 0:f4fbeaabdff5 52 }
cristea 1:345039810771 53 }