Node-Red 学习

一、mqtt主题动态订阅

有这样一个需求,通过前端传过来一个主题,我们直接可以订阅它,而不是每次都需要通过更改MQTT in 节点中的主题,这样就可以实现前后端分离。

1.更改mqtt in 的action 为Dynamic subscribe (动态订阅)

2.配置动态订阅的输入参数

一共两个参数:action 和 topicaction控制是否订阅该主题subscribe表示订阅,unsubscribe表示取消订阅。topic表示订阅的主题

3.示例

[
    {
        "id": "983829ff436cd9a1",
        "type": "function",
        "z": "b637766791ca5afe",
        "name": "",
        "func": "// msg.topic=flow.get(\"mqttTheme\");\nmsg.action=\"subscribe\"\nmsg.topic=\"/iot/dev/864819052615505/t\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 380,
        "wires": [
            [
                "0fc6620a4f447a66"
            ]
        ]
    },
    {
        "id": "188fd27884263496",
        "type": "inject",
        "z": "b637766791ca5afe",
        "name": "",
        "props": [
            {
                "p": "payload.param",
                "v": "uart",
                "vt": "str"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 250,
        "y": 380,
        "wires": [
            [
                "983829ff436cd9a1"
            ]
        ]
    },
    {
        "id": "b74cb002076e94e0",
        "type": "debug",
        "z": "b637766791ca5afe",
        "name": "mqtt主题",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 380,
        "wires": []
    },
    {
        "id": "0fc6620a4f447a66",
        "type": "mqtt in",
        "z": "b637766791ca5afe",
        "name": "动态订阅",
        "topic": "",
        "qos": "0",
        "datatype": "auto",
        "broker": "4bcf89f15da95371",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 1,
        "x": 520,
        "y": 380,
        "wires": [
            [
                "b74cb002076e94e0"
            ]
        ]
    },
    {
        "id": "4bcf89f15da95371",
        "type": "mqtt-broker",
        "name": "",
        "broker": "127.0.0.1",
        "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": {},
        "sessionExpiry": ""
    }
]

二、登录密码设置,生成明文替换

node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" 密码

三、function函数节点关闭输出

在用function函数总会遇到多个输出的情况,有时根据情况不需要某个节点输出可以将msg设为null,该节点就不会输出

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小飞爱学习1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值