Locator beacon firmware

Dependencies:   BLE_API mbed nRF51822

Fork of WeatherStation by Weather man

Committer:
PostaL
Date:
Sat Apr 29 14:27:31 2017 +0000
Revision:
6:dc269cf4f951
Parent:
5:fe4888cc60cc
Child:
7:8fa805941074
added service

Who changed what in which revision?

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