Node-RED中使用function函式节点实现数值计算(相加计算)
作者:互联网
场景
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"]]}]
标签:Node,function,wires,false,name,payload,msg,函式,节点 来源: https://www.cnblogs.com/badaoliumangqizhi/p/16142329.html