場景
Node-RED簡介與Windows上安裝、啟動和運行示例:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/121884766
Node-RED怎樣導出導入流程為json文件:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/124130985
Node-RED中函式節點可以建立JavaScript函數來處理msg物件。
例如使用change節點指定x和y屬性的值,然后使用function節點將x和y的值相加
並輸出和。
注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。
實現
1、編輯change節點,新增兩個設定操作
2、function節點配置,在函數列輸入JS代碼
msg.payload = msg.x + msg.y; return msg;
3、json數據
[{"id":"997333a8.03e08","type":"inject","z":"b7057587.2e51d8","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":160,"wires":[["339cfc81.711174"]]},{"id":"9bcbb391.04dd2","type":"function","z":"b7057587.2e51d8","name":"msg.payload = msg.x + msg.y","func":"msg.payload = msg.x + msg.y;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":160,"wires":[["f961b950.8c5de8"]]},{"id":"f961b950.8c5de8","type":"debug","z":"b7057587.2e51d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":240,"wires":[]},{"id":"339cfc81.711174","type":"change","z":"b7057587.2e51d8","name":"","rules":[{"t":"set","p":"x","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"y","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":160,"wires":[["9bcbb391.04dd2"]]}]