How to get "Device Information" from a BLE device!?

4,129 views
Skip to first unread message

Gerard Bucas

unread,
Jun 6, 2019, 7:37:33 PM6/6/19
to MIT App Inventor Forum
Hi guys,

Another question for the BLE experts that have been so incredibly helpful so far.

I can happily connect to my custom BLE device, read/check Supported Services & Characteristics and read data from it (UART service).

What confuses me is how to do "simple" things like get "Device Information" (or other "English Like" Characteristics from the device.
So for example "Device Information" has a GATT Service Assigned Number of 0x180A (see: https://www.bluetooth.com/specifications/gatt/services/ and
C:\Users\gerar\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\TempState\Downloads\org.bluetooth.service.device_information (1).xml )

But what does this mean exactly and how does one retrieve it (in BLE ext for AI2!)?

Guess I am missing something fundamental here (and should read the whole BLE spec but thought I would ask here just in case!! :) )

Regards

Gerard

SteveJG

unread,
Jun 6, 2019, 8:06:02 PM6/6/19
to mitappinv...@googlegroups.com
I do not know how to retrieve the GATT Assigned Number.   If the method is not in  BluetoothClient or  BluetoothServer or in another extension, you  cannot retrieve the Assigned Number..   You can only do what the extension indicates in its documentation.    If there is no  getGATTAssignedNumber method, you are probably out of luck.

If you can capture the 0x1800 then you know the 'English' equivalent Gerad.  Create either two Lists or a ListofPairs.  When your device indicates/receives  0x1800 tell your app to display the corresponding 'English' value  in List1 .     This is called using a 'dictionary'   It can be created using two Lists    0x1800 --> Generic Access  in two Lists or    0x1800,Generic Access using a List of Pairs.

twoLIsts.PNG

The problem is getting the Bluetooth device to provide the GATT info.  I suspect that cannot be done with the existing tools.    Someone else will hopefully provide more information.
Regards,
Steve

Gerard Bucas

unread,
Jun 6, 2019, 11:12:35 PM6/6/19
to mitappinv...@googlegroups.com
Hi Steve,

Thanks - I DO in fact know how to use lists for a dictionary, etc!

You misunderstood my question! Every BLE device provides certain "standard" information about itself (like the information I referenced called "Device Info").
If you look at the 2nd link I provided, you will see the format of the information thus provided using these "Standard" (like 0x180A) GATT assigned service codes.
So I don't need a dictionary (!) what I NEED to know is how one can "interrogate" ANY BLE device using these standard GATT assigned standard Service codes.

I am sure there are some people on this forum will in fact know how to do this - so I am still hopeful and feel that with the right Service/Characteristics codes I can in fact read these from any BLE Device.

So hopefully they will better understand what I am asking... :)

Regards

Gerard
 

Evan Patton

unread,
Jun 7, 2019, 12:09:31 AM6/7/19
to MIT App Inventor Forum
Hi Gerard,

Unfortunately this used to be easier because the Bluetooth SIG had a web-based tool to explore the service/characteristic from the specs. They took that tool down last year. And unfortunately the links from the BLE GATT pages on the Bluetooth website link to incomplete XML documents that contain the Service UUIDs but not the Characteristic UUIDs.  I did find this GitHub repo with XML files for the characteristics, so you can look up the UUIDs of the characteristics of interest. For the device information service, the UUID will always be 180A. Once you have the service/characteristic UUIDs, you can call any of the Read methods of the BLE extension to read the data. Which method you call will depend on the datatype of the corresponding characteristic.

Regards,
Evan

gerrikoio

unread,
Jun 7, 2019, 8:25:53 AM6/7/19
to MIT App Inventor Forum
But what does this mean exactly and how does one retrieve it (in BLE ext for AI2!)?


Ok, as you know there is a block "call BluetoothLE1.SupportedServices" which will provide a list of all the services available.

For access to these type of services I scan through the list to find a match for the 0x180A, for example, and then save the index number within the list.

Then you can use the block "call BluetoothLE1.ServiceByIndex" using the saved index number. This will return the unique ID for that service which you can then use to access this service.

Now that you have the UUID you can do something similar for Characteristics.

As before use "call BluetoothLE1.GetCharactertisticsForService".

Then you can search through this list to find the right one.

So if you open up the XML page as found in the Bluetooth specifications you will see the following:

Note: Some are mandatory and some would be optional - look inside the XML defined characteristic for "Requirement"

1. Manufacturer Name String
2. Model Number String
3. Serial Number String
4. Hardware Revision String
5. Firmware Revision String
6. Software Revision String
7. System ID
8. IEEE 11073-20601 Regulatory Certification Data List
9. PnP ID

For each characteristic there is a defined data structure - that is given to you in the XML. You would need to search through the Bluetooth website to find the relevant XML page.

Also if you look at the characteristic it defines which properties applies. So some would have a mandatory READ property for example and have WRITE excluded. Then some allow for Notify or Indicate properties etc.

Hope that helps

Gerard Bucas

unread,
Jun 7, 2019, 9:57:49 AM6/7/19
to MIT App Inventor Forum
Thanks gerrikoio - that was extremely useful & informative! Will try it.

one thing that still confuses me is that once I find the characteristics associated with 0x180A (as you describe), is there then a separate characteristic for each of the ‘items’ (eg: Manufacturer, Serial, model, etc) that the device supports?

That’s how it sounds to me so that one then uses each of those supported characteristics to retrieve the ‘xml string’ describing that ‘item’ (eg: Manufacturer, etc)?

Just trying to get my head around the whole concept before I try to implement it.

You are a great teacher! :)

Much appreciated

Gerard

gerrikoio

unread,
Jun 7, 2019, 11:36:10 AM6/7/19
to MIT App Inventor Forum
one thing that still confuses me is that once I find the characteristics associated with 0x180A (as you describe), is there then a separate characteristic for each of the ‘items’ (eg: Manufacturer, Serial, model, etc) that the device supports? 


Note if you right click on any of the links given for each characteristic and choose "open link in new tab" it will open up in browser rather than having to download each one.

So for example " Manufacturer Name String" is a standard characteristic with shortened UUID = 0x2A29


The key field is "format" as in <Format>utf8s</Format> or string format.

So here you need to look back at the Services structure and there it tells you: <Read>Mandatory</Read> and all other properties are excluded.

So the only way to get this information will be to use the "call BluetoothLE1.ReadStrings" method.






Gerard Bucas

unread,
Jun 7, 2019, 12:41:23 PM6/7/19
to MIT App Inventor Forum
Wow - you really are a wealth of information! I’m starting to feel like I understand this stuff now (scary! :) )

Last quick question:
Can one use those short Service m/Characteristics codes directly in the AI BLE blocks (so 180A for 0x180A and 2A29 for 0x2A29)?

Thanks again!!!

Gerard

gerrikoio

unread,
Jun 7, 2019, 1:15:35 PM6/7/19
to MIT App Inventor Forum
Good to hear!

I think the best way to answer your question is for you to actually try 0x180A and 180A etc and see what happens :-)

If any error messages pop up we can always then help interpret.

Gerard Bucas

unread,
Jun 7, 2019, 8:31:50 PM6/7/19
to mitappinv...@googlegroups.com
FYI..! :)

One can use the "short codes" without any problems!
So for 0x180A, you would use "0000180A" in AI2 BLE and for 0x2A29 one would use "00002A29".

PS: I should have added that I actually tested the above & it all works like a charm..!

gerrikoio

unread,
Jun 8, 2019, 5:51:25 AM6/8/19
to MIT App Inventor Forum
That's great to hear. Thanks for updating.

ABG

unread,
Jun 8, 2019, 6:14:06 PM6/8/19
to MIT App Inventor Forum
Reply all
Reply to author
Forward
0 new messages