Re-run different nodes at different times

Hi!

I have the following Flow created to login with an API and then fetch data from a second endpoint.

[
    {
        "id": "4d1f98b0.642758",
        "type": "http request",
        "z": "c155aa476d7d3fe2",
        "name": "/login",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://eu5.fusionsolar.huawei.com/thirdData/login",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 490,
        "y": 180,
        "wires": [
            [
                "9e0cdaf0c53abc05"
            ]
        ]
    },
    {
        "id": "62206b38.707924",
        "type": "function",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "func": "msg.headers = {}\nmsg.url = \"https://eu5.fusionsolar.huawei.com/thirdData/login\";\nmsg.headers[\"content-type\"] = \"application/json\"\n\n\nmsg.payload = {\n    \"userName\": \"API\",\n    \"systemCode\": \"1337\"\n}\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 180,
        "wires": [
            [
                "4d1f98b0.642758"
            ]
        ]
    },
    {
        "id": "fda2c97918f48fc3",
        "type": "inject",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 180,
        "wires": [
            [
                "62206b38.707924"
            ]
        ]
    },
    {
        "id": "0ce4ec69bf9d8b8a",
        "type": "debug",
        "z": "c155aa476d7d3fe2",
        "name": "debug msg",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1570,
        "y": 180,
        "wires": []
    },
    {
        "id": "9e0cdaf0c53abc05",
        "type": "function",
        "z": "c155aa476d7d3fe2",
        "name": "flow save token",
        "func": "flow.set('token', msg.headers[\"xsrf-token\"]);\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 660,
        "y": 180,
        "wires": [
            [
                "8d4abce006eb56da"
            ]
        ]
    },
    {
        "id": "7a3e4af0ea3ffca9",
        "type": "function",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "func": "msg.headers = {}\nmsg.url = \"https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi\";\nmsg.headers[\"content-type\"] = \"application/json\"\nmsg.headers[\"XSRF-TOKEN\"] = flow.get(\"token\");\n\nmsg.payload = {\n    \"devIds\": \"123\",\n    \"devTypeId\": \"1\"\n}\n\nnode.log(msg.payload);\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1020,
        "y": 180,
        "wires": [
            [
                "45bbc3580423f628"
            ]
        ]
    },
    {
        "id": "45bbc3580423f628",
        "type": "http request",
        "z": "c155aa476d7d3fe2",
        "name": "/getDevRealKpi",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1200,
        "y": 180,
        "wires": [
            [
                "0fdbf21d9218945b"
            ]
        ]
    },
    {
        "id": "f2fa10e69d612fbb",
        "type": "inject",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "token",
        "payloadType": "flow",
        "x": 840,
        "y": 220,
        "wires": [
            [
                "7a3e4af0ea3ffca9"
            ]
        ]
    },
    {
        "id": "8d4abce006eb56da",
        "type": "delay",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 840,
        "y": 180,
        "wires": [
            [
                "7a3e4af0ea3ffca9"
            ]
        ]
    },
    {
        "id": "0fdbf21d9218945b",
        "type": "json",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 1370,
        "y": 180,
        "wires": [
            [
                "0ce4ec69bf9d8b8a",
                "c91763435a1a9f49"
            ]
        ]
    },
    {
        "id": "c91763435a1a9f49",
        "type": "loxone-control-out",
        "z": "c155aa476d7d3fe2",
        "name": "Miniserver",
        "miniserver": "294f4e359f889cd9",
        "control": "",
        "x": 1530,
        "y": 300,
        "wires": []
    },
    {
        "id": "294f4e359f889cd9",
        "type": "loxone-miniserver",
        "host": "192.168.1.1",
        "port": "80",
        "enctype": "0",
        "active": true,
        "keepalive": "30000"
    }
]

What I dont understand is how I can schedule the /login http request every 4 hours but the getDevRealKpi should get called every 20 seconds as I need the response as UDP message.

Split your chain. Save the token from /login as a flow variable such as flow.token in one chain. Then in the second, call getDevRealKpi every 20 seconds but using the value of flow.token. You can call flow variables anywhere in the flow with a change node, or a function node like this flow.get("token", "memoryOnly")orflow.get("token", "file")

Don't forget to set the inject nodes to repeat on an interval so they fire at the right rates.

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