Introduction

This programming guide discusses the MQTT message format provided from Irisys Vector units.

This section should be used in conjunction with the MQTT Settings Section which discusses how to configure the various options.

MQTT is just one of the many different methods of retrieving count data from a Vector device. Alternative data retrieval methods are the REST API, HTTP Post, BACnet and relay outputs via the optional USB IO module.

MQTT works by pushing out selected data ‘topics’ whenever an update occurs. This means that as soon as there is a change, data is received within a few seconds. MQTT data is accessed via an MQTT ‘broker’ which is a kind of middleman for moving the MQTT JSON messages around.

MQTT can be considered an almost 'real time' data retrieval method as an MQTT message will be sent within a second or two of a register change occurring.
Note: This section refers to Vector firmware 2.0.165 and above. See the Vector firmware section of any updates required.

 

Using the MQTT Data

There are five different topics available for selection: ‘Counts’, ‘Status’, ‘Targets’, ‘Live counts’, and ‘Device Info’. The ‘Targets’ topic is only available on Vector Analytic devices - not Vector Counts.

There must be an application that connects to the MQTT broker and subscribes to a data topic to receive the data provided. This is something that you will most likely have to create yourself, based on your own count data usage requirements, and the topics selected.

There are many free websites that can provide an MQTT broker which can be used for test purposes, if required.

We have some code examples on how to integrate with MQTT and also the REST API and the HTTP Post functionality, stored online at the GitHub repository. Go to: https://github.com/IrisysUK

 

Retain State

Some MQTT Brokers will cause additional data processing costs of MQTT messages when the Retain State is enabled.

In these cases it can be disabled if required, in the settings on device for that particular topic. See here.

 

MQTT Message Format

Counts Topic

Whenever a count register value changes, an event message is queued containing the register name, the change in value and the timestamp. This will be sent out along with any other pending messages on the next publication interval (configAWured in RIFT as the “period” value). An example of the message format of a ‘Counts’ topic is as follows:

[{      
      "register": "MainEntranceIn",
      "value": 1,
      "t": "2019-02-91T12:30:00+0000"
}, {      
      "register": "MainEntranceOut",
      "value": 1,
      "t": "2019-02-91T12:30:12+0000" 
}, {
      "register": "MainEntranceIn",
      "value": 1,
      "t": "2019-02-91T12:30:14+0000" 
}]

In the example above there have been count increments on two registers- two on the one named as “MainEntranceIn” and one on the register named as “MainEntranceOut”. The timestamps indicate the time of each event occurrence.

If no count events occur in the interval, an empty array will be sent out as below:

[]

 

Status Topic

Status event messages are published on connection and disconnection from the broker.

Connection Message

This is of the following format:

{“status”: “connected”}

 

Disconnection Message

This is sent up to the broker on connection as its “Last Will and Testament”. The broker will then push this out to subscribers in the event of the device’s disconnection. This is of the following format:

{“status”: “disconnected”}

Because it is the broker that pushes this out when a device disconnects, any ungraceful disconnects will also be notified (sudden power offs, network disruptions, etc.).

 

Targets Topic (Vector Analytic ONLY)

The Vector4D device supports sending the co-ordinate data for each tracked target in real-time over MQTT. This allows the end-user to build rich applications beyond people counting with Vector 4D features such as multi-unit target tracking and staff identification included, perhaps overlaying the information over a real-world representation of the installed environment, for example.

Data Format

The target data is delivered on a per-frame basis, regardless of whether any targets are currently being tracked. Data is delivered from the device to the broker at 15 frames per second.

Note that Target positioning stream will produce a lot of MQTT messages, especially when there are lots of people walking around.

The target data is delivered as little-endian binary data with no packing. The first byte is the target data format byte. This byte will always be present. If packet type is >=1, the next 8 bytes are timestamp (type 0 contained no timestamp). This is the number of milliseconds that have elapsed since 1 Jan 1970 (Unix Epoch time).

DataType

Description

uint8

Message type

uint64

timestamp (milliseconds), present since message type 1

DataType

Description

uint8

Message type

uint64

timestamp (milliseconds), present since message type 1

 

The packet ends here if no targets are present for this frame. If targets are present, the data continues with 15 bytes per target, packed as follows:

DataType

Description

uint16

target ID

uint8

status bits (0x20: tagged)

float32

x position (m)

float32

y position (m)

float32

target height (m)

 

Live Counts Topic

Similar to the Counts Topic but sent whenever there is a register change.

This is a retained topic on server.

An example is shown below:

{ 
"counts":
      [{
           "count":0,"id":0,"name":"Boardroom in"
      },{
           "count":0,"id":1,"name":"Boardroom out"
      },{
           "count":0,"id":2,"name":"Toilet in"
      },{
           "count":0,"id":3,"name":"Toilet out"
      },{
           "count":995,"id":4,"name":"KitchenDoorIn"
      },{
           "count":992,"id":5,"name":"KitchenDoorOut"
      },{
           "count":21000,"id":6,"name":"PIR"
      },{
           "count":1,"id":7,"name":"Occupancy"
      },{
           "count":674,"id":8,"name":"Occupancy Reset"
      },{
           "count":0,"id":9,"name":"Occupancy Wait"
      }], 
"index": 471, 
"time": "2020-12-17T11:19:46+0000" 
}

 

Device Info Topic

The Device Info Topic is sent on connection and when settings change.

This is a retained topic on the server. Example below:

{
      "deviceId":"D001",
      "deviceName":"CounterTest",
      "dhcpEnable":false,
      "ipV4Address":"192.168.1.120",
      "ipV6Address":"fe80::221:acff:fe04:125d",
      "macAddress":"00:21:AC:04:12:5D",
      "productId":"IRC6637CAW",
      "siteId":"S001",
      "siteName":"OriginOffice",
      "userString":"-" 
}

 

Event Stream Topic (Vector Analytic ONLY)

The Event Stream Topic is sent based on the configured trigger settings, for example, whenever a target appears or dies and whenever a target is seen crossing a line or entering/exiting a zone.

The event stream topic can be used to record movements of each and every target tracked through the field of view.

Each target has a unique ID which is sent along in the MQTT message.
It should be noted that some messages types will be sent at the same time when certain events occur, for example if a person walks into the field of view and appears within a configured zone, you should expect to see a Target birth message, and a Polygon Birth message, and also a Polygon Enter message.

The event stream will comprise the below message types:

 

Target Birth

When a target is acquired. I.e. created when a person first walks into the field of view and is 'initialised' as a valid target to be tracked.

{"target":{"heightCM":0,"id":1841},"type":"TARGET_BIRTH"}

 

Target Death

When target is lost. I.e. this event message is sent when a person walks out of the field of view and can no longer be tracked.

{"target":{"heightCM":164,"id":1841},"type":"TARGET_DEATH"}

 

Line Count

Triggers if line's count is incremented; based on direction of travel and register settings.

{"name":"Line 2","target":{"heightCM":161,"id":1844},"type":"LINE_COUNT"}

 

Line Forward Crossing

Sent Immediately regardless of the line register settings.

{"name":"Line 2","target":{"heightCM":161,"id":1844},"type":"LINE_FWD_XING"}

 

Line Reverse Crossing

Sent Immediately regardless of the line register settings.

{"name":"Line 1","target":{"heightCM":161,"id":1844},"type":"LINE_REV_XING"}

 

Polygon Birth

If target was birthed in the zone. I.e. a person is first seen appearing inside a polygon/zone.

{"name":"Testing Zone","target":{"heightCM":0,"id":1841},"type":"POLYGON_BIRTH"}
Note: dependent on configuration, a Polygon Birth message will also be accompanied by a Target Birth message

 

Polygon Enter

If target enters zone by crossing border or target birth.

{"name":"Testing Zone","target":{"heightCM":0,"id":1841},"type":"POLYGON_ENTER"}
Note: dependent on configuration, a Polygon Enter message may also be accompanied by a Polygon Birth and a Target Birth message, if a persons target is first seen (first appears) inside the polygon/zone.

 

Polygon Exit

If target exits zone by crossing border or target death

{"name":"Testing Zone","target":{"heightCM":164,"id":1841},"type":"POLYGON_EXIT"}

 

Polygon Death

If target died in the zone. i.e. the target is last seen within the zone.

{"name":"Testing Zone","target":{"heightCM":0,"id":1843},"type":"POLYGON_DEATH"}
Note: dependent on configuration, a Polygon Death message will also be accompanied by a Polygon Exit message, and a Target Death message, if a persons target is last seen (disappears) inside the polygon/zone.

 

If a person walks through the field of view, and out the other side, you should expect to see one Target Birth and one Target Death message, as well as any additional relevant line or zone messages, but importantly, each message will have the same id.

If a person walks out of the field of view and then re-enters the field of view, there is no way to associate the two different events, so the targets and associated event messages will have different ids.

Lastly, note that a person who is tracked on the edge of the field of view may generate lots of Target Birth and Target Death message (and possibly others dependent on configuration) as the Vector struggles to track that person. In these cases, each Target Birth will contain a new id.