MQTT BLE sensor stream
The BLE sensor stream includes all Bluetooth advertisement data received from BLE tags / sensors present in the setup. This stream can be filtered, see BLE whitelisting, allowing you to restrict which devices are included.
Data is sent on the ble-data
topic
This topic is only available on the local MQTT broker
MQTT packet structure
Each MQTT message contains an array of BLE messages. Below is an example of the general structure:
[
{
"version": "1.0",
"deviceId": "ex:am:pl:ma:ca:dr",
"timestamp": 1671165464.3779979,
"data":
{
"deviceData":
{
"type": "EDDYSTONE-TLM/EDDYSTONE-UUID/iBeacon/.../Unknown",
"payloadRaw": "018754af470000fa7894", // optional, only for unknown packets
"payloadData": { // optional, only for supported packets
}
},
"anchorData":
[
{
"anchorId": "4678",
"rss": -85,
"channel": 37
},
{
"anchorId": "5565",
"rss": -100,
"channel": 37
},
...
],
}
}
]
BLE message fields
Each BLE message contains the following fields
version
: string
Version of the Pozyx BLE sensor stream.
deviceId
: string
MAC address of the BLE tag or sensor.
timestamp
: number
The timestamp of when the position was calculated in Epoch time. You can convert it to a more human readable time with the following snippet:
import datetime
ts = datetime.datetime.fromtimestamp(1616424015.121358).strftime('%Y-%m-%d %H:%M:%S')
print(ts)
data.deviceData.type
: string
Type of BLE advertisement, currently supported data types are:
IBeacon
Eddystone UUID
Eddystone TLM
For non supported data types, the value of this field will be UNKNOWN
data.deviceData.payloadRaw
: string
Raw BLE advertisement payload as a hexadecimal string.
For messages with supported advertisement formats, payloadRaw
will not be present
data.deviceData.payloadData
: string
Decoded content of the payload for supported advertisement types.
Messages with unsupported advertisement formats will still be forwarded, but payloadData
will not be present
data.anchorData
: array
An array of the anchors that picked up the BLE advertisement, for each anchor containing:
anchorId
(string): ID of the receiving anchor.rss
(number): Received Signal Strength (RSS) in dBmchannel
(number): BLE advertising channel
Example messages supported data types
Example script
Below is a simple Python script that can be used to subscribe to the BLE sensor stream and print out the MQTT messages
import paho.mqtt.client as mqtt
import json
host = "localhost" # fill in the IP of your positioning server
port = 1883
topic = "ble-data"
def on_connect(client, userdata, flags, rc):
print(mqtt.connack_string(rc))
client.subscribe(topic)
# callback triggered by a new Pozyx data packet
def on_message(client, userdata, msg):
print("MQTT message:", msg.payload.decode())
def on_subscribe(client, userdata, mid, granted_qos):
print("Subscribed to topic!")
client = mqtt.Client()
# set callbacks
client.on_connect = on_connect
client.on_message = on_message
client.on_subscribe = on_subscribe
client.connect(host, port=port)
# works blocking, other, non-blocking, clients are available too.
client.loop_forever()