Skip to main content
Skip table of contents

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:

JSON
[
    {
        "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:

PY
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 dBm

  • channel (number): BLE advertising channel

Example messages supported data types

Example message IBeacon
JSON
{
   "version":"1.0",
   "deviceId":"xx:yy:zz:08:23:00",
   "timestamp":0.0,
   "data":{
      "deviceData":{
         "type":"IBEACON",
         "payloadData":{
            "major":0,
            "minor":0,
            "power":-59,
            "proximityUuid":"e2c56db5dffb48d2b060d0f5a71096e0"
         }
      },
      "anchorData":[
         {
            "anchorId":"12175",
            "rss":-91,
            "channel":39
         },
         {
            "anchorId":"12251",
            "rss":-88,
            "channel":37
         },
         {
            "anchorId":"12275",
            "rss":-86,
            "channel":37
         }
      ]
   }
}
Example message Eddystone UUID
JSON
{
   "version":"1.0",
   "deviceId":"xx:yy:zz:00:3e:b7",
   "timestamp":0.0,
   "data":{
      "deviceData":{
         "type":"EDDYSTONE_UUID",
         "payloadData":{
            "instanceId":"000000000027",
            "namespaceId":"00112233445566778899",
            "powerAt1m":232,
            "rfu":0
         }
      },
      "anchorData":[
         {
            "anchorId":"10395",
            "rss":-82,
            "channel":38
         },
         {
            "anchorId":"12173",
            "rss":-78,
            "channel":39
         },
         {
            "anchorId":"12175",
            "rss":-85,
            "channel":38
         },
         {
            "anchorId":"12190",
            "rss":-69,
            "channel":39
         },
         {
            "anchorId":"12298",
            "rss":-65,
            "channel":37
         }
      ]
   }
}
Example message Eddystone TLM
JSON
{
   "version":"1.0",
   "deviceId":"xx:yy:zz:08:23:00",
   "timestamp":0.0,
   "data":{
      "deviceData":{
         "type":"EDDYSTONE_TLM",
         "payloadData":{
            "advPduCount":85416670,
            "batteryVoltage":3144,
            "beaconTemp":5888,
            "customDataHex":"",
            "timeSinceBoot":667347990,
            "version":0
         }
      },
      "anchorData":[
         {
            "anchorId":"12184",
            "rss":-87,
            "channel":38
         },
         {
            "anchorId":"12243",
            "rss":-82,
            "channel":37
         },
         {
            "anchorId":"12275",
            "rss":-81,
            "channel":38
         }
      ]
   }
}
Example message Unknown format
JSON
{
   "version":"1.0",
   "deviceId":"xx:yy:zz:35:8e:3b",
   "timestamp":0.0,
   "data":{
      "deviceData":{
         "type":"UNKNOWN",
         "payloadRaw":"0201061bff3906ca1b01001bd03b8e350000c3055e18f000c50000000e2dca"
      },
      "anchorData":[
         {
            "anchorId":"10395",
            "rss":-80,
            "channel":39
         },
         {
            "anchorId":"12175",
            "rss":-70,
            "channel":38
         },
         {
            "anchorId":"12283",
            "rss":-91,
            "channel":37
         },
         {
            "anchorId":"12298",
            "rss":-76,
            "channel":37
         }
      ]
   }
}

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

PY
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()
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.