Node-RED使用指南:15:使用switch进行多路输入和多路输出

在这里插入图片描述
这篇文章继续介绍通过具体的示例使用switch处理多路输入和多路输出的方法。

事前准备

以容器方式启动Node-RED服务,启动命令如下所示:

启动命令:docker run -it -p 1880:1880 -v $PWD/data:/data -e TZ=Asia/Shanghai --name nodered -d nodered/node-red:1.0.4

flow生成和设定

生成下图所示的flow
Node-RED使用指南:15:使用switch进行多路输入和多路输出_第1张图片

  • Inject节点:issue
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第2张图片

  • Inject节点:bug
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第3张图片

  • Inject节点:codeline
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第4张图片

  • switch节点:分支选择
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第5张图片

  • Debug节点:issue
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第6张图片

  • Debug节点:bug
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第7张图片

  • Debug节点:codeline
    Node-RED使用指南:15:使用switch进行多路输入和多路输出_第8张图片

结果确认

执行部署之后,分别手工触发三个Inject类型的输入节点,结果如下所示:
Node-RED使用指南:15:使用switch进行多路输入和多路输出_第9张图片

json格式的输出

[{"id":"bd397316.dd008","type":"inject","z":"73554227.4474dc","name":"issue:10","topic":"issue","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":340,"wires":[["4f9d5d85.cedb34"]]},{"id":"b9fa5ac6.eaa208","type":"inject","z":"73554227.4474dc","name":"bug:2","topic":"bug","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":420,"wires":[["4f9d5d85.cedb34"]]},{"id":"a64a71da.22b98","type":"inject","z":"73554227.4474dc","name":"codeline:1000","topic":"codeline","payload":"1000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":500,"wires":[["4f9d5d85.cedb34"]]},{"id":"4f9d5d85.cedb34","type":"switch","z":"73554227.4474dc","name":"分支选择","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"issue","vt":"str"},{"t":"eq","v":"bug","vt":"str"},{"t":"eq","v":"codeline","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":380,"y":420,"wires":[["1caeac40.cacba4"],["6d8c515d.203df"],["f8aea65c.5bb548"]]},{"id":"1caeac40.cacba4","type":"debug","z":"73554227.4474dc","name":"issue","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":340,"wires":[]},{"id":"6d8c515d.203df","type":"debug","z":"73554227.4474dc","name":"bug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":420,"wires":[]},{"id":"f8aea65c.5bb548","type":"debug","z":"73554227.4474dc","name":"codeline","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":500,"wires":[]}]

你可能感兴趣的:(#,Node-Red)