Introduction

In this tutorial you will learn how to include custom data in the tag transmission payload. This will essentially transform the Enterprise system in a wireless sensor network. The data transmitted will be available in the MQTT stream on the gateway, with the position included. This will allow you to capture location-based events or location-based sensor data for your application.

The developer tag can be used both for the Creator and the Enterprise series. For the Enterprise series, the tag must be configured to be in the Enterprise TDOA Aloha mode. Using the device configurator, it is already possible to change the behavior of the tag such as positioning update rate, or by selecting between some standard payloads. The standard payloads capture sensor data from developer tag and include it in the transmission packet. Sensors to choose from are the on-board accelerometer, gyroscope, magnetometer or pressure sensor.

We will see now how to customize this even further.

Python library setup

First we’re going to need the Pozyx python library to communicate with the developer-tag over USB. You can download it through git. When cloning the repository, make sure you checkout the develop branch.

Make sure you have the prerequisites as stated in the readme.rst

  • python installed

  • pyserial package installed

  • ST’s virtual COM driver installed

Custom payload

Here we will create a script that connects to the developer tag. Then it will enable the ALOHA-mode and write the custom data that needs to be transmitted as payload. In the script below, the custom payload is an incrementing integer which is transmitted every 0.5 seconds. To encapsulate other types of data, please check the Python function pack.

from pypozyx 
import * from pypozyx.definitions.registers 
import * from time 
import sleep 

import struct p = PozyxSerial(get_first_pozyx_serial_port())  
p.startAloha() 
index = 0 
while True: 
    transmit_data = struct.pack("I", index) 
    index += 1 
    p.writeTXBufferData(transmit_data) 
    p.sendAloha(POZYX_SEND_CUSTOM_ALOHA_IMMEDIATE) 
    sleep(0.5)
PY

Grabbing the data through MQTT

Finally, we can capture the transmitted data by connecting to the MQTT stream. For the example above, the output looks as follows. The custom payload can be found under data > tagData > customSensors under customPayload. The data is represented as bytes in BigEndian. In the example below, this is the value 13 represented by "\\u0013\\u0000\\u0000\\u0000".

[
   {
      "version":"1.4",
      "data":{
         "anchorData":[
            {
               "rss":-82.88,
               "anchorId":"26856",
               "tagId":"24903"
            },
            {
               "rss":-87.03,
               "anchorId":"50864",
               "tagId":"24903"
            },
            {
               "rss":-89.02,
               "anchorId":"32733",
               "tagId":"24903"
            },
            {
               "rss":-86.66,
               "anchorId":"56705",
               "tagId":"24903"
            },
            {
               "rss":-85.01,
               "anchorId":"23664",
               "tagId":"24903"
            },
            {
               "rss":-80.19,
               "anchorId":"41193",
               "tagId":"24903"
            }
         ],
         "coordinatesType":1,
         "velocity":{
            "z":0,
            "y":117,
            "x":419
         },
         "tagData":{
            "blinkIndex":20,
            "customSensors":[
               {
                  "name":"customPayload",
                  "value":"\\u0013\\u0000\\u0000\\u0000"
               }
            ]
         },
         "coordinates":{
            "z":1500,
            "y":10663,
            "x":1795
         },
         "metrics":{
            "rates":{
               "packetLoss":0,
               "success":1.78,
               "update":1.78
            },
            "latency":22
         },
         "extras":{
            "zones":[

            ],
            "version":"0.1"
         }
      },
      "success":true,
      "tagId":"24903",
      "timestamp":1559034161.9817805
   }
]
JSON