一、mqtt主题动态订阅
有这样一个需求,通过前端传过来一个主题,我们直接可以订阅它,而不是每次都需要通过更改MQTT in 节点中的主题,这样就可以实现前后端分离。
1.更改mqtt in 的action 为Dynamic subscribe (动态订阅)
2.配置动态订阅的输入参数
一共两个参数:action 和 topic
action控制是否订阅该主题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,该节点就不会输出