当前位置 : 主页 > 编程语言 > python >

Node-RED中使用function函式节点实现数值计算(相加计算)

来源:互联网 收集:自由互联 发布时间:2023-03-22
Node-RED中函式节点可以建立JavaScript函数来处理msg物件。 例如使用change节点指定x和y属性的值,然后使用function节点将x和y的值相加 并输出和。 注: 霸道的程序猿 获取编程相关电子书、

Node-RED中函式节点可以建立JavaScript函数来处理msg物件。

例如使用change节点指定x和y属性的值,然后使用function节点将x和y的值相加

并输出和。

Node-RED中使用function函式节点实现数值计算(相加计算)_json

注:

霸道的程序猿 获取编程相关电子书、教程推送与免费下载。

实现

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-RED中使用JSON数据建立web网站
下一篇:没有了
网友评论