INSTAR Deutschland GmbHINSTAR Deutschland GmbH

Using the INSTAR MQTT Alarmserver to track Moving Objects



Q: Is it possible to use Node-RED to have my Full HD pan&tilt camera follow moving objects ?

A: You can use INSTAR MQTT Alarmserver to notify Node-RED about detected movements. You can start by selecting two areas you want to use to trigger a pan or tilt movement of your camera:

INSTAR MQTT Alarmserver and Node-RED

We now want to tell Node-RED to move our camera to the left, when the left motion detection area (Area 1) is triggered, and to the right, in case of the right detection area (Area 4).

To make sure that our camera does not "get lost" following shadows or light reflections, we will first set preset position 1 in a sensible center position:

INSTAR MQTT Alarmserver and Node-RED

And tell our camera to return to this position (Park Position) after a reasonable amount of time:

INSTAR MQTT Alarmserver and Node-RED

Node-RED now needs a Subscription to the MQTT Status Topic status/alarm/triggered. As we have shown before, this topic receive an update with the value 1-4 if Area 1 to 4 are triggered.

When we receive a payload of {"val":"1"} we now know that the left area was triggered and we have to move to left. The same way a payload of {"val":"4"} means that we have to move one step to the right. The complete Node-RED Flow looks like this (see JSON export at the end of this article):

INSTAR MQTT Alarmserver and Node-RED

And here is the flow in action:

INSTAR MQTT Alarmserver and Node-RED

[
    {
        "id": "b3f2131d.c323e",
        "type": "mqtt in",
        "z": "c025b147.f6afb",
        "name": "Alarm Server",
        "topic": "instar/local/status/alarm/triggered",
        "qos": "1",
        "datatype": "auto",
        "broker": "996228fe.ababc8",
        "x": 90,
        "y": 620,
        "wires": [
            [
                "7e41db00.f5ed94"
            ]
        ]
    },
    {
        "id": "7e41db00.f5ed94",
        "type": "json",
        "z": "c025b147.f6afb",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 230,
        "y": 620,
        "wires": [
            [
                "da03fe2f.869de"
            ]
        ]
    },
    {
        "id": "da03fe2f.869de",
        "type": "switch",
        "z": "c025b147.f6afb",
        "name": "",
        "property": "payload.val",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 347,
        "y": 620,
        "wires": [
            [
                "682bc199.6b418"
            ],
            [
                "ec0056bc.645fa8"
            ]
        ]
    },
    {
        "id": "682bc199.6b418",
        "type": "change",
        "z": "c025b147.f6afb",
        "name": "Area 1 => Move Left",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"val\":\"left\"}",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 520,
        "y": 600,
        "wires": [
            [
                "5bbe46a4.047128"
            ]
        ]
    },
    {
        "id": "ec0056bc.645fa8",
        "type": "change",
        "z": "c025b147.f6afb",
        "name": "Area 4 => Move Right",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"val\":\"right\"}",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 520,
        "y": 640,
        "wires": [
            [
                "5bbe46a4.047128"
            ]
        ]
    },
    {
        "id": "5bbe46a4.047128",
        "type": "mqtt out",
        "z": "c025b147.f6afb",
        "name": "features/ptz/movestep",
        "topic": "instar/local/features/ptz/movestep",
        "qos": "1",
        "retain": "false",
        "broker": "996228fe.ababc8",
        "x": 740,
        "y": 620,
        "wires": []
    },
    {
        "id": "996228fe.ababc8",
        "type": "mqtt-broker",
        "z": "",
        "name": "INSTAR MQTT",
        "broker": "192.168.2.117",
        "port": "1883",
        "clientid": "iored",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]