当前位置:   article > 正文

Node-Red系列教程——NodeRed订阅opcua数据,并通过mqtt发布_node-red opcua

node-red opcua

目录

1.nodered 订阅opcua数据

2. nodered发布为mqtt

3. 部署运行结果,通过emqx接收数据

4. nodered的json代码


nodered搭配结果如下图:

1.nodered 订阅opcua数据

前言:opcua数据来自kepware模拟数据,具体nodered的OPCUA安装,mqtt安装参考下文使用kepware配置opcua服务端,并使用UaExpert作为opc客户端进行连接(匿名和用户名密码)_鲸鱼姐的博客-CSDN博客_kepware opc ua服务器配置

Node-Red系列——NodeRed通过OPC UA读取数据并写入mysql_鲸鱼姐的博客-CSDN博客

Node-Red系列——NodeRed创建mqtt broker(mqtt服务器),并使用mqttx进行消息发送验证_鲸鱼姐的博客-CSDN博客_mqttx 发送消息

(1)inject节点配置

(2)OPCUA-Item节点配置

(3)OPC client配置

action采用subscribe方式,Interval为1 second(s)  

注意订阅间隔的单位,可以为毫秒,秒,小时,分钟

2. nodered发布为mqtt

(1)function节点

将msg.topic作为device的键值,msg的payload作为value的键值。这样接收的mqtt端可以通过device进行设备区分。

  1. msg.payload = {
  2. 'device': msg.topic,
  3. 'value': msg.payload
  4. };
  5. return msg;

(2)mqtt out配置

配置服务端和主题

(3)debug节点

3. 部署运行结果,通过emqx接收数据

(1)nodered运行结果

(2) 运行mqtt服务端——emqx,接收nodered发送的mqtt消息

使用emqx的websocket客户端连接,并订阅plc/data主题

 订阅后,emqx可以收到nodered发出的mqtt消息

4. nodered的json代码

  1. [
  2. {
  3. "id": "b521b512ccf51472",
  4. "type": "tab",
  5. "label": "流程 3",
  6. "disabled": false,
  7. "info": "",
  8. "env": []
  9. },
  10. {
  11. "id": "a16131868eeaedda",
  12. "type": "OpcUa-Item",
  13. "z": "b521b512ccf51472",
  14. "item": "ns=2;s=通道 2.设备 1.tt1",
  15. "datatype": "Int32",
  16. "value": "",
  17. "name": "tt1",
  18. "x": 190,
  19. "y": 140,
  20. "wires": [
  21. [
  22. "ba7429bb4b39cf36"
  23. ]
  24. ]
  25. },
  26. {
  27. "id": "ba7429bb4b39cf36",
  28. "type": "OpcUa-Client",
  29. "z": "b521b512ccf51472",
  30. "endpoint": "058a91456e27a0bc",
  31. "action": "subscribe",
  32. "deadbandtype": "a",
  33. "deadbandvalue": 1,
  34. "time": "1",
  35. "timeUnit": "s",
  36. "certificate": "n",
  37. "localfile": "",
  38. "localkeyfile": "",
  39. "securitymode": "None",
  40. "securitypolicy": "None",
  41. "folderName4PKI": "",
  42. "name": "",
  43. "x": 380,
  44. "y": 120,
  45. "wires": [
  46. [
  47. "98aeb1313adf6976"
  48. ]
  49. ]
  50. },
  51. {
  52. "id": "702470447b1bbcbe",
  53. "type": "inject",
  54. "z": "b521b512ccf51472",
  55. "name": "",
  56. "props": [
  57. {
  58. "p": "payload"
  59. },
  60. {
  61. "p": "topic",
  62. "vt": "str"
  63. }
  64. ],
  65. "repeat": "",
  66. "crontab": "",
  67. "once": true,
  68. "onceDelay": 0.1,
  69. "topic": "",
  70. "payload": "",
  71. "payloadType": "str",
  72. "x": 50,
  73. "y": 120,
  74. "wires": [
  75. [
  76. "a16131868eeaedda",
  77. "efd47eaa4a986b84"
  78. ]
  79. ]
  80. },
  81. {
  82. "id": "0bd1292815c00b3a",
  83. "type": "mqtt out",
  84. "z": "b521b512ccf51472",
  85. "name": "mqtt out",
  86. "topic": "plc/data",
  87. "qos": "1",
  88. "retain": "",
  89. "respTopic": "",
  90. "contentType": "",
  91. "userProps": "",
  92. "correl": "",
  93. "expiry": "",
  94. "broker": "019d2a5c6d879e6a",
  95. "x": 620,
  96. "y": 220,
  97. "wires": []
  98. },
  99. {
  100. "id": "5116c26ea1dcb1e6",
  101. "type": "debug",
  102. "z": "b521b512ccf51472",
  103. "name": "debug 24",
  104. "active": false,
  105. "tosidebar": true,
  106. "console": true,
  107. "tostatus": true,
  108. "complete": "payload",
  109. "targetType": "msg",
  110. "statusVal": "payload",
  111. "statusType": "auto",
  112. "x": 630,
  113. "y": 300,
  114. "wires": []
  115. },
  116. {
  117. "id": "98aeb1313adf6976",
  118. "type": "function",
  119. "z": "b521b512ccf51472",
  120. "name": "function 10",
  121. "func": "msg.payload = {\n 'device': msg.topic,\n 'value': msg.payload\n};\nreturn msg;",
  122. "outputs": 1,
  123. "noerr": 0,
  124. "initialize": "",
  125. "finalize": "",
  126. "libs": [],
  127. "x": 430,
  128. "y": 220,
  129. "wires": [
  130. [
  131. "5116c26ea1dcb1e6",
  132. "0bd1292815c00b3a"
  133. ]
  134. ]
  135. },
  136. {
  137. "id": "efd47eaa4a986b84",
  138. "type": "OpcUa-Item",
  139. "z": "b521b512ccf51472",
  140. "item": "ns=2;s=通道 2.设备 1.tt2",
  141. "datatype": "Int32",
  142. "value": "",
  143. "name": "tt2",
  144. "x": 190,
  145. "y": 100,
  146. "wires": [
  147. [
  148. "ba7429bb4b39cf36"
  149. ]
  150. ]
  151. },
  152. {
  153. "id": "058a91456e27a0bc",
  154. "type": "OpcUa-Endpoint",
  155. "endpoint": "opc.tcp://192.168.31.88:49320",
  156. "secpol": "None",
  157. "secmode": "None",
  158. "none": true,
  159. "login": false,
  160. "usercert": false,
  161. "usercertificate": "",
  162. "userprivatekey": ""
  163. },
  164. {
  165. "id": "019d2a5c6d879e6a",
  166. "type": "mqtt-broker",
  167. "name": "",
  168. "broker": "127.0.0.1",
  169. "port": "1883",
  170. "clientid": "",
  171. "autoConnect": true,
  172. "usetls": false,
  173. "protocolVersion": "4",
  174. "keepalive": "60",
  175. "cleansession": true,
  176. "birthTopic": "",
  177. "birthQos": "0",
  178. "birthPayload": "",
  179. "birthMsg": {},
  180. "closeTopic": "",
  181. "closeQos": "0",
  182. "closePayload": "",
  183. "closeMsg": {},
  184. "willTopic": "",
  185. "willQos": "0",
  186. "willPayload": "",
  187. "willMsg": {},
  188. "userProps": "",
  189. "sessionExpiry": ""
  190. }
  191. ]

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/218040
推荐阅读
相关标签
  

闽ICP备14008679号