node-red-contrib-example-scada 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scada.html +34 -0
- package/scada.js +46 -2
package/package.json
CHANGED
package/scada.html
CHANGED
|
@@ -87,6 +87,27 @@
|
|
|
87
87
|
return this.name || '获取单个设备采集值'; // 如果有名称,则显示名称,否则显示默认名称
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
+
|
|
91
|
+
RED.nodes.registerType('获取系统状态', {
|
|
92
|
+
category: 'scada', // 节点类别
|
|
93
|
+
color: '#a6bbcf', // 节点颜色
|
|
94
|
+
defaults: {
|
|
95
|
+
broker: {
|
|
96
|
+
type: "http-broker",
|
|
97
|
+
required: true
|
|
98
|
+
},
|
|
99
|
+
name: {
|
|
100
|
+
value: ''
|
|
101
|
+
}, // 节点名称
|
|
102
|
+
|
|
103
|
+
},
|
|
104
|
+
inputs: 1, // 一个输入端口
|
|
105
|
+
outputs: 1, // 一个输出端口
|
|
106
|
+
icon: 'file.png', // 节点图标
|
|
107
|
+
label: function() { // 标签显示
|
|
108
|
+
return this.name || '获取系统状态'; // 如果有名称,则显示名称,否则显示默认名称
|
|
109
|
+
}
|
|
110
|
+
});
|
|
90
111
|
</script>
|
|
91
112
|
|
|
92
113
|
<script type="text/html" data-template-name="设备标签写入">
|
|
@@ -166,4 +187,17 @@
|
|
|
166
187
|
<label for="node-input-deviceCode"><i class="fa fa-cogs"></i> 设备号</label>
|
|
167
188
|
<input type="text" id="node-input-deviceCode" placeholder="Enter Device Code" class="node-input">
|
|
168
189
|
</div>
|
|
190
|
+
</script>
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
<script type="text/html" data-template-name="获取系统状态">
|
|
194
|
+
<div class="form-row">
|
|
195
|
+
<label for="node-input-broker"><i class="fa fa-globe"></i> 服务器</span></label>
|
|
196
|
+
<input type="text" id="node-input-broker">
|
|
197
|
+
</div>
|
|
198
|
+
<div class="form-row">
|
|
199
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> 名称</label>
|
|
200
|
+
<input type="text" id="node-input-name" placeholder="Node Name" class="node-input">
|
|
201
|
+
</div>
|
|
202
|
+
|
|
169
203
|
</script>
|
package/scada.js
CHANGED
|
@@ -90,7 +90,7 @@ module.exports = function(RED) {
|
|
|
90
90
|
RED.nodes.registerType("http-broker", RemoteServerNode);
|
|
91
91
|
|
|
92
92
|
//获取单个设备采集值配置
|
|
93
|
-
function
|
|
93
|
+
function GetDevice(config) {
|
|
94
94
|
RED.nodes.createNode(this, config);
|
|
95
95
|
var node = this;
|
|
96
96
|
|
|
@@ -140,6 +140,50 @@ module.exports = function(RED) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
// 注册自定义节点
|
|
143
|
-
RED.nodes.registerType("获取单个设备采集值",
|
|
143
|
+
RED.nodes.registerType("获取单个设备采集值", GetDevice);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
//获取系统状态
|
|
149
|
+
function GetSystemInfo(config) {
|
|
150
|
+
RED.nodes.createNode(this, config);
|
|
151
|
+
var node = this;
|
|
152
|
+
|
|
153
|
+
// 每次接收到消息时处理
|
|
154
|
+
this.on('input', function(msg) {
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
// 设置 API 请求的 URL
|
|
158
|
+
var broker = RED.nodes.getNode(config.broker);
|
|
159
|
+
var baseURL = "http://" + broker.host + ":" + broker.port + '/api/ScadaSystem/GetSystemInfo';
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
// 使用 axios 发送 GET 请求
|
|
163
|
+
axios.get(url)
|
|
164
|
+
.then(response => {
|
|
165
|
+
if (response.data.code == 200 && response.data.msg != "null") {
|
|
166
|
+
msg.payload = response.data;
|
|
167
|
+
node.send(msg);
|
|
168
|
+
node.status({ fill: "green", shape: "dot", text: "Success" });
|
|
169
|
+
|
|
170
|
+
} else {
|
|
171
|
+
node.status({ fill: "red", shape: "ring", text: "Error" });
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
.catch(error => {
|
|
175
|
+
// 请求失败,记录错误并将错误信息传递到下游节点
|
|
176
|
+
node.error("Request failed: " + error.message, msg);
|
|
177
|
+
msg.payload = { error: error.message };
|
|
178
|
+
node.status({ fill: "red", shape: "ring", text: "Error" });
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 注册自定义节点
|
|
187
|
+
RED.nodes.registerType("获取系统状态", GetSystemInfo);
|
|
144
188
|
|
|
145
189
|
};
|