边缘网关对接
大约 4 分钟edgefeature
边缘计算介绍
Node-RED 是一个基于流的开发工具,用于可视化地连接硬件设备、API 和在线服务,作为物联网组件不可或缺的一部分。
- 可视化编程:Node-RED 提供了一个基于浏览器的流式编辑器,支持将节点拖放到画布上,连接各种设备、服务和API。
- 丰富的节点库:社区贡献了大量的节点, 可在线直接下载安装,也可轻松地自定义扩展功能。
- 轻松集成:支持多种通信协议,如 HTTP, WebSocket, MQTT, TCP, MODBUS, PLC 等,方便与其他系统集成。
- 运用广泛:商业化的硬件边缘网关大部分已内置Node-Red服务,安全可靠,值得信赖。
一、创建边缘网关数据
- 登录物联网平台,选择【边缘计算】>【边缘网关】,进入边缘网关页面。
- 点击【新增】,填写边缘网关名称、边缘网关描述等信息,点击【保存】即可创建边缘网关。
- 保存成功后会弹出确认框提示是否打开边缘网关详情页,点击【确定】即可自动跳转开始正式设计。
二、边缘网关数据配置
- 为了方便大家快速集成,可直接复制以下json配置进行导入。
[
{
"id": "fb78bee53fb30c0f",
"type": "function",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "转换为IOT数据格式",
"func": "let payload = msg.payload;\nlet timestamp = new Date().getTime();\n\n// 生成一个0-10之间的随机数 \nlet randomNumber = Math.floor(Math.random() * 10); \nlet a = payload.a + randomNumber;\nlet b = payload.b + randomNumber;\nlet c = payload.c;\n\nmsg.payload = {\n id: timestamp,\n version: \"1.0\",\n params: {\n Brightness: a,\n BatteryLevel: b,\n AlarmSwitch: c,\n }\n};\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 810,
"y": 260,
"wires": [
[
"dbed4aca40a0915e"
]
]
},
{
"id": "dbed4aca40a0915e",
"type": "mqtt out",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "发布MQTT消息",
"topic": "/blade/custom/dwi0gke0xo1t/dwi2gcnb6pz5/battery/post",
"qos": "2",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f4ea06209ab9d6e9",
"x": 1040,
"y": 260,
"wires": []
},
{
"id": "0805515171255d8d",
"type": "debug",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "mqtt消息",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 420,
"wires": []
},
{
"id": "ab4f151c965c6d1a",
"type": "mqtt in",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "订阅MQTT消息",
"topic": "/blade/custom/dwi0gke0xo1t/dwi2gcnb6pz5/battery/post",
"qos": "2",
"datatype": "auto-detect",
"broker": "f4ea06209ab9d6e9",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 480,
"y": 420,
"wires": [
[
"0805515171255d8d"
]
]
},
{
"id": "9776e94edd32316f",
"type": "template",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "发送数据",
"field": "payload",
"fieldType": "msg",
"format": "json",
"syntax": "plain",
"template": "{\n \"a\": 60,\n \"b\": 10,\n \"c\": 1\n}",
"output": "str",
"x": 400,
"y": 260,
"wires": [
[
"869bb060333e1a86"
]
]
},
{
"id": "17cf7d56.9efb03",
"type": "inject",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "点击触发",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 240,
"y": 260,
"wires": [
[
"9776e94edd32316f"
]
]
},
{
"id": "869bb060333e1a86",
"type": "json",
"z": "67fb6781bc41cf1bb8159a38ab9c85d7",
"name": "转换为JSON格式",
"property": "payload",
"action": "",
"pretty": false,
"x": 590,
"y": 260,
"wires": [
[
"fb78bee53fb30c0f"
]
]
},
{
"id": "f4ea06209ab9d6e9",
"type": "mqtt-broker",
"name": "本机",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]
- 导入配置后进行部署,然后再点击重启流程,即可开始正式运行。
- 将数据设置为定时1秒上传,mqtt的topic为自定义topic,部署后可以看到数据已经成功上传,并且在实时更新。
注意⚠️:若不采用设备加密参数连接mqtt服务器,则需要先前往【MQTT管理】>【MQTT账号】,新增账号密码后才可进行认证连接。
三、边缘网关解析不同协议
- 在边缘网关中,可以通过不同的节点来解析不同的协议,如HTTP、WebSocket、MQTT、TCP、MODBUS、PLC等。
- 系统已默认做了TCP与MODBUS的解析,用户可根据实际需求自定义解析节点,方便与其他系统集成。
- 具体功能测试可看演示站的操作流程。
四、后记
- 边缘网关的数据解析功能非常强大,用户可以根据实际需求自定义解析节点,方便与其他系统集成。
- 通过边缘网关的数据解析功能,用户可以实现设备数据的实时上传,实现设备数据的实时监控。
- 在此之前推荐大家多学习一下Node-Red的基础节点操作,相信熟悉后会对边缘网关的数据解析功能有更深入的理解。