1. 程式人生 > 其它 >Node-RED中change更改節點與switch分支節點的使用

Node-RED中change更改節點與switch分支節點的使用

場景

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"]]}]