How to read the BLE broadcast advertising custom 31 byte message?

1,594 views
Skip to first unread message
Assigned to ewpa...@gmail.com by me

Artur Walewski

unread,
Aug 13, 2017, 8:39:58 AM8/13/17
to MIT App Inventor Forum
Hi,

I have a set of BLE sensors which insert a custom payload of data in 31 byte advertisement using the Manufacturer Specific Data Field. There is no any UUID used in advertisement data, only custom data.
I'm trying to read the custom data using AdvertisementData block without success, because this block requires an UUID as the input.

Is there any way to read the Manufacturer Specific Data Field? 


gerrikoio

unread,
Aug 14, 2017, 5:12:27 PM8/14/17
to MIT App Inventor Forum
If you used the "call BluetoothLE1.AdvertiserServiceUUIDs method" what service UUIDs are returned when you provide the device Address. This should then give you the data for AdvertisementData method without having to specify it yourself.

Artur Walewski

unread,
Aug 15, 2017, 5:00:39 PM8/15/17
to MIT App Inventor Forum

I receive only a null object reference. There is no UUID in advertisement data (UUID is not mandatory advertisement data according to BLE standard), so it is understandable that a null object reference is returned. So I can not set an UUID, because there is no one defined/used by BLE device.




gerrikoio

unread,
Aug 15, 2017, 5:41:37 PM8/15/17
to MIT App Inventor Forum
I don't believe you can do it that way. The AdvertiserServiceUUIDs is providing you with a list of services which may also include some of the primary ones (e.g. 0x180A device information) or not. Anyways you need to make reference to an item inside the service list. As such try inserting "call BluetoothLE1.ServicebyIndex" with index value of 1 as ServiceUuid for AdvertisementData and see what happens. If there are multiple services inside list then suggest using some logic to rule out the primary ones etc.

gerrikoio

unread,
Aug 15, 2017, 5:49:36 PM8/15/17
to MIT App Inventor Forum


CaptureAdvertise.JPG

Evan Patton

unread,
Aug 15, 2017, 6:55:02 PM8/15/17
to MIT App Inventor Forum
Hi Artur,

Having looked at the BLE sources, I don't think it is possible to do what you are asking with the blocks we currently provide. That being said, it would be possible to add a mechanism to access the manufacturer data.

Evan

gerrikoio

unread,
Aug 16, 2017, 6:19:25 AM8/16/17
to MIT App Inventor Forum
Evan

So are you saying then that the "Advertiser" blocks do not work at present? I too had assumed these blocks were designed to retrieve advertising packet data.

I have a couple of iBeacons and I could not get any "advertising" data or service uuids from them other than "Advertiser Address" if I supplied correct device name.

I've attached a screenshot of what other Android scanning apps provide when they detect a beacon "advertising". Note that all this data (advertising uuid + major / minor fields) is provided at device level without the need for accessing or clicking into a service uuid (and actually it appears that no service uuid is provided for advertising data in this case).

It would be nice to have access to this data.
Screenshot_2017-08-16-10-50-38.png
Screenshot_2017-08-16-11-12-33.png

Artur Walewski

unread,
Aug 16, 2017, 11:41:31 AM8/16/17
to MIT App Inventor Forum
Thanks for help.

Gerrikoio, I was trying your latest proposition and I also received a null object reference. There is no UUID in advertisement data. I've attached an example of my sensors data.

Evan, do you know if and when such mechanism be implemented in AI2?


Screenshot_2017-08-16-17-32-43-956_no.nordicsemi.android.mcp.png
Screenshot_2017-08-16-17-33-22-423_no.nordicsemi.android.mcp.png

Evan Patton

unread,
Aug 16, 2017, 4:05:32 PM8/16/17
to MIT App Inventor Forum
@gerrikoio,

The advertisement data should work as expected when the advertisement data are tied to a service UUID. The issue here that Artur is having is that manufacturer data aren't reported as part of an existing service advertisement. There is a separate API call for that, which we haven't exposed via the blocks. So if you are attempting to get the advertisement data for a specific service you should be fine, it only affects this specific scenario.

@Artur

I can't say for certain. It doesn't look like it would be too difficult to implement, but the earliest I would be able to take a look would be Friday. There are a few bugs that need to be fixed in the BLE extension as well, so I'll try to fit it in.

Evan

Message has been deleted

gerrikoio

unread,
Aug 16, 2017, 4:54:14 PM8/16/17
to MIT App Inventor Forum
Hi Evan

Ok, I now understand the scenario and now makes sense. I've been researching online as to how best to apply service uuids in order to access advertising data. This link seems to offer a good explanation. Based on my understanding of their explanation, you use the service uuid to allow the Android device to narrow down / speed up the device search based on this filter - so it's linked to the scanning process where you do not need to know the device id beforehand. This would make sense for beacons, for example, where you typically use one uuid to link a group of beacons together in an application.


Now curious to see whether one can implement this with the current ble blocks available. At first glance, it does not appear so.


Evan Patton

unread,
Aug 16, 2017, 5:04:12 PM8/16/17
to MIT App Inventor Forum
Hi gerrikoio,

That's correct. The Bluetooth Specification v4.2, Vol. 3, Part G, Subsection 4.4.1 (page 2239) discusses how (1) service declaration should be readable without authentication and authorization, and that the subprocedure to read services from the server can exit early if an appropriate UUID is found as part of the discovery process. Specifically:

It is permitted to end the sub-procedure early if a desired primary service is found prior to discovering all the primary services on the server.

However, at this time we do not provide any blocks that would allow you to customize Android's ScanFilter object prior to starting the scan, so this particular power optimization is not available for App Inventor apps. Exposing the filter API might make for an interesting research project but is currently outside the scope of our efforts for the BLE extension.

Evan

Evan Patton

unread,
Aug 16, 2017, 5:08:18 PM8/16/17
to MIT App Inventor Forum
I should also point out that Subsection 3.3.1.1 of the same document (page 2225 of the spec PDF) describes the Broadcast bit for the characteristic which allows for its value to be broadcast in the advertising packet. I believe this is how most beacon protocols work since it prevents having to do further configuration between devices, but I have not looked into it.

Evan

JP Le Riche

unread,
Aug 14, 2019, 11:52:00 AM8/14/19
to MIT App Inventor Forum
Hi Arthur, Any success on this? I have the same issue....

TimAI2

unread,
Aug 14, 2019, 12:04:46 PM8/14/19
to MIT App Inventor Forum
That was 2 years ago.....perhaps start a new thread ;)

Artur Walewski

unread,
Aug 14, 2019, 4:56:17 PM8/14/19
to MIT App Inventor Forum
No. I used Android Studio...
Reply all
Reply to author
Forward
0 new messages