Trigger node once at start

Hello,

I already tried to search in the forum for "trigger node at start" but wasnt able to solve my issue.

I have a node that reads MOBUS data and updates a flow.context.

The problem is, that when i restart my raspi, the flow.context will not be initalized, and further the flow.context is empty. So i have always trigger the node once manualy to get my program running.

Seems a bit complicated, because its hard to explain. But here is my simple flow. Hope it gets clear what i mean:

[
    {
        "id": "6657eb09941580e0",
        "type": "buffer-maker",
        "z": "41b5704d6704d5e1",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item",
                "type": "16bitbe",
                "length": 1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 470,
        "y": 140,
        "wires": [
            [
                "9d8d02b203c92447"
            ]
        ]
    },
    {
        "id": "9d8d02b203c92447",
        "type": "buffer-parser",
        "z": "41b5704d6704d5e1",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "decimal",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 470,
        "y": 180,
        "wires": [
            [
                "5ea7e6d442ecda2d"
            ]
        ]
    },
    {
        "id": "5ea7e6d442ecda2d",
        "type": "function",
        "z": "41b5704d6704d5e1",
        "name": "write_101",
        "func": "var fc = 6;\nvar sa = 100;\nvar addresses = 1;\nvar value = msg.payload.decimal;  // value calculated from buffer-parser\nmsg.slave_ip = \"10.240.6.39\";\n\nmsg.payload = { \"value\": value, 'fc': fc, 'unitid': 1, 'address': sa, 'quantity': addresses };\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 220,
        "wires": [
            [
                "2659bfcd276bf6cb"
            ]
        ]
    },
    {
        "id": "566e7bae2263114f",
        "type": "function",
        "z": "41b5704d6704d5e1",
        "name": "update ContextADR100",
        "func": "let ps = flow.get(\"ContextADR101\")\n\nps = [[ps.Remote_On_Off, ps.Deaerating, ps.AnalogueMode, ps.TimerMode, ps.SlowMode, ps.Velocity, false, false]]\n\nif (msg.topic === \"CIM500/W_Remote\") {\n    ps[0][0] = msg.payload\n}\nelse if (msg.topic === \"CIM500/W_Deaerating\") {\n    ps[0][1] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_AnalogMode\") {\n    ps[0][2] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_TimerMode\") {\n    ps[0][3] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_SlowMode\") {\n    ps[0][4] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_Velocity\") {\n    ps[0][5] = msg.payload;\n}\n\nmsg.payload = ps;\n\nreturn msg;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 510,
        "y": 100,
        "wires": [
            [
                "6657eb09941580e0"
            ]
        ]
    },
    {
        "id": "6a374d18466837e3",
        "type": "function",
        "z": "41b5704d6704d5e1",
        "name": "Read_101",
        "func": "msg.payload =\n{\n    value: msg.payload,\n    'fc': 3,\n    'unitid': 1,\n    'address': 100,\n    'quantity': 1\n\n};\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1230,
        "y": 140,
        "wires": [
            [
                "54f178b536270468"
            ]
        ]
    },
    {
        "id": "d69f3d76fe293483",
        "type": "inject",
        "z": "41b5704d6704d5e1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1220,
        "y": 100,
        "wires": [
            [
                "6a374d18466837e3"
            ]
        ]
    },
    {
        "id": "689647688d980a67",
        "type": "buffer-parser",
        "z": "41b5704d6704d5e1",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "bool",
                "name": "Remote_On_Off",
                "offset": 1,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "Deaerating",
                "offset": 1,
                "length": 1,
                "offsetbit": 1,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "AnalogueMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "TimerMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 3,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "SlowMode",
                "offset": 1,
                "length": 1,
                "offsetbit": 4,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "Velocity",
                "offset": 1,
                "length": 1,
                "offsetbit": 5,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 1230,
        "y": 220,
        "wires": [
            [
                "13fc57f6cfea5440"
            ]
        ]
    },
    {
        "id": "8b7b624610e80c33",
        "type": "debug",
        "z": "41b5704d6704d5e1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1470,
        "y": 260,
        "wires": []
    },
    {
        "id": "13fc57f6cfea5440",
        "type": "change",
        "z": "41b5704d6704d5e1",
        "name": "ContextADR101",
        "rules": [
            {
                "t": "set",
                "p": "ContextADR101",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1240,
        "y": 260,
        "wires": [
            [
                "8b7b624610e80c33"
            ]
        ]
    },
    {
        "id": "b899684c6e9e84ad",
        "type": "link out",
        "z": "41b5704d6704d5e1",
        "name": "link out 2",
        "mode": "link",
        "links": [
            "06101fa818c4b68a"
        ],
        "x": 885,
        "y": 260,
        "wires": []
    },
    {
        "id": "06101fa818c4b68a",
        "type": "link in",
        "z": "41b5704d6704d5e1",
        "name": "link in 2",
        "links": [
            "b899684c6e9e84ad"
        ],
        "x": 1015,
        "y": 140,
        "wires": [
            [
                "6a374d18466837e3"
            ]
        ]
    },
    {
        "id": "8e5f21347dec19bc",
        "type": "mqtt in",
        "z": "41b5704d6704d5e1",
        "name": "",
        "topic": "CIM500/W_Remote",
        "qos": "2",
        "datatype": "json",
        "broker": "3b168ddc20c96394",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 150,
        "y": 100,
        "wires": [
            [
                "566e7bae2263114f"
            ]
        ]
    },
    {
        "id": "a40bb42b56415ffe",
        "type": "mqtt in",
        "z": "41b5704d6704d5e1",
        "name": "",
        "topic": "CIM500/W_Deaerating",
        "qos": "2",
        "datatype": "json",
        "broker": "3b168ddc20c96394",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 140,
        "wires": [
            [
                "566e7bae2263114f"
            ]
        ]
    },
    {
        "id": "d0207977f0fe33a3",
        "type": "mqtt in",
        "z": "41b5704d6704d5e1",
        "name": "",
        "topic": "CIM500/W_AnalogMode",
        "qos": "2",
        "datatype": "json",
        "broker": "3b168ddc20c96394",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 180,
        "wires": [
            [
                "566e7bae2263114f"
            ]
        ]
    },
    {
        "id": "2081653186293316",
        "type": "mqtt in",
        "z": "41b5704d6704d5e1",
        "name": "",
        "topic": "CIM500/W_TimerMode",
        "qos": "2",
        "datatype": "json",
        "broker": "3b168ddc20c96394",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 220,
        "wires": [
            [
                "566e7bae2263114f"
            ]
        ]
    },
    {
        "id": "e1a7ec45fa2ee666",
        "type": "mqtt in",
        "z": "41b5704d6704d5e1",
        "name": "",
        "topic": "CIM500/W_SlowMode",
        "qos": "2",
        "datatype": "json",
        "broker": "3b168ddc20c96394",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 260,
        "wires": [
            [
                "566e7bae2263114f"
            ]
        ]
    },
    {
        "id": "955a0e5cc524f7d7",
        "type": "mqtt in",
        "z": "41b5704d6704d5e1",
        "name": "",
        "topic": "CIM500/W_Velocity",
        "qos": "2",
        "datatype": "json",
        "broker": "3b168ddc20c96394",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 150,
        "y": 300,
        "wires": [
            [
                "566e7bae2263114f"
            ]
        ]
    },
    {
        "id": "2659bfcd276bf6cb",
        "type": "modbus-flex-write",
        "z": "41b5704d6704d5e1",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": true,
        "server": "3c8dd0dd2a7c33cf",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 490,
        "y": 260,
        "wires": [
            [
                "b899684c6e9e84ad",
                "a78b7bf007d58563"
            ],
            []
        ]
    },
    {
        "id": "b13c138f8e78d23d",
        "type": "modbus-response",
        "z": "41b5704d6704d5e1",
        "name": "",
        "registerShowMax": 20,
        "x": 1490,
        "y": 180,
        "wires": []
    },
    {
        "id": "a78b7bf007d58563",
        "type": "modbus-response",
        "z": "41b5704d6704d5e1",
        "name": "",
        "registerShowMax": 20,
        "x": 710,
        "y": 260,
        "wires": []
    },
    {
        "id": "54f178b536270468",
        "type": "modbus-flex-getter",
        "z": "41b5704d6704d5e1",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "3c8dd0dd2a7c33cf",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 1260,
        "y": 180,
        "wires": [
            [
                "b13c138f8e78d23d",
                "689647688d980a67"
            ],
            []
        ]
    },
    {
        "id": "3b168ddc20c96394",
        "type": "mqtt-broker",
        "name": "",
        "broker": "185.164.7.227",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "3c8dd0dd2a7c33cf",
        "type": "modbus-client",
        "name": "CIM500/Rasp",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.1.2",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true,
        "showWarnings": true,
        "showLogs": true
    }
]

thank you

1 Like

Why not use persistent context?

Additionally / alternatively, use an inject node set to fire once at startup.

Thank you very much.

I had no idea, that it is possible to save with .conext persistent to the filesystem. I alwayse used
"write file" and "read file". Thank you for that

inject node solved it.

thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.