Search code examples
bluetooth-lowenergycore-bluetoothbtle

BTLE characteristic value has too many bytes


I'm trying to read data from the BTLE fitness machine service, specifically the Indoor Bike Data characteristic.

A typical reading I'm getting has the bytes 44-02-9c-09-5c-00-4f-00-50. The first two are flags which indicate that the rest of the bytes represent, in order:

  • Instantaneous cadence (uint16)
  • Instantaneous power (sint16)
  • Heart rate (uint8)

The trouble is, that only accounts for 5 more bytes, but there are 7 more bytes in the value. It looks like 5c-00 is cadence, 00-4f is power, and 50 is heart rate, but

  • I don't know what the 9c-09 represents, but more importantly,
  • I don't know how to reliably read this characteristic if it's going to send me data that the flags field says is not present.

What do I need to do to parse these bytes correctly? In this specific case I could maybe skip those two bytes, but that won't be reliable over different device manufacturers.

Update: FWIW I don't think it was correct to mark this as a duplicate. I was able to parse the bytes, the problem was that the result appeared to contradict the fitness machine spec. The accepted answer clarified that.


Solution

  • The 9c-09 value is instantaneous speed, which is present (counterintuitively) if the first flag bit is 0. See Fitness Machine Service spec, section 4.9.1.1.