Locator beacon firmware
Dependencies: BLE_API mbed nRF51822
Fork of WeatherStation by
main.cpp
- Committer:
- PostaL
- Date:
- 2017-04-29
- Revision:
- 6:dc269cf4f951
- Parent:
- 5:fe4888cc60cc
- Child:
- 7:8fa805941074
File content as of revision 6:dc269cf4f951:
#define I2C_SDA p3 #define I2C_SCL p4 #define BAT_SENSE p1 #include "mbed.h" #include "BLE.h" #include "BatteryService.h" BLE ble; PwmOut light(LED1); AnalogIn battery(BAT_SENSE); const static char DEVICE_NAME[] = "Locator"; static const uint16_t serviceList[] = { GattService::UUID_BATTERY_SERVICE, 0x1821 }; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { /* Restart Advertising on disconnection*/ ble.gap().startAdvertising(); } int main(void) { printf("Starting locator\n"); light = 1; ble.init(); ble.gap().onDisconnection(disconnectionCallback); /* Setup weather service. */ BatteryService batteryService(ble, 0); + /* setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)serviceList, sizeof(serviceList)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(500); /* 1000ms */ ble.gap().startAdvertising(); while (true) { ble.waitForEvent(); } }