『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
12
返回列表 发新帖

[求助] 请问nodered中能不能将两个输出的消息合并?

[复制链接]

1

主题

30

帖子

885

积分

高级会员

Rank: 4

积分
885
金钱
855
HASS币
0
发表于 2023-4-14 06:57:11 | 显示全部楼层
[
    {
        "id": "1d46653.604e69b",
        "type": "tab",
        "label": "流程1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "b7d30c66.c3d7",
        "type": "inject",
        "z": "1d46653.604e69b",
        "name": "",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "开始",
        "payloadType": "str",
        "x": 90,
        "y": 40,
        "wires": [
            [
                "81f18e10.92c77",
                "7dfee0ca.464ad",
                "8b6a66ef.3f81b8"
            ]
        ]
    },
    {
        "id": "7dfee0ca.464ad",
        "type": "change",
        "z": "1d46653.604e69b",
        "name": "开机",
        "rules": [
            {
                "t": "set",
                "p": "payload1",
                "pt": "msg",
                "to": "001",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 290,
        "y": 40,
        "wires": [
            [
                "4849658d.b57eac"
            ]
        ]
    },
    {
        "id": "81f18e10.92c77",
        "type": "change",
        "z": "1d46653.604e69b",
        "name": "温度",
        "rules": [
            {
                "t": "set",
                "p": "payload3",
                "pt": "msg",
                "to": "003",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 290,
        "y": 160,
        "wires": [
            [
                "4849658d.b57eac"
            ]
        ]
    },
    {
        "id": "8b6a66ef.3f81b8",
        "type": "change",
        "z": "1d46653.604e69b",
        "name": "风速",
        "rules": [
            {
                "t": "set",
                "p": "payload2",
                "pt": "msg",
                "to": "002",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 290,
        "y": 100,
        "wires": [
            [
                "4849658d.b57eac"
            ]
        ]
    },
    {
        "id": "23b9d530.9a3e8a",
        "type": "debug",
        "z": "1d46653.604e69b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 520,
        "y": 320,
        "wires": []
    },
    {
        "id": "4849658d.b57eac",
        "type": "function",
        "z": "1d46653.604e69b",
        "name": "合并输出",
        "func": "//var ac =['0','0','0','0','0','0','0','0','0'];\n//var msg1 = { payload:msg.payload1 };\n//var msg2 = { payload:msg.payload2 };\n//var msg3 = { payload:msg.payload3 };\n//var msg4 = { payload:msg.payload4 };\n//var msg5 = { payload:msg.payload5 };\n//var msg6 = { payload:msg.payload6 };\n//var msg7 = { payload:msg.payload7 };\n//var msg8 = { payload:msg.payload8 };\n//var msg9 = { payload:msg.payload9 };\nvar ac =[];\n\nvar lst = [msg.payload1, msg.payload2,msg.payload3];\nvar s1 = lst.join(); \n//for (x in msg)\n//{\n//    data = s1+s1;\n    \n//}\nreturn { payload:s1};\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 100,
        "wires": [
            [
                "4f295d7f.a465f4"
            ]
        ]
    },
    {
        "id": "4f295d7f.a465f4",
        "type": "join",
        "z": "1d46653.604e69b",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "3",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 490,
        "y": 180,
        "wires": [
            [
                "c8ab7c03.2e19f",
                "23b9d530.9a3e8a"
            ]
        ]
    },
    {
        "id": "c8ab7c03.2e19f",
        "type": "function",
        "z": "1d46653.604e69b",
        "name": "参数转换",
        "func": "var data = ''\nfor (x in msg.payload) {\n    ms1 = msg.payload[x]\n    //for (y in ms1)     \n    //{      \n    //data = ms1.split(",")     \n    //}      \n    data = ms1.split(",")\n    if (data[0].length) { arr0 = data[0] }\n    if (data[1].length) { arr1 = data[1] }\n    if (data[2].length) { arr2 = data[2] }\n} var das = arr0 + arr1 + arr2;\n//var das= arr5  return { payload:das}; ",
        "outputs": 1,
        "noerr": 10,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 260,
        "wires": [
            [
                "23b9d530.9a3e8a"
            ]
        ]
    }
]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-24 20:34 , Processed in 0.167173 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表