Locator beacon firmware
Dependencies: BLE_API mbed nRF51822
Fork of WeatherStation by
main.cpp@7:8fa805941074, 2017-04-29 (annotated)
- Committer:
- sycorax
- Date:
- Sat Apr 29 15:02:20 2017 +0000
- Revision:
- 7:8fa805941074
- Parent:
- 6:dc269cf4f951
- Child:
- 8:2aa1fc734e13
Add Indoor Positioning System Service
Who changed what in which revision?
User | Revision | Line number | New 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" |
sycorax | 7:8fa805941074 | 8 | #include "LocatorService.h" |
sycorax | 7:8fa805941074 | 9 | |
PostaL | 4:fddb2d7c7c61 | 10 | |
PostaL | 4:fddb2d7c7c61 | 11 | BLE ble; |
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, |
sycorax | 7:8fa805941074 | 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 | 0:7f951f57dbd2 | 33 | ble.init(); |
PostaL | 0:7f951f57dbd2 | 34 | ble.gap().onDisconnection(disconnectionCallback); |
PostaL | 0:7f951f57dbd2 | 35 | |
PostaL | 2:654ee4b3950f | 36 | /* Setup weather service. */ |
sycorax | 7:8fa805941074 | 37 | LocatorService locatorService(ble); |
PostaL | 6:dc269cf4f951 | 38 | + |
PostaL | 0:7f951f57dbd2 | 39 | /* setup advertising */ |
PostaL | 0:7f951f57dbd2 | 40 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
PostaL | 3:b6d2c5195055 | 41 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)serviceList, sizeof(serviceList)); |
PostaL | 0:7f951f57dbd2 | 42 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
PostaL | 0:7f951f57dbd2 | 43 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
sycorax | 7:8fa805941074 | 44 | ble.gap().setAdvertisingInterval(1000); /* 1000ms */ |
PostaL | 0:7f951f57dbd2 | 45 | ble.gap().startAdvertising(); |
PostaL | 6:dc269cf4f951 | 46 | |
PostaL | 6:dc269cf4f951 | 47 | while (true) { |
PostaL | 6:dc269cf4f951 | 48 | ble.waitForEvent(); |
PostaL | 0:7f951f57dbd2 | 49 | } |
PostaL | 0:7f951f57dbd2 | 50 | } |