0

I am performing a Bluetooth scan from a SiPy board using Pymakr. The console returns unexpected values when decoding the returning advertisements.

from network import Bluetooth
bluetooth = Bluetooth()

bluetooth.start_scan(30)
while bluetooth.isscanning():
    adv = bluetooth.get_adv()
    if adv:
         print(adv)
         print(adv[4].decode())

The advertisement returns:

(mac=b'\xd0O~\x07\xc0.', addr_type=0, adv_type=0, rssi=-53, data=b'\x02\x01\x1a\x0b\xffL\x00\t\x06\x03\x04\xc0\xa8\x01!\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

When decoding the 'data' on [4] I get:

STX SOH SUB VT ÿL

I have a hard time making sense of the last two characters. Why the accent? Why the capital L? What's with this piece of the data string:

\xffL

Looks like bad hex to me.

I am using MicroPython so I'm sort of limited in workarounds.

dda
  • 6,030
  • 2
  • 25
  • 34
Mathias
  • 578
  • 2
  • 8
  • 15

1 Answers1

0

I had read some non-complete micropython documentation, AND misunderstood my output. The output is raw binary, not hex....

print(mac)  #is the rawbinary equal to adv[0]
mac = binascii.hexlify(mac) #apparently supported in firmware
print(mac.decode()) #makes wonders

fixed the problem.

The output to console is now:

(mac=b'fUD3"\x11', addr_type=1, adv_type=0, rssi=-27, data=b'\x02\x01\x06\x06\x088MHzL\x04\xff\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
b'fUD3"\x11'
665544332211
Mathias
  • 578
  • 2
  • 8
  • 15