BLE GATT characteristic parsing

Hi There,

Sorry if this has already been answered elsewhere but I wanted to know what the easiest way of parsing BlueTooth characteristic types, in particular ones such as the example below which have several fields to pick from:

I have managed to extract the heart rate data but just by messing with string manipulation but for more complex ones I don’t see how it’s possible in App Inventor. If there is an extension which allows you to use an XML spec to expose each field that would be ideal.


Look into the Web Component for XML decoding.

Also see

1 Like

I have been using the BytesReceved for sensor data like Heart Rate and Speed Sensor. Then you can manipulate each byte as needed.

1 Like

Thanks - I’ll see how I get on :slight_smile:

Hi guys - I’m trying to filter what’s coming through the bytes received, but wondered if the data can easily get mixed up e.g power value and battery level - is this possible? I’ve been selecting the 3rd string along for power but think it might be a moving target:

. Heart rate works all the time and HRM battery level.

I think you just need to register for bytes once for each device. I am using an HRM, Speed Sensor and Cadence Sensor and Register for bytes once for each one. I use three Bluetooth LE components one for each device.

I’ve figured out what’s happening, when the PWR gets above 255W it clips and I just get the left-over e.g if it’s 257W I get 2W, so looks like I was only getting literally one byte, but when I tried to get the one next to it no luck. Ideally I’d have a bit mask I can AND over the whole data - think that’s what I need to do. Think it’s the 2nd block of 16 bits I need to focus on for cycling power data.

I tidied up all characteristic literals so it’s all done with lookups in plain English. I was also doing > 1 read bytes operation per bytes received which didn’t help! So stored it in a local variable at the top :slight_smile:

Hi @Martin_Wood,

If the characteristic is intended to be larger than a single byte (and it’s fixed width), consider using RegisterForShorts instead as that will give you 2-byte wide values, which implies an unsigned range of 0-65535. Do you have a pointer to the exact characteristic you’re reading that’s going beyond a single byte?

H there @ewpatton - using RegisterForShorts worked great - thank you!! Now to see what other similar data items I can poll e.g cadence data. If there’s anything that changes position within the data that’s going to be more challenging, so leave that for now eh :slight_smile:

Yes, unfortunately we don't have a good solution right now for more arbitrarily structured BLE packets. You can use the bytes version for this but you end up needing to implement a bit of math to reconstruct the larger values from the individual bytes.

In this thread I am looking for help. It is a similar problem to the one raised here.
Any help will be welcome.

Thank you so much for everything.

I got bogged-down making sure I had all the right codes in the right places so set up a few functions to return the service and characteristics, like this : image
Then to read battery level on HRM and heart rate the calls look like this now:

Hope this is somewhat useful as it's from a huge project and just trying to pull out the useful bits.

I wished when I was working on this that I could use an XML GATT specification to automatically map on to the data but it was very manual to parse this stuff.

This was the hardest bit - trying to extract speed, cadence, stride length from my power meter!

I had a working invterval timer for running workouts but once I got my Polar Vantage M I didn't need my app anymore :slight_smile:

I lost track of the original poster.

The downloaded blocks would be more useful if they were draggable, not clipped screen shots.
Draggable blocks save a whole lot of typing.
Here's how to make them ...

Please download and post each of those event block(s)/procedures here ...
(sample video)

BLE_Snippets_01.aia (9.0 KB)

Here's some sample snippets I took from my overall project via the backpack and pasting into a new project - they are just to illustrate a few ideas and don't work as a project ( which also has grown out of all proportion and is totally unmanageable !! ). I hope this helps someone :slight_smile:

I have tried to read data from the Heart Rate and the battery simultaneously. I am cappable of reading well the HR data but the battery level doesen't refresh the data. This data only refresh when I turn off and turn on the bluetooth connection. Could you help me?

For reading the heart rate data I use a RegisterforShorts and ReadShorts. For reading the battery level I use RegisterForBytes and ReadBytes.

To obtain the data I use ShortsReceived while loop and BytesReceived while loop.

Hi Miquel - I found that I had to manually call the .ReadBytes for battery every so often on a timer / via a button as well. With one of my heart rate monitors the battery level was in increments of 10 i.e 90,80,70% etc so if you wanted to wait long enough you might get a battery level notification from the device and therefore your .BytesReceived event should trigger. I hope this helps. Cheers, Martin