Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_Example by
Revision 27:ed42554cf870, committed 2017-06-10
- Comitter:
- andreydung
- Date:
- Sat Jun 10 01:03:26 2017 +0000
- Parent:
- 26:b3e90d7672f8
- Child:
- 28:382c630bae02
- Commit message:
- it works!!
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jun 10 00:51:10 2017 +0000
+++ b/main.cpp Sat Jun 10 01:03:26 2017 +0000
@@ -1,13 +1,13 @@
#include "mbed.h"
#include "ble/BLE.h"
-DigitalOut led(LED1, 1);
+DigitalOut led(P0_19, 1);
uint16_t customServiceUUID = 0xA000;
uint16_t readCharUUID = 0xA001;
uint16_t writeCharUUID = 0xA002;
-const static char DEVICE_NAME[] = "timesync1"; // change this
-static const uint16_t uuid16_list[] = {0xA000}; //Custom UUID, FFFF is reserved for development
+const static char DEVICE_NAME[] = "ChangeMe!!"; // change this
+static const uint16_t uuid16_list[] = {0xFFFF}; //Custom UUID, FFFF is reserved for development
/* Set Up custom Characteristics */
static uint8_t readValue[10] = {0};
@@ -20,23 +20,27 @@
GattCharacteristic *characteristics[] = {&readChar, &writeChar};
GattService customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
+
+/*
+ * Restart advertising when phone app disconnects
+*/
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *)
{
+ led = 1; // just in case
BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
}
+/*
+ * Handle writes to writeCharacteristic
+*/
void writeCharCallback(const GattWriteCallbackParams *params)
{
/* Check to see what characteristic was written, by handle */
if(params->handle == writeChar.getValueHandle()) {
- /* toggle LED if only 1 byte is written */
- if(params->len == 1) {
- led = 1;
- wait(0.5);
- led = 0;
- }
- /* Update the readChar with the value of writeChar */
- BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), params->data, params->len);
+ // since LED is pullup mode
+ led = 0;
+ wait(1.0);
+ led = 1;
}
}
/*
