I am facing some issue while reading data from bluetooth peripheral. We have a bluetooth device with the following gatt details.
<service uuid="service id" advertise="true">
<description>XXXX service</description>
<characteristic uuid="characteristic id" id="xgatt_data">
<description>Data</description>
<properties write="true" indicate="true" />
<value variable_length="true" length="20" type="user" />
</characteristic>
</service>
What i am doing is
I am able to connect to the device. and i can send commands(data) to peripheral also. Once we send any command to device it will send some data in response. I can see logs at the device, it is sending some data back once it receive any command. But in my iOS device i am not able to read the data by using either notification or normal read functions. What i am missing here?
Notifications and Indiciations are two different things: If you enable indications you won't receive notifications, and if you enable indications then the application sending the indications expects a response to every sent indiciation (from the application layer).
Also your permissions seem not quite right: the xgatt_data characteristic does not necessarily need the "Write" permission, unless you intend to let a client change it's value. It requires the "Read" permission if you want to read data from the notification, other than simply being notified that it was received.
To enable notifications a client characteristic configuration descriptor is required (UUID 00002901-..) within the xgatt_data characteristic. This CCCD requires "Read+Write" permissions to enable notifications/indications (some work without read permission, some dont).
And finally make sure that your device never agrees to an Attribute MTU of less than the size of your notification, it will not be received by the peripheral if it doesnt fit into a single package. If data length extensions are used, dont enable notifications until after DLE was negotiated, or keep the notification value size below your device's original minimum attribute MTU.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With