Push data over MQTT
The sensor can send its data to an MQTT broker on its own: the events, the zone states, the tracked objects or the health of the sensor. Your system subscribes to a topic at the broker, without programming against the API of the sensor. The recommended way is a flow in Blickfeld Flow; the configurations of Push do the same without TLS.
Publish with Blickfeld Flow
A flow on the sensor streams the data from the API of the sensor and publishes it with an mqtt out node. The connection to the broker can use TLS: the data and the credentials are encrypted, and the sensor checks the certificate of the broker.
Example flow
The example flow publishes what Push configurations with the sources EVENT and STATES and the encoding JSON send:
-
An inject node starts both streams once when the flow is deployed.
-
A blickfeld-qb2-method node streams
percept_processing.Event/Stream, another onepercept_processing.States/Stream. Each passes every response on as JSON. -
Two mqtt out nodes publish the events to
blickfeld/eventsand the zone states toblickfeld/zone-states, over TLS on port8883, with the certificate of the broker checked.
The example flow
[
{
"id": "b1f10a0e00000001",
"type": "tab",
"label": "Publish to MQTT",
"disabled": false,
"info": "Publishes the events and the zone states of the sensor to an MQTT broker over TLS, as Push configurations with the sources EVENT and STATES and the encoding JSON do.",
"env": []
},
{
"id": "b1f10a0e00000011",
"type": "inject",
"z": "b1f10a0e00000001",
"name": "Start",
"props": [],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"x": 110,
"y": 80,
"wires": [
[
"b1f10a0e00000012",
"b1f10a0e00000014"
]
]
},
{
"id": "b1f10a0e00000012",
"type": "blickfeld-qb2-method",
"z": "b1f10a0e00000001",
"name": "",
"connection": "local",
"device": "",
"fqdn": "",
"key": "",
"method": "/blickfeld.percept_processing.services.Event/Stream",
"request": "{}",
"request-type": "json",
"response": "",
"response-type": "*",
"response-format": "json",
"timeout": "",
"injectButton": false,
"autoReconnect": true,
"reconnectInterval": "5",
"x": 340,
"y": 80,
"wires": [
[
"b1f10a0e00000013"
]
]
},
{
"id": "b1f10a0e00000013",
"type": "mqtt out",
"z": "b1f10a0e00000001",
"name": "",
"topic": "blickfeld/events",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "b1f10a0e00000002",
"x": 610,
"y": 80,
"wires": []
},
{
"id": "b1f10a0e00000014",
"type": "blickfeld-qb2-method",
"z": "b1f10a0e00000001",
"name": "",
"connection": "local",
"device": "",
"fqdn": "",
"key": "",
"method": "/blickfeld.percept_processing.services.States/Stream",
"request": "",
"request-type": "*",
"response": "",
"response-type": "*",
"response-format": "json",
"timeout": "",
"injectButton": false,
"autoReconnect": true,
"reconnectInterval": "5",
"x": 340,
"y": 160,
"wires": [
[
"b1f10a0e00000015"
]
]
},
{
"id": "b1f10a0e00000015",
"type": "mqtt out",
"z": "b1f10a0e00000001",
"name": "",
"topic": "blickfeld/zone-states",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "b1f10a0e00000002",
"x": 620,
"y": 160,
"wires": []
},
{
"id": "b1f10a0e00000002",
"type": "mqtt-broker",
"name": "",
"broker": "mqtt.example.com",
"port": "8883",
"tls": "b1f10a0e00000003",
"clientid": "",
"autoConnect": true,
"usetls": true,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "b1f10a0e00000003",
"type": "tls-config",
"name": "",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "",
"servername": "",
"verifyservercert": true,
"alpnprotocol": ""
}
]
Import and deploy the flow
-
In the sidebar, click Configuration > Flow.
-
In the main menu
at the top right of the editor, click Import, paste the example flow and click Import. The flow opens on its own tab Publish to MQTT.
-
Double-click one of the mqtt out nodes and click
next to Server:
-
On the Connection tab, enter the host name of your broker at Server and its TLS port at Port, usually
8883. -
Leave Use TLS ticked and click
next to TLS Configuration. If a certificate authority of your own signed the certificate of the broker, upload the certificate of that authority at CA Certificate. Leave Verify server certificate ticked and click Update.
-
If the broker expects credentials, enter Username and Password on the Security tab.
-
Click Update, then Done.
-
-
Click Deploy.
Below each mqtt out node, the editor shows connected once the sensor has reached the broker.
Both mqtt out nodes use the same broker configuration, so the settings apply to both.
The zone states can come with every frame of the sensor. To send fewer messages, wire a delay node set to Rate Limit or a filter node between the method node and the mqtt out node, see Build rules with Blickfeld Flow.
For the other sources of Push, stream percept_processing.Objects/Stream or diagnostics.Health/Watch the same way.
What the broker receives
The broker receives each response of the API as one JSON message, with the field names of the encoding JSON of Push.
Unlike Push, the method node leaves out the fields that have their default value, such as false, 0 or an empty text, and writes decimal numbers with more digits.
Long lists and binary data are cut in the examples; a text in their place says how much was left out.
The examples were recorded on a sensor that watches two bunkers with volume zones.
A message on blickfeld/zone-states
{
"states": {
"timestamp": "1794520860008621299",
"states": {
"95f3e3e5-8994-4dac-b09d-ca50fb3293b7": {
"generatorName": "Bunker 1",
"volume": {
"volume": 178.75827026367188,
"coverage": 0.6081326603889465
}
},
"a1e33c96-57fd-42e2-b675-bf5d70359d9a": {
"generatorName": "Bunker 2",
"volume": {
"volume": 150.12660217285156,
"coverage": 0.6665635704994202
}
}
}
}
}
Push
|
Push is deprecated. For new integrations, use Blickfeld Flow: the example flow above sends the same data and connects to the broker over TLS. Push connects to the broker over plain MQTT only. It offers no TLS: the data and the credentials are sent unencrypted. Use Push only in a network you trust. |
Each push configuration sends one kind of data to one broker. You can set up several, for example events to one broker and health to another. Push can also be configured over the API with the Push service.
Create a configuration
-
In the sidebar, click Configuration > Push.
-
Click
at the top of the list.
-
Fill in the settings:
Figure 1. A new configuration with its default valuesSetting What it does Default Name
The name of the configuration. Required, and different from the names of the other configurations.
Empty
Switch next to the name
On: the sensor sends data once the configuration is applied. Off: the configuration is kept without sending.
On
Source
The data to send, see Sources.
HEALTH
Output encoding
The format of the messages, see Output encodings.
JSON
Output target
Where the data goes. Mqtt is the only target.
Mqtt
Endpoint > Hostname
The hostname or IP address of the MQTT broker, for example
mqtt.example.com. Required.Empty
Endpoint > Port
The port of the broker.
1883Endpoint > Client Identifier
The client identifier the sensor uses at the broker. Set it if your broker expects a particular one.
Empty
User authentication
None if the broker accepts clients without credentials. Credentials to enter the Username and Password of the broker account; the button
shows the password.
None
Topic
The MQTT topic to publish to. Empty: the default topic.
Empty
Figure 2. The endpoint of the configuration -
Click Apply. The sensor stores the configuration only now.
Apply is only active when you changed something and every required field is valid. Hover over it to see which fields still need attention.
Sources
Each message on the selected stream becomes one MQTT message.
| Source | What it sends |
|---|---|
EVENT |
One message for every event of the processing, at the moment it occurs. An event with a start and an end sends a message for each. The events are the occupancy of each occupancy zone. |
HEALTH |
The health state of the sensor, aggregated over its software modules, with the reason for a warning or an error. |
OBJECTS |
The objects the processing detects and tracks. |
STATES |
The states of the configured zones, for example the volume measured in a volume zone. |
Output encodings
| Encoding | Format |
|---|---|
JSON |
The message as JSON text. |
JSON_FLATTENED |
The message as JSON text with one level only. Nested fields are joined with dots into one key, for example |
PROTOBUF |
The message as binary Protocol Buffers. The most compact encoding; needs the Blickfeld protocol definitions to decode it. |
Example messages
One message of the source STATES, recorded on a sensor that watches two bunkers with volume zones, in JSON and in JSON_FLATTENED: the flattened message holds the same values as the JSON message above it.
The other sources send the messages of their services in the same form. Long lists are cut after three elements; a text in place of the fourth element says how many were left out. A PROTOBUF message holds the same fields in binary form.
STATES in JSON
{
"states": {
"timestamp": "1794520505777349630",
"states": {
"95f3e3e5-8994-4dac-b09d-ca50fb3293b7": {
"volume": {
"volume": 178.75827,
"coverage": 0.60813266
},
"generatorName": "Bunker 1",
"coverage": 0.0,
"coverageObservedArea": 0.0,
"coverageZoneArea": 0.0
},
"a1e33c96-57fd-42e2-b675-bf5d70359d9a": {
"volume": {
"volume": 150.1266,
"coverage": 0.6665636
},
"generatorName": "Bunker 2",
"coverage": 0.0,
"coverageObservedArea": 0.0,
"coverageZoneArea": 0.0
}
},
"injected": false
}
}
STATES in JSON_FLATTENED
{
"states.timestamp": "1794520505777349630",
"states.states.95f3e3e5-8994-4dac-b09d-ca50fb3293b7.volume.volume": 178.75827,
"states.states.95f3e3e5-8994-4dac-b09d-ca50fb3293b7.volume.coverage": 0.60813266,
"states.states.95f3e3e5-8994-4dac-b09d-ca50fb3293b7.generatorName": "Bunker 1",
"states.states.95f3e3e5-8994-4dac-b09d-ca50fb3293b7.coverage": 0.0,
"states.states.95f3e3e5-8994-4dac-b09d-ca50fb3293b7.coverageObservedArea": 0.0,
"states.states.95f3e3e5-8994-4dac-b09d-ca50fb3293b7.coverageZoneArea": 0.0,
"states.states.a1e33c96-57fd-42e2-b675-bf5d70359d9a.volume.volume": 150.1266,
"states.states.a1e33c96-57fd-42e2-b675-bf5d70359d9a.volume.coverage": 0.6665636,
"states.states.a1e33c96-57fd-42e2-b675-bf5d70359d9a.generatorName": "Bunker 2",
"states.states.a1e33c96-57fd-42e2-b675-bf5d70359d9a.coverage": 0.0,
"states.states.a1e33c96-57fd-42e2-b675-bf5d70359d9a.coverageObservedArea": 0.0,
"states.states.a1e33c96-57fd-42e2-b675-bf5d70359d9a.coverageZoneArea": 0.0,
"states.injected": false
}
Topics
If you leave Topic empty, the sensor sets a default topic when you apply the configuration: blickfeld/ followed by the name of the configuration in lower case, with spaces replaced by hyphens and special characters removed.
A configuration named Zone events publishes to blickfeld/zone-events.
After you apply, Topic shows the topic in use. Click in the field to copy it.
The sensor also publishes to the subtopic <topic>/status: OK when it starts sending data, or a description of the problem when sending fails.
Change, disable or delete configurations
One configuration
-
Click the configuration in the list to open it. Click it again to close it.
-
Change the settings and click Apply.
Reset discards the changes you have not applied yet. Delete removes the configuration from the sensor immediately.
To stop sending without losing the settings, switch off the switch next to the name and click Apply.
Several configurations at once
Tick the checkbox at the left of each configuration in the list and click Delete, Disable or Enable below the list. Disable stops sending and keeps the settings. The Search field above the list filters the configurations by name.
Read the status of a configuration
Each list entry shows the state of its connection, the number of messages sent (Messages) and Last message sent.
| State | Meaning |
|---|---|
|
The configuration is switched off and sends nothing. |
|
The sensor is connecting to the broker. |
|
The sensor is connected to the broker. |
|
The sensor is connected to the broker and sends data. The entry also shows the data rate. |
|
The connection to the broker is lost. |
Troubleshooting
- The state stays at
CONNECTINGorDISCONNECTED -
The sensor cannot reach the broker or the broker refuses it. Check Hostname and Port, the credentials under User authentication, and that the sensor has a route to the broker. Push cannot connect to a port that expects TLS, such as
8883. The sensor retries every 5 seconds on its own. - The connection works but no messages arrive
-
Check that your client subscribes to the topic shown in Topic, and check
<topic>/statusfor an error. With the source EVENT, a message is only sent when an event occurs. - The topic did not change after renaming a configuration
-
The sensor sets the default topic once, when the configuration is first applied with an empty Topic. To get the default topic for the new name, clear Topic and click Apply.