【问题标题】:Strange MQTT message loop with node-red dashboard after network error网络错误后带有节点红色仪表板的奇怪 MQTT 消息循环
【发布时间】:2021-01-02 22:25:41
【问题描述】:

我有一个简单的灯控制器(在树莓上),它订阅 MQTT 消息“/floor1/terrace/lamps”,打开最多 9 个灯并通过“/floor1/terrace/lamps_r”发布新设置的模式。 此外,本地交换机也可能会更改此模式,因此会将其发布在“/floor1/terrace/lamps_r”上。该模式是一个数字,用于保存与灯输出相对应的位模式。

我想使用 node-red-dashboard 控制这些灯,并根据它们的当前状态更新它们,所以我创建了一个带有相应图案(月亮符号)的 ui-dropdown

流程接收“lamps_r”以在 ui-dropdown 上显示它(通过选定的消息传递)并在它更改为“lamps”时发送消息

这可以完美运行,但是在 mqtt 断开连接(中断或网络断开连接)之后,它会快速循环通过 ui-dropdown 中定义的模式。

这是流程

[
    {
        "id": "4ec0402f.174028",
        "type": "mqtt out",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "floor1/terrace/lamps",
        "qos": "0",
        "retain": "false",
        "broker": "26e8c216.d6cd06",
        "x": 900,
        "y": 200,
        "wires": []
    },
    {
        "id": "a6324306.af9eb8",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "incoming",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 320,
        "wires": []
    },
    {
        "id": "4097bb88.a6b6fc",
        "type": "ui_dropdown",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "label": "Lamps",
        "tooltip": "",
        "place": "Select option",
        "group": "83e0c62c.0828d8",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "multiple": false,
        "options": [
            {
                "label": "????????????????????????????????????",
                "value": 0,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 1,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 56,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 17,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 170,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 85,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 255,
                "type": "num"
            }
        ],
        "payload": "",
        "topic": "",
        "x": 510,
        "y": 200,
        "wires": [
            [
                "29bfc4ae.3bfd64"
            ]
        ]
    },
    {
        "id": "1592291a.25645f",
        "type": "mqtt in",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "floor1/terrace/lamps_r",
        "qos": "2",
        "datatype": "json",
        "broker": "26e8c216.d6cd06",
        "x": 320,
        "y": 200,
        "wires": [
            [
                "4097bb88.a6b6fc",
                "a6324306.af9eb8"
            ]
        ]
    },
    {
        "id": "123f5abc.e6551d",
        "type": "comment",
        "z": "f6f2187d.f17ca8",
        "name": "MQTT message propagation",
        "info": "the dropdown element only shows the received state if the message is passed through!\nTo avoid an endless cycle 'only_if_changed' filters the message propagation if the current state was changed already.",
        "x": 640,
        "y": 260,
        "wires": []
    },
    {
        "id": "7776ebb4.fafda4",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "outgoing",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 930,
        "y": 320,
        "wires": []
    },
    {
        "id": "29bfc4ae.3bfd64",
        "type": "rbe",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "property": "payload",
        "x": 670,
        "y": 200,
        "wires": [
            [
                "4ec0402f.174028",
                "7776ebb4.fafda4"
            ]
        ]
    },
    {
        "id": "26e8c216.d6cd06",
        "type": "mqtt-broker",
        "name": "Morpheus",
        "broker": "morpheus.lan",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "83e0c62c.0828d8",
        "type": "ui_group",
        "name": "Default",
        "tab": "c3af9807.77191",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "c3af9807.77191",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

我是 node-red 的新手,对可能发生的事情一无所知。

【问题讨论】:

    标签: mqtt dashboard node-red


    【解决方案1】:

    这不是关于为什么会出现无限循环的答案,但至少是一种可能对其他人有帮助的解决方法。

    当从回读 MQTT 对象中读取消息并在“过滤回读”中过滤消息时,我将属性“from_input”注入到消息中。这允许将读回的消息与 ui-dropdown 节点中的选择生成的消息区分开来:

    完整流程:

    [
        {
            "id": "4ec0402f.174028",
            "type": "mqtt out",
            "z": "f6f2187d.f17ca8",
            "name": "",
            "topic": "floor1/terrace/lamps",
            "qos": "0",
            "retain": "false",
            "broker": "26e8c216.d6cd06",
            "x": 1060,
            "y": 200,
            "wires": []
        },
        {
            "id": "a6324306.af9eb8",
            "type": "debug",
            "z": "f6f2187d.f17ca8",
            "name": "incoming",
            "active": false,
            "tosidebar": true,
            "console": false,
            "tostatus": false,
            "complete": "true",
            "targetType": "full",
            "statusVal": "",
            "statusType": "auto",
            "x": 620,
            "y": 260,
            "wires": []
        },
        {
            "id": "4097bb88.a6b6fc",
            "type": "ui_dropdown",
            "z": "f6f2187d.f17ca8",
            "name": "",
            "label": "Lamps",
            "tooltip": "",
            "place": "Select option",
            "group": "83e0c62c.0828d8",
            "order": 1,
            "width": 0,
            "height": 0,
            "passthru": true,
            "multiple": false,
            "options": [
                {
                    "label": "?????????",
                    "value": 0,
                    "type": "num"
                },
                {
                    "label": "?????????",
                    "value": 1,
                    "type": "num"
                },
                {
                    "label": "?????????",
                    "value": 56,
                    "type": "num"
                },
                {
                    "label": "?????????",
                    "value": 17,
                    "type": "num"
                },
                {
                    "label": "?????????",
                    "value": 170,
                    "type": "num"
                },
                {
                    "label": "?????????",
                    "value": 85,
                    "type": "num"
                },
                {
                    "label": "?????????",
                    "value": 255,
                    "type": "num"
                }
            ],
            "payload": "",
            "topic": "",
            "x": 610,
            "y": 200,
            "wires": [
                [
                    "8ff45087.04324"
                ]
            ]
        },
        {
            "id": "1592291a.25645f",
            "type": "mqtt in",
            "z": "f6f2187d.f17ca8",
            "name": "",
            "topic": "floor1/terrace/lamps_r",
            "qos": "2",
            "datatype": "json",
            "broker": "26e8c216.d6cd06",
            "x": 180,
            "y": 200,
            "wires": [
                [
                    "e756f46d.03854"
                ]
            ]
        },
        {
            "id": "7776ebb4.fafda4",
            "type": "debug",
            "z": "f6f2187d.f17ca8",
            "name": "outgoing",
            "active": false,
            "tosidebar": true,
            "console": false,
            "tostatus": false,
            "complete": "true",
            "targetType": "full",
            "statusVal": "",
            "statusType": "auto",
            "x": 1020,
            "y": 260,
            "wires": []
        },
        {
            "id": "e756f46d.03854",
            "type": "change",
            "z": "f6f2187d.f17ca8",
            "name": "",
            "rules": [
                {
                    "t": "set",
                    "p": "from_input",
                    "pt": "msg",
                    "to": "true",
                    "tot": "bool"
                }
            ],
            "action": "",
            "property": "",
            "from": "",
            "to": "",
            "reg": false,
            "x": 410,
            "y": 200,
            "wires": [
                [
                    "4097bb88.a6b6fc",
                    "a6324306.af9eb8"
                ]
            ]
        },
        {
            "id": "8ff45087.04324",
            "type": "function",
            "z": "f6f2187d.f17ca8",
            "name": "filter readback",
            "func": "if (!msg.hasOwnProperty('from_input'))\n    return msg;",
            "outputs": 1,
            "noerr": 0,
            "initialize": "",
            "finalize": "",
            "x": 800,
            "y": 200,
            "wires": [
                [
                    "7776ebb4.fafda4",
                    "4ec0402f.174028"
                ]
            ],
            "info": "check if 'from_input' is set, if not pass the message on"
        },
        {
            "id": "26e8c216.d6cd06",
            "type": "mqtt-broker",
            "name": "Morpheus",
            "broker": "morpheus.lan",
            "port": "1883",
            "clientid": "",
            "usetls": false,
            "compatmode": false,
            "keepalive": "60",
            "cleansession": true,
            "birthTopic": "",
            "birthQos": "0",
            "birthPayload": "",
            "closeTopic": "",
            "closeQos": "0",
            "closePayload": "",
            "willTopic": "",
            "willQos": "0",
            "willPayload": ""
        },
        {
            "id": "83e0c62c.0828d8",
            "type": "ui_group",
            "name": "Default",
            "tab": "c3af9807.77191",
            "order": 1,
            "disp": true,
            "width": "6",
            "collapse": false
        },
        {
            "id": "c3af9807.77191",
            "type": "ui_tab",
            "name": "Home",
            "icon": "dashboard",
            "disabled": false,
            "hidden": false
        }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多