Bluetooth Low Energy (a.k.a Bluetooth LE, BTLE, Bluetooth Smart)

GattClient read characteristic value

04 Jan 2016

Hello. Anybody knows how to read or write characterstic value ?

05 Jan 2016

https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_LEDBlinker/file/507318f2afda/main.cpp this works works for me. Some places are not obvious, but it is possible to understand. There are two key functions

 ble.gattClient().onDataRead(triggerToggledWrite);
 ble.gattClient().onDataWrite(triggerRead);

and the functions

void triggerToggledWrite(const GattReadCallbackParams *response) {
    if (response->handle == ledCharacteristic.getValueHandle()) {
#if DUMP_READ_DATA
        printf("triggerToggledWrite: handle %u, offset %u, len %u\r\n", response->handle, response->offset, response->len);
        for (unsigned index = 0; index < response->len; index++) {
            printf("%c[%02x]", response->data[index], response->data[index]);
        }
        printf("\r\n");
#endif
 
        uint8_t toggledValue = response->data[0] ^ 0x1;
        ledCharacteristic.write(1, &toggledValue);
    }
}
 
void triggerRead(const GattWriteCallbackParams *response) {
    if (response->handle == ledCharacteristic.getValueHandle()) {
        ledCharacteristic.read();
    }
}

thanks to all for helping

05 Jan 2016
01 Mar 2017