场景

Node-RED简介与Windows上安装、启动和运行示例:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/121884766

Node-RED的switch节点就是条件判断,可以依据条件来传递msg物件至不同的下一个节点。

例如:inject注入0和1,使用switch和change节点来分别输出成ON和OFF

 

 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、switch节点编辑

 

 

2、change节点编辑

 

 

3、流程转换的json数据

[{"id":"6ef823fa.ff781c","type":"inject","z":"34d4d5aa.c0d0ea","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":170,"y":80,"wires":[["45345f77.71a5f"]]},{"id":"90976eb6.0bc82","type":"inject","z":"34d4d5aa.c0d0ea","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":170,"y":180,"wires":[["45345f77.71a5f"]]},{"id":"45345f77.71a5f","type":"switch","z":"34d4d5aa.c0d0ea","name":"On or OFF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":140,"wires":[["60b9f22a.9acb4c"],["8e48a261.b465e"]]},{"id":"aa1452ff.c3ffa","type":"debug","z":"34d4d5aa.c0d0ea","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":80,"wires":[]},{"id":"de505863.01f448","type":"debug","z":"34d4d5aa.c0d0ea","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":200,"wires":[]},{"id":"60b9f22a.9acb4c","type":"change","z":"34d4d5aa.c0d0ea","name":"Set to ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":100,"wires":[["aa1452ff.c3ffa"]]},{"id":"8e48a261.b465e","type":"change","z":"34d4d5aa.c0d0ea","name":"Set to OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":200,"wires":[["de505863.01f448"]]}]

 

posted on 2022-04-13 21:34  霸道流氓  阅读(446)  评论(0编辑  收藏  举报