MQTT Camera for Node-RED

Alarm Recording as long as there is Movement

The internal alarm recording has a 3s pre-recording + a fixed recording length of 15-60s (adjustable from the webUI). I want to use Node-RED to make sure that the recording time always last as long as there is movement in front of the camera instead of having a fixed recording time.

Modules Used

Stoptimer2 allows me to define a delay that is automatically reset when a new trigger arrives. I want to use a Node-RED webhook that is contacted by the cameras HTTP alarmserver. This webhook triggers an update of the MQTT topic that starts the video recording. And it also triggers the stoptimer node that delays the update of the stop recording MQTT topic. Stoptimer will prevent the stop command as long as the camers alarmserver keeps contacting the Node-RED webhook.

Node-RED Flow

alarm-recording

[{"id":"4694e347.53620c","type":"stoptimer2","z":"f6bbaaa5.59a388","duration":"5","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":263,"y":572,"wires":[["4f9c9769.2be338"],[]]},{"id":"d0d3ebaf.f0d578","type":"http response","z":"f6bbaaa5.59a388","name":"","x":356,"y":479,"wires":[]},{"id":"65b1f092.794c2","type":"template","z":"f6bbaaa5.59a388","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h2>Hallo von Node-RED</h2>\n    </body>\n</html>","x":236,"y":479,"wires":[["d0d3ebaf.f0d578"]]},{"id":"620c71af.7a54","type":"http in","z":"f6bbaaa5.59a388","name":"Webhook","url":"/alarm-recording/","method":"get","upload":false,"swaggerDoc":"","x":105,"y":520,"wires":[["65b1f092.794c2","4694e347.53620c","eccf7756.849748"]]},{"id":"4f9c9769.2be338","type":"change","z":"f6bbaaa5.59a388","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"off\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":566,"wires":[["db35f8f0.f15cb8"]]},{"id":"eccf7756.849748","type":"change","z":"f6bbaaa5.59a388","name":"On","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"60\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":236,"y":520,"wires":[["37348a02.650846"]]},{"id":"db35f8f0.f15cb8","type":"mqtt out","z":"f6bbaaa5.59a388","name":"/features/manualrec/stop","topic":"instar/10D1DC218F96/features/manualrec/stop","qos":"1","retain":"false","broker":"9e4e460d.640f18","x":586,"y":566,"wires":[]},{"id":"37348a02.650846","type":"mqtt out","z":"f6bbaaa5.59a388","name":"features/manualrec/start","topic":"instar/10D1DC218F96/features/manualrec/start","qos":"1","retain":"false","broker":"9e4e460d.640f18","x":416,"y":520,"wires":[]},{"id":"9e4e460d.640f18","type":"mqtt-broker","z":"","name":"IN-9010FHD","broker":"192.168.2.165","port":"8883","tls":"ccad131e.c9943","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ccad131e.c9943","type":"tls-config","z":"","name":"9010pcert.pem","cert":"","key":"","ca":"","certname":"9010pcert.pem","keyname":"","caname":"","servername":"","verifyservercert":true}]

** this flow is written for a camera with the MQTT ID 000389888811. Search&replace all instances of this with your cameras ID before importing*

The INSTAR MQTT topics for starting and stopping the recording on the internal SD card are:

  • features/manualrec/start
  • features/manualrec/stop

The webhook can be contacted under [Node-RED IP]:[Node-RED Port]/alarm-recording/

Prerequisite

The alarmserver interval has to be lowered to a suitable value, e.g. 5s or 10s. This can only be done from the hidden dev menu on your camera. Open your cameras webUI and go to System/System Log and press and hold the 3 keys d, e and v to access the menu. The default delay between alarmserver triggers is set to 60s which would only work if you set the stoptimer delay to a value <60s.