BLE Gateway V4 MQTT and problems getting information msgpack.unpackb



I am trying to use the information coming from the AB BLE Gateway V4 via MQTT server into python. After unpacking via msgpack.unpack (payload) the devices array seems to be partially messed up:

Here an example:
{‘ip’: ‘’, ‘v’: ‘’, ‘mid’: 1558, ‘devices’: [’\x03\x12;j\x1bE\xcc\xc1\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x07\xc5’, ‘\x03\xc4S9<\x9d\xe6\xc7\x02\x01\x06\x1b\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\td\x0b\xcbd’, ‘\x03\x12;j\x1bE\xcf\xc0\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x08\xc5’, ‘\x03\xe9D\xf6\x1eBE\xb9\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\td\x05\xc5’, ‘\x03\x12;j\x1bE\xcf\xbf\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x08\xc5’, ‘\x03\xde\xfb)\6\x0f\xc2\x02\x01\x06\x1b\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\tY\t\xcbY’, ‘\x03\x12;j\x1bE\xcc\xc1\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x07\xc5’, ‘\x03\x12;j\x1bE\xcc\xc1\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x07\xc5’, ‘\x03\xe9D\xf6\x1eBE\xb8\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\td\x05\xc5’, ‘\x03\xdf\xca\x9e\xcd\xcfi\xb7\x02\x01\x06\x1b\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\td\n\xcbd’, ‘\x03\x12;j\x1bE\xcf\xc0\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x08\xc5’, ‘\x03\xde\xfb)\6\x0f\xc2\x02\x01\x06\x1b\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\tY\t\xcbY’, ‘\x03\x12;j\x1bE\xcc\xc0\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x07\xc5’, ‘\x03\xc4S9<\x9d\xe6\xc8\x02\x01\x06\x1b\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\td\x0b\xcbd’, ‘\x03\x12;j\x1bE\xcf\xc1\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x08\xc5’, ‘\x03\xe9D\xf6\x1eBE\xb5\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\td\x05\xc5’, ‘\x03\x12;j\x1bE\xcf\xb7\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x08\xc5’], ‘mac’: ‘30AEA490FE14’, ‘time’: 404}

Any idea why this happened and how to correctly unpack the information to not mess up the devices part?

Any help or idea would be great



Please check the wiki for data format. The devices array contains raw advertising data in hex format.


Thank you for the quick answer. Yes I know the format, but when using the standard python unpack on the mqtt message the content of the devices part is messed up. For the time being I am using a http server to receive the message which works, but I need eventually get mqtt working. Do you habe any idea why the message content is not received or unpacked properly. For example via web service the content is after unpack something like


but via mqtt it is somehow messed up and not even pure hex after the unpack command:

\x03\x12;j\x1bE\xcc\xc1\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x07\xc5

so I guess my method of getting the mqtt message and then unpacking in python via:

messagestring = str(msgpack.unpackb(theMessage.payload, use_list=False, raw=True))

is wrong, but I have no idea what to try. I tried it with raw=False already, no significant change. Do you have any hint what to try?



So which unpack message is right?



\x03\x12;j\x1bE\xcc\xc1\x02\x01\x06\x1a\xffL\x00\x02\x15^\xb2\xae\xdeO{1n#|\xd7 H\x7f\xb4\xb0\x00\x01\x00\x07\xc5


The first one coming through http is fine, but in the second one coming through MQTT are not only hexbin data e.g. \x03 but elements like \xffL or \x15^ or \xdeO{1n#| … I would expect only \x followed by two hex letters. So something on the way from sniffer -> MQTT -> python -> unpack -> messagestring goes wrong and I don‘t know what happens. Do you have maybe a code example for python to extract the data from the MQTT message coming from the V4 BLE Gateway? The code I use
messagestring = str(msgpack.unpackb(theMessage.payload, use_list=False, raw=True))
Does not do the trick.


No. I have only example PHP code for parse data from MQTT. I think the problem is python side. What mean is this parameter? – use_list=False


The parameter use_list=False only changes the output format, if it comes as an array or as one string. It does not change the content, I tried both. Can you please send me the php code example, then I will try it later this week to identify if the problem also appears there. this would tell me if the problem is maybe in the MQTT part and the MQTT Server needs to be changed.


The php SDK is here. Please check the source file examples/example_gateway4_mqtt.php