【问题标题】:Decoding hex returns (some) unexpected values解码十六进制返回(一些)意外值
【发布时间】:2017-06-29 21:38:25
【问题描述】:

我正在使用 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,所以我的解决方法有点有限。

【问题讨论】:

    标签: python bluetooth micropython


    【解决方案1】:

    我阅读了一些不完整的 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
    

    【讨论】:

      猜你喜欢
      • 2014-07-10
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2018-05-16
      • 2019-07-30
      • 1970-01-01
      • 2021-06-04
      相关资源
      最近更新 更多