3

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.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • This is going to be a dumb question (and feels like a really unlikely mistake to make), but is it possible that the first 44 is in decimal? If that were the case, then you'd have Inst Cadence (1230rpm ?!?!?), Average Cadence (46 rpm), Resistance (79), Heart Rate (80 bpm). That Inst Cadence number makes it feel even less likely. Have you connected to this with nrfConnect, which does very good decoding? (I agree this decoding data packet feels very weird.) – Rob Napier Feb 18 '21 at 02:04
  • Instantaneous speed is always present – Paulw11 Feb 18 '21 at 02:10

1 Answers1

4

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.

bradeyh
  • 56
  • 2
  • Thank you, that's bizarre but apparently true. Just what I needed to know. – Tom Harrington Feb 18 '21 at 18:45
  • Now that I look again though, bit 2 (instantaneous cadence) also has its value flipped, so that a 1 indicates it's not present. That goes back to saying only 5 bytes should follow, I think. – Tom Harrington Feb 18 '21 at 19:00
  • Like you noted in the [other question](https://stackoverflow.com/questions/64002583/decode-bluetooth-data-from-the-indoor-bike-data-characteristic), that looks like a bug in the spec. I think the XML file has it right--bit 2 is active-high. – bradeyh Mar 06 '21 at 00:46