Locator beacon firmware

Dependencies:   BLE_API mbed nRF51822

Fork of WeatherStation by Weather man

Committer:
sycorax
Date:
Sat Apr 29 16:33:11 2017 +0000
Revision:
9:dd7ba1fdae47
Parent:
8:2aa1fc734e13
NON CONNECTABLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sycorax 8:2aa1fc734e13 1
PostaL 0:7f951f57dbd2 2
PostaL 0:7f951f57dbd2 3 #include "mbed.h"
PostaL 0:7f951f57dbd2 4 #include "BLE.h"
PostaL 2:654ee4b3950f 5 #include "BatteryService.h"
sycorax 7:8fa805941074 6 #include "LocatorService.h"
sycorax 7:8fa805941074 7
PostaL 4:fddb2d7c7c61 8
PostaL 4:fddb2d7c7c61 9 BLE ble;
sycorax 8:2aa1fc734e13 10
PostaL 5:fe4888cc60cc 11
sycorax 8:2aa1fc734e13 12 const static char DEVICE_NAME[] = "Locator RedBear";
PostaL 3:b6d2c5195055 13
PostaL 3:b6d2c5195055 14 static const uint16_t serviceList[] = {
sycorax 7:8fa805941074 15 0x1821
PostaL 2:654ee4b3950f 16 };
PostaL 3:b6d2c5195055 17
PostaL 0:7f951f57dbd2 18 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
PostaL 0:7f951f57dbd2 19 {
PostaL 4:fddb2d7c7c61 20 /* Restart Advertising on disconnection*/
PostaL 0:7f951f57dbd2 21 ble.gap().startAdvertising();
PostaL 0:7f951f57dbd2 22 }
PostaL 0:7f951f57dbd2 23
PostaL 4:fddb2d7c7c61 24
PostaL 0:7f951f57dbd2 25 int main(void)
PostaL 0:7f951f57dbd2 26 {
PostaL 6:dc269cf4f951 27 printf("Starting locator\n");
PostaL 3:b6d2c5195055 28
PostaL 0:7f951f57dbd2 29 ble.init();
PostaL 0:7f951f57dbd2 30 ble.gap().onDisconnection(disconnectionCallback);
PostaL 0:7f951f57dbd2 31
PostaL 2:654ee4b3950f 32 /* Setup weather service. */
sycorax 7:8fa805941074 33 LocatorService locatorService(ble);
PostaL 6:dc269cf4f951 34 +
PostaL 0:7f951f57dbd2 35 /* setup advertising */
PostaL 0:7f951f57dbd2 36 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
PostaL 3:b6d2c5195055 37 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)serviceList, sizeof(serviceList));
PostaL 0:7f951f57dbd2 38 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
sycorax 9:dd7ba1fdae47 39 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
sycorax 9:dd7ba1fdae47 40 ble.gap().setAdvertisingInterval(100); /* 1000ms */
PostaL 0:7f951f57dbd2 41 ble.gap().startAdvertising();
PostaL 6:dc269cf4f951 42
PostaL 6:dc269cf4f951 43 while (true) {
PostaL 6:dc269cf4f951 44 ble.waitForEvent();
PostaL 0:7f951f57dbd2 45 }
PostaL 0:7f951f57dbd2 46 }