Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LBLECentral read/write characteristic occasionally fails #82

Closed
pablosun opened this issue Jan 9, 2018 · 2 comments · Fixed by #84
Closed

LBLECentral read/write characteristic occasionally fails #82

pablosun opened this issue Jan 9, 2018 · 2 comments · Fixed by #84
Assignees
Labels

Comments

@pablosun
Copy link
Contributor

pablosun commented Jan 9, 2018

In the following code snippet, the read operation succeeds, while the write operation fails - even the UUID attribute is indeed having a WRITABLE permission.

     char a = client.readCharacteristicInt("00010203-0405-0607-0809-0A0B0C0D2B11"); 
     // write  
     int mm = client.writeCharacteristicInt("00010203-0405-0607-0809-0A0B0C0D2B11",6);
@pablosun pablosun added the bug label Jan 9, 2018
@pablosun pablosun self-assigned this Jan 9, 2018
@pablosun
Copy link
Contributor Author

pablosun commented Jan 9, 2018

The symptom here is that LBLEClient::writeCharacteristic may send the BLE write request with incorrect handle when the services have both 16-bit UUID and 128-bit UUID services.

This issue does not happen when there are only 16-bit UUIDs, e.g. the Example sketch.

@pablosun
Copy link
Contributor Author

pablosun commented Jan 9, 2018

The root cause here is that LBLEClient stores all the scanned UUID and corresponding value handle in a std::map table, which relies on less(operator <) comparison to properly order the elements.

However, the implementation of LBLEUuid does not return proper ordering when comparing 16-bit UUID with 128-bit UUID, and vice versa. Therefore writeCharacteristic may retrieve wrong value handle when read/write the attribute.

@pablosun pablosun added this to the BLE Fixes 2018 Jan milestone Jan 9, 2018
@pablosun pablosun mentioned this issue Jan 10, 2018
pablosun added a commit that referenced this issue Jan 10, 2018
Fix #80 by handling CCCD for all characteristics

Some BLE implementation requires the presence of CCCD(Client Characteristic Configuration Descriptor) to propery "subscribe" to notifications and indications.

By default we allow notification/indication of all characteristics, so we add CCCD to all characteristics and corresponding read/write callbacks.

Note that this increases the callback table usage, since 1 characteristics now requires 2 callback functions. Therefore, the number of statically allocated callback table is doubled from 30 to 60 entires.

* Fix #82 by fixing UUID comparison between 16-bit and 128-bit UUIDs

In some cases where both 16-bit UUID and 128-bit UUID characteristics present, the implementation of UUID comparison is incorrect. This leads to incorrect retrieval of the characteristic GATT database handles. Therefore the remote peripheral device won't be able to update the correct characteristics. 

* Re-format files

* TxPower should be signed

* Add LBLE keywords

* Fix build warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant