解码十六进制返回(一些)意外值



我正在使用Pymakr从SiPy板执行蓝牙扫描。控制台在解码返回的广告时返回意外值。

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())

广告返回:

(mac=b'xd0O~x07xc0.', addr_type=0, adv_type=0, rssi=-53, data=b'x02x01x1ax0bxffLx00tx06x03x04xc0xa8x01!x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00')

在 [4] 上解码"数据"时,我得到:

STX SOH SUB VT ÿL

我很难理解最后两个字符。为什么是口音?为什么是大写的L?这部分数据字符串是怎么回事:

xffL

对我来说看起来像糟糕的十六进制。

我正在使用MicroPython,所以我在解决方法方面受到限制。

我读过一些不完整的micropython文档,并误解了我的输出。输出是原始二进制,而不是十六进制。

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

修复了问题。

控制台的输出现在为:

(mac=b'fUD3"x11', addr_type=1, adv_type=0, rssi=-27, data=b'x02x01x06x06x088MHzLx04xffx00xffx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00')
b'fUD3"x11'
665544332211

相关内容

最新更新