0

我正在使用 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~\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')

在解码 [4] 上的“数据”时,我得到:

STX SOH SUB VT ÿL

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

\xffL

对我来说看起来像是坏的十六进制。

我正在使用 MicroPython,所以我的解决方法有点有限。

4

1 回答 1

0

我已经阅读了一些不完整的 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'\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
于 2017-02-12T08:10:35.477 回答