[SOLVED] Need Help with GATTC services
-
Hi All
Forgive me if this is a dumb question but I am struggling with understanding the GATT packet I am getting from my Lopy.
I have a BLE beacon (a TILT hydrometer) and am reading the GATT output from it using the "Class Bluetooth "Quick Usage Example".
The LoPy is connecting OK. but when I execute the line "print('Reading chars from service = {}'.format(service.uuid()))"
I get a bunch of replies most of which I understand. But one service returns the line Quote "Reading chars from service = b'\xdet-\xf0p\x13\x12\xb5DK\xb1\xc5 \xff\x95\xa4' Unquote.
I realize this may be a dumb question but what does this mean. I understand the 'b' means byte ( I could not find this documented anywhere so this is an educated guess) but what is the significance of "xdet" and what format are the included numbers in. I have never seen a number with DK in it.
Thanks for any help anybody can provide. And by the way if this IS documented could somebody tell me where?
Thanks in advance
Tom B
-
SOLVED
Thanks for the help. Was able to adapt the example to connect to my Lopy and get a specific service with no issues.
Some tips for anybody else trying to do access a GATT service.
If you use the Pycom example it will print out a services.uuid like this
b'\xdet-\xf0p\x13\x12\xb5DK\xb1\xc5 \xff\x95\xa4' .
But if you are trying to access the service using the UUID as it appears it will not work.
So what I did (as suggested by jmarcelino) was use binascii.hexlify to get a hex value. Which in this case was -----de742df0701312b5444bb1c520ff95a4' ,then use that as the value with binascci.unhexlify as the uuid input like this
service.uuid()==binascii.unhexlify(b'de742df0701312b5444bb1c520ff95a4'):
Another way to get the uuid is to use the Android Nordic Semiconductor nRF Connect app (or similar) to get the hex value for the UUID and then use unhexlify as above.
-
b'...' is a standard Python 3 bytes literal (docs)
Printable characters are shown as they are, while non-printable are shown as \xYZ where YZ is the hexadecimal value, so in your example \xdet means 0xDE, 0x74 (which prints as t)
If you want everything in hexadecimal use the binascii module:
import binascii print(binascii.hexlify(service.uuid()))