Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth data update notifications not getting fired

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

  • Search for the peripheral who is having "service id"
  • Connect to the peripheral once found and keeping a strong reference to it.
  • After connecting setting delegate and searching for all the services it providing
  • loop all services and scan for characteristics once we discover service
  • after i found desired characteristic i am enabling notification
  • On button click i am writing data to characteristic

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?

like image 719
naresh Avatar asked Oct 30 '22 06:10

naresh


1 Answers

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.

like image 83
markus-nm Avatar answered Nov 11 '22 19:11

markus-nm