上文:HMI触屏网关-VISION如何与Modbus TCP从机通信-CSDN博客
1. Node-red启用HTTP监听
HTTP监听,用于模拟WebAPI服务端,接收WebAPI客户端GET请求。
启用HTTP监听服务,选择请求方式GET
;URL自定义,本示例设置为:/A
。
2. Node-red启用HTTP响应
HTTP响应,用于将请求响应的内容返回给WebAPI客户端。
将Node-red采集到的数据,通过函数节点
,封装成JSON格式,作为请求响应的内容,连接到HTTP响应
。本示例以DI1、DI2的状态值为例:
封装的JSON格式如下:
{
DI1:状态值,
DI2:状态值,
}
至此,Node-red已经设置完成!
[{"id":"85bd525c74ef55c1","type":"http in","z":"5b9fc35027b74a20","name":"","url":"/A","method":"get","upload":false,"swaggerDoc":"","x":290,"y":240,"wires":[["19cd94b6439ae3d1"]]},{"id":"f0a0b1ebb111c15d","type":"di","z":"5b9fc35027b74a20","name":"","index":"1","interval":false,"intervalValue":1000,"x":290,"y":280,"wires":[[]]},{"id":"e083f8f1ac57efe6","type":"di","z":"5b9fc35027b74a20","name":"","index":"2","interval":false,"intervalValue":1000,"x":290,"y":320,"wires":[[]]},{"id":"19cd94b6439ae3d1","type":"function","z":"5b9fc35027b74a20","name":"函数计算 14","func":"msg.payload = {\n DI1: global.get(\"DI_1\"),\n DI2: global.get(\"DI_2\")\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":240,"wires":[["81bd4f1b62646b79"]]},{"id":"81bd4f1b62646b79","type":"http response","z":"5b9fc35027b74a20","name":"","statusCode":"","headers":{},"x":630,"y":240,"wires":[]}]
3. VISION创建WebAPI设备
VISION选择WebAPI协议,填好WebAPI参数,如果连接正常,左下角会有绿色指示灯常亮。
4. VISION添加数据标签
点击编辑设备标签按钮,添加需要采集的WebAPI数据点标签。
至此,使用WebAPI协议通信的数据标签已经建立完成,接下来只需要将控件和数据标签绑定即可使用,详情参看下一章节:
此处为语雀内容卡片,点击链接查看:如何使用控件 · IOTRouter