node-red-contrib-symi-modbus 2.6.4 → 2.6.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/README.md +20 -15
- package/nodes/modbus-slave-switch.html +22 -2
- package/nodes/modbus-slave-switch.js +18 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -479,7 +479,7 @@ msg.payload = 1; // 或 0
|
|
|
479
479
|
|
|
480
480
|
## 项目信息
|
|
481
481
|
|
|
482
|
-
**版本**: v2.6.
|
|
482
|
+
**版本**: v2.6.5
|
|
483
483
|
|
|
484
484
|
**核心功能**:
|
|
485
485
|
- 支持多种Modbus协议(Telnet ASCII、RTU over TCP、Modbus TCP、Modbus RTU串口)
|
|
@@ -499,24 +499,29 @@ msg.payload = 1; // 或 0
|
|
|
499
499
|
- Node.js: >=14.0.0
|
|
500
500
|
- Node-RED: >=2.0.0
|
|
501
501
|
|
|
502
|
-
**最新更新(v2.6.
|
|
502
|
+
**最新更新(v2.6.5)**:
|
|
503
|
+
- **🔥 修复MQTT报错问题**:彻底解决未配置MQTT时的错误日志
|
|
504
|
+
- 从站开关节点新增"启用MQTT"勾选框
|
|
505
|
+
- 默认不启用MQTT,不会尝试连接
|
|
506
|
+
- 勾选后才显示MQTT服务器配置
|
|
507
|
+
- 不会在调试窗口产生任何MQTT错误日志
|
|
508
|
+
- **更好的用户体验**:
|
|
509
|
+
- 节点拖出即可使用(无需配置MQTT)
|
|
510
|
+
- 不再有烦人的错误提示
|
|
511
|
+
- 主站和从站开关均支持MQTT可选
|
|
512
|
+
- 本地模式和MQTT模式自由切换
|
|
513
|
+
|
|
514
|
+
**v2.6.4更新**:
|
|
503
515
|
- **🔥 日志优化**:大幅减少日志输出,保证长期稳定运行
|
|
504
|
-
- 高频操作日志改为debug
|
|
505
|
-
-
|
|
506
|
-
-
|
|
507
|
-
- 完善的内存清理机制,防止内存泄漏
|
|
508
|
-
- **适合工控机长期运行**:
|
|
509
|
-
- 无debug节点时不产生日志
|
|
510
|
-
- 不会因日志增加硬盘占用
|
|
511
|
-
- 不会因日志增加内存占用
|
|
512
|
-
- 断网/MQTT断开也不会持续报错
|
|
516
|
+
- 高频操作日志改为debug级别
|
|
517
|
+
- 默认不输出到日志文件
|
|
518
|
+
- 完善的内存清理机制
|
|
513
519
|
|
|
514
520
|
**v2.6.3更新**:
|
|
515
521
|
- **🔥 MQTT可选配置**:完全兼容无MQTT环境
|
|
516
|
-
-
|
|
517
|
-
- MQTT模式:可选接入
|
|
518
|
-
-
|
|
519
|
-
- 状态显示:清晰区分当前运行模式
|
|
522
|
+
- 本地模式:纯串口通信
|
|
523
|
+
- MQTT模式:可选接入HA
|
|
524
|
+
- 智能切换和状态显示
|
|
520
525
|
|
|
521
526
|
**性能优化**:
|
|
522
527
|
- 轮询间隔优化:修复间隔计算逻辑,确保每个从站使用正确的轮询间隔
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// RS-485连接配置(共享配置节点)
|
|
8
8
|
serialPortConfig: {value: "", type: "serial-port-config", required: true},
|
|
9
9
|
// MQTT配置(可选)
|
|
10
|
+
enableMqtt: {value: false}, // 默认不启用MQTT
|
|
10
11
|
mqttServer: {value: "", type: "mqtt-server-config", required: false},
|
|
11
12
|
// 开关面板配置
|
|
12
13
|
switchBrand: {value: "symi"}, // 品牌选择
|
|
@@ -24,6 +25,19 @@
|
|
|
24
25
|
// 显示时直接使用用户输入的路数(1-32)
|
|
25
26
|
const coilDisplay = this.targetCoilNumber || 1;
|
|
26
27
|
return this.name || `开关${this.switchId}-按钮${this.buttonNumber} → 继电器${this.targetSlaveAddress}-${coilDisplay}路`;
|
|
28
|
+
},
|
|
29
|
+
oneditprepare: function() {
|
|
30
|
+
// MQTT开关控制显示/隐藏
|
|
31
|
+
$("#node-input-enableMqtt").on("change", function() {
|
|
32
|
+
if ($(this).is(":checked")) {
|
|
33
|
+
$(".form-row-mqtt-slave").show();
|
|
34
|
+
} else {
|
|
35
|
+
$(".form-row-mqtt-slave").hide();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// 初始化显示状态
|
|
40
|
+
$("#node-input-enableMqtt").trigger("change");
|
|
27
41
|
}
|
|
28
42
|
});
|
|
29
43
|
</script>
|
|
@@ -64,13 +78,19 @@
|
|
|
64
78
|
<span style="margin-left: 8px; padding: 2px 8px; background: #e3f2fd; color: #1976d2; border-radius: 3px; font-size: 11px; font-weight: 500;">可选</span>
|
|
65
79
|
</label>
|
|
66
80
|
<div style="font-size: 11px; color: #555; padding: 10px 12px; background: linear-gradient(135deg, #e3f2fd 0%, #f0f7ff 100%); border-left: 4px solid #2196f3; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
|
|
67
|
-
<strong>💡 提示:</strong
|
|
81
|
+
<strong>💡 提示:</strong>不启用MQTT则使用<strong>本地模式</strong>(通过连线控制),启用MQTT则使用<strong>MQTT模式</strong>(可接入Home Assistant)
|
|
68
82
|
</div>
|
|
69
83
|
</div>
|
|
70
84
|
|
|
71
85
|
<div class="form-row">
|
|
86
|
+
<label for="node-input-enableMqtt" style="width: 110px;"><i class="fa fa-toggle-on"></i> 启用MQTT</label>
|
|
87
|
+
<input type="checkbox" id="node-input-enableMqtt" style="width: auto; margin-left: 5px; transform: scale(1.3); cursor: pointer;">
|
|
88
|
+
<span style="margin-left: 15px; font-size: 11px; color: #666; font-style: italic;">勾选后切换到MQTT模式</span>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
<div class="form-row form-row-mqtt-slave">
|
|
72
92
|
<label for="node-input-mqttServer" style="width: 110px;"><i class="fa fa-server"></i> MQTT服务器</label>
|
|
73
|
-
<input type="text" id="node-input-mqttServer" placeholder="
|
|
93
|
+
<input type="text" id="node-input-mqttServer" placeholder="选择MQTT服务器配置" style="width: calc(70% - 110px);">
|
|
74
94
|
<div style="font-size: 11px; color: #888; margin-left: 110px; margin-top: 3px;">
|
|
75
95
|
选择已配置的MQTT服务器(需与主站节点使用同一配置)
|
|
76
96
|
</div>
|
|
@@ -79,8 +79,9 @@ module.exports = function(RED) {
|
|
|
79
79
|
|
|
80
80
|
// 配置参数
|
|
81
81
|
node.config = {
|
|
82
|
-
//
|
|
83
|
-
|
|
82
|
+
// MQTT配置
|
|
83
|
+
enableMqtt: config.enableMqtt !== undefined ? config.enableMqtt : false, // 是否启用MQTT(默认false)
|
|
84
|
+
mqttBroker: node.mqttServerConfig ? node.mqttServerConfig.broker : "",
|
|
84
85
|
mqttUsername: node.mqttServerConfig ? node.mqttServerConfig.username : "",
|
|
85
86
|
mqttPassword: node.mqttServerConfig ? (node.mqttServerConfig.credentials ? node.mqttServerConfig.credentials.password : "") : "",
|
|
86
87
|
mqttBaseTopic: node.mqttServerConfig ? node.mqttServerConfig.baseTopic : "modbus/relay",
|
|
@@ -509,27 +510,27 @@ module.exports = function(RED) {
|
|
|
509
510
|
node.updateStatus = function() {
|
|
510
511
|
const rs485Status = node.isRs485Connected ? 'OK' : 'ERR';
|
|
511
512
|
const state = node.currentState ? 'ON' : 'OFF';
|
|
512
|
-
const
|
|
513
|
+
const mqttEnabled = node.config.enableMqtt === true;
|
|
513
514
|
const mqttConnected = node.mqttClient && node.mqttClient.connected;
|
|
514
515
|
|
|
515
516
|
// RS485连接正常
|
|
516
517
|
if (node.isRs485Connected) {
|
|
517
|
-
if (!
|
|
518
|
-
//
|
|
518
|
+
if (!mqttEnabled) {
|
|
519
|
+
// 本地模式(未启用MQTT)
|
|
519
520
|
node.status({
|
|
520
521
|
fill: node.currentState ? "green" : "blue",
|
|
521
522
|
shape: "dot",
|
|
522
|
-
text: `本地模式
|
|
523
|
+
text: `本地模式 ${state}`
|
|
523
524
|
});
|
|
524
525
|
} else if (mqttConnected) {
|
|
525
|
-
// MQTT
|
|
526
|
+
// MQTT模式(已启用且已连接)
|
|
526
527
|
node.status({
|
|
527
528
|
fill: node.currentState ? "green" : "grey",
|
|
528
529
|
shape: "dot",
|
|
529
530
|
text: `MQTT模式 ${state}`
|
|
530
531
|
});
|
|
531
532
|
} else {
|
|
532
|
-
// MQTT
|
|
533
|
+
// MQTT已启用但未连接(使用本地模式)
|
|
533
534
|
node.status({
|
|
534
535
|
fill: node.currentState ? "green" : "blue",
|
|
535
536
|
shape: "ring",
|
|
@@ -548,10 +549,17 @@ module.exports = function(RED) {
|
|
|
548
549
|
|
|
549
550
|
// 连接MQTT(带智能重试和fallback)
|
|
550
551
|
node.connectMqtt = function() {
|
|
552
|
+
// 检查是否启用MQTT
|
|
553
|
+
if (!node.config.enableMqtt) {
|
|
554
|
+
node.log('MQTT未启用 - 使用本地模式(通过Node-RED连线控制)');
|
|
555
|
+
node.log('提示:将此节点连线到主站节点,即可实现本地控制');
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
|
|
551
559
|
// 验证MQTT broker配置
|
|
552
560
|
if (!node.config.mqttBroker || node.config.mqttBroker.trim() === '') {
|
|
553
|
-
node.
|
|
554
|
-
node.
|
|
561
|
+
node.warn('MQTT已启用但broker地址未配置 - 使用本地模式');
|
|
562
|
+
node.warn('提示:请在MQTT服务器配置节点中设置broker地址,或禁用MQTT功能');
|
|
555
563
|
return;
|
|
556
564
|
}
|
|
557
565
|
|
package/package.json
CHANGED