5

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?

naresh
  • 627
  • 1
  • 7
  • 28
  • When you discover the characteristic, is it readable? I mean, `if (yourCharacteristic.properties & CBCharacteristicPropertyRead){youCanReadIt}`. I'm not familiar with bluegiga, but your XML seems to allow write, but not explictly read. – Larme Jun 22 '17 at 14:54
  • No it has only "write" and "indicate" property. Can we read data if we have indicate property? Someone has developed a test application for the same device for desktop and its working perfectly. – naresh Jun 23 '17 at 06:07
  • Do you able to read data? or just notification is not fired, also what's your expected output format about bluetooth data? – Allen Jul 03 '17 at 01:04

2 Answers2

2

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.

markus-nm
  • 805
  • 5
  • 8
0

I found the issue. Actually issue is with the emulator. And now i can get data update indications and able to write data to BLE with only "read" and "indicate" properties.

naresh
  • 627
  • 1
  • 7
  • 28