INSTAR Deutschland GmbHINSTAR Deutschland GmbH

MQTT Sensor Video Overlay



Q: I am using a MQTT/Zigbee/Z-Wave Sensor and I want to display it's readout as an overlay over my camera's video feed. Is it possible to add a data stream to my camera's video image?

A: Here is an example how this problem can be solved in Node-RED using the INSTAR MQTT Interface and the image overlay.

MQTT Sensor Video Overlay

Activating the Overlay

In the example above I added an option to activate and deactivate the sensor overlay using the multimedia/overlay/showname MQTT topic. You can replace the Inject Nodes by incoming triggers - for example when the sensor readout exceeds a save value:

Node-RED Flow Export

[{"id":"fe5510d0.fada1","type":"mqtt out","z":"9c94ad40.eea84","name":"multimedia/overlay/showname","topic":"cameras/117/multimedia/overlay/showname","qos":"1","retain":"false","broker":"7553a41d.22b8bc","x":319,"y":58,"wires":[]},{"id":"e3f4cbf0.f0d0d8","type":"inject","z":"9c94ad40.eea84","name":"OFF","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"val\":\"0\"}","payloadType":"json","x":110,"y":80,"wires":[["fe5510d0.fada1"]]},{"id":"46aa340.db0f0cc","type":"inject","z":"9c94ad40.eea84","name":"ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"val\":\"1\"}","payloadType":"json","x":110,"y":40,"wires":[["fe5510d0.fada1"]]},{"id":"7553a41d.22b8bc","type":"mqtt-broker","name":"192.168.2.117","broker":"192.168.2.117","port":"8883","tls":"c411fab7.e16228","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c411fab7.e16228","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"mqtt_client-new.crt","keyname":"","caname":"","servername":"","verifyservercert":false}]

Adding your Data Stream

I am using a random number generator to simulate the sensor readout. The readout is then send as payload to an MQTT Out node for the MQTT topic multimedia/overlay/cameraname - replacing the camera name with the sensor readout.

Node-RED Flow Export

[{"id":"ad54e87a.837728","type":"mqtt out","z":"9c94ad40.eea84","name":"multimedia/overlay/cameraname","topic":"cameras/117/multimedia/overlay/cameraname","qos":"1","retain":"false","broker":"7553a41d.22b8bc","x":471,"y":122,"wires":[]},{"id":"a4fdb5a5.dd1ee8","type":"function","z":"9c94ad40.eea84","name":"Sensor","func":"random=Math.round(Math.log(Math.floor(Math.random() * 100) + 1) * 1000) / 1000;\nmsg.payload='{\"val\":\"Rad%3A%20'+ random + '%20Bq\"}'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":253,"y":122,"wires":[["ad54e87a.837728"]]},{"id":"7c6c476.68d89b8","type":"inject","z":"9c94ad40.eea84","name":"Intervall","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":110,"y":122,"wires":[["a4fdb5a5.dd1ee8"]]},{"id":"7553a41d.22b8bc","type":"mqtt-broker","name":"192.168.2.117","broker":"192.168.2.117","port":"8883","tls":"c411fab7.e16228","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c411fab7.e16228","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"mqtt_client-new.crt","keyname":"","caname":"","servername":"","verifyservercert":false}]

Overlay Position

If you need to position the overlay on the bottom of the image, you can use the following CGI SET command to do that:

/param.cgi?cmd=setoverlayattr&-region=1&-show=1&-name=Rad%3A%204.563%20Bq&-place=1
/param.cgi?cmd=setoverlayattr&-region=1&-show=1&-name=Rad%3A%204.563%20Bq&-place=0

The parameter place either places the overlay on the top left or bottom left of the video image. To read the current setting use the following GET command:

/param.cgi?cmd=getoverlayattr&-region=1