BLE Gateway V4 MQTT 和使用 python3 获取信息 msgpack.unpackb 的问题

BLE Gateway V4 MQTT and problems getting information msgpack.unpackb using python3

我正在尝试通过 MQTT 服务器使用来自 AB BLE Gateway V4 的信息进入 python3。通过 msgpack.unpack(有效负载)解包后,设备数组似乎部分混乱:

import time
import paho.mqtt.client as mqtt
import msgpack

def on_subscribe(mosq, obj, mid, granted_qos):
    print("Subscribed: " + str(mid))

def on_message(mosq, obj, msg):
    for d in msgpack.unpackb(msg.payload)[b'devices']:
      print("=============================================")
      # adv type
      print(d)
      print("type:", ord(d[0]))
      print("mac:{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}".format(ord(d[1]), ord(d[2]), ord(d[3]), ord(d[4]), ord(d[5]), ord(d[6])))
      print("rssi:", ord(d[7]) - 256)
      hex_chars = map(hex,map(ord,d))
      del hex_chars[:8]
      print("adv:", hex_chars)

def on_connect(mosq, obj,flags, rc):
    print("Connected with result code "+str(rc))
    mqttc.subscribe("/test", 0)
    print("Connected")


mqttc = mqtt.Client()
mqttc.on_connect = on_connect
mqttc.on_subscribe = on_subscribe
mqttc.on_message = on_message
mqttc.connect("mqtt.bconimg.com", 1883, 60)
mqttc.loop_forever()

我希望输出像

"type: 3
mac:2026698D97F1
rssi: -66"

但我得到的输出是 blow

 "Connected with result code 0
Connected
Subscribed: 1
=============================================
b'\x03\x16*)\x82|\xa7\xa7\x1e\xff\x06\x00\x01\t \x02\x1b6.\xe7P\xdf\xe9\xc3\xe6r\xca\x04H\x96!\xc0z~+\xd9\x13\x91?'
=============================================
b'\x037~M(\x83A\xaa\x1e\xff\x06\x00\x01\t \x02L\x90Ps\xb8\x9e\x80\x996Vx\xe3N\\x1f\x0c\x8eHE\x0eN\xaf\xbd'"

从这一行中删除 ord,您就可以开始了。

要更改的行

print("mac:{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}".format(ord(d[1]), ord(d[2]), ord(d[3]), ord(d[4]), ord(d[5]), ord(d[6])))