Jelle Bakker
/
mbed-os-example-ble-LED
working adverticement
Fork of mbed-os-example-ble-LED by
Diff: source/main.cpp
- Revision:
- 48:684526d07191
- Parent:
- 44:df8adb3bc797
--- a/source/main.cpp Thu Nov 23 14:00:24 2017 +0000 +++ b/source/main.cpp Tue Dec 05 15:32:44 2017 +0000 @@ -22,22 +22,25 @@ DigitalOut alivenessLED(LED1, 0); DigitalOut actuatedLED(LED2, 0); -const static char DEVICE_NAME[] = "LED"; +const static char DEVICE_NAME[] = "Jelle"; +uint8_t NUMBER = 3; +uint8_t COUNTER = 0; static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID}; static EventQueue eventQueue(/* event count */ 10 * EVENTS_EVENT_SIZE); LEDService *ledServicePtr; - + void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { (void) params; BLE::Instance().gap().startAdvertising(); } -void blinkCallback(void) +void blinkCallback() { alivenessLED = !alivenessLED; /* Do blinky on LED1 to indicate system aliveness. */ + } /** @@ -49,6 +52,20 @@ void onDataWrittenCallback(const GattWriteCallbackParams *params) { if ((params->handle == ledServicePtr->getValueHandle()) && (params->len == 1)) { actuatedLED = *(params->data); + printf("Led state %d\n\r",*(params->data)); + printf("NUMBER before change %d\n\r",NUMBER); + printf("counter before change %d\n\r",COUNTER); + COUNTER++; + NUMBER = *(params->data); + + BLE &ble = BLE::Instance(); + + ble.gap().updateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA , &NUMBER, sizeof(NUMBER)); + ble.gap().updateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA , &COUNTER, sizeof(COUNTER)); + + printf("NUMBER before change %d\n\r",NUMBER); + printf("counter before change %d\n\r",COUNTER); + } } @@ -66,11 +83,15 @@ Gap::AddressType_t addr_type; Gap::Address_t address; BLE::Instance().gap().getAddress(&addr_type, address); - printf("DEVICE MAC ADDRESS: "); + printf("TEST1\n\r"); + + printf("DEVICE MAC ADDRESS asdfasdf: "); for (int i = 5; i >= 1; i--){ printf("%02x:", address[i]); } printf("%02x\r\n", address[0]); + + } /** @@ -102,6 +123,10 @@ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA , &NUMBER, sizeof(NUMBER)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA , &COUNTER, sizeof(COUNTER)); + + ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms. */ ble.gap().startAdvertising();