Locator beacon firmware

Dependencies:   BLE_API mbed nRF51822

Fork of WeatherStation by Weather man

Committer:
sycorax
Date:
Sat Apr 29 15:43:33 2017 +0000
Revision:
8:2aa1fc734e13
Parent:
7:8fa805941074
Child:
9:dd7ba1fdae47
IPS

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