node-red-contrib-symi-modbus 2.7.0 → 2.7.3
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 +141 -110
- package/nodes/custom-protocol.html +276 -0
- package/nodes/custom-protocol.js +204 -0
- package/nodes/modbus-dashboard.html +396 -0
- package/nodes/modbus-dashboard.js +98 -0
- package/nodes/modbus-slave-switch.js +36 -32
- package/package.json +5 -3
|
@@ -691,55 +691,59 @@ module.exports = function(RED) {
|
|
|
691
691
|
node.mqttClient.on('error', (err) => {
|
|
692
692
|
// 连接失败,尝试下一个候选地址
|
|
693
693
|
const errorMsg = err.message || err.code || '连接失败';
|
|
694
|
-
node.warn(`MQTT连接错误: ${errorMsg} (broker: ${brokerUrl})`);
|
|
695
|
-
|
|
696
694
|
const now = Date.now();
|
|
695
|
+
|
|
696
|
+
// 使用日志限流,避免长期断网时产生垃圾日志
|
|
697
|
+
const shouldLogError = (now - node.lastMqttErrorLog) > node.errorLogInterval;
|
|
698
|
+
if (shouldLogError) {
|
|
699
|
+
node.debug(`MQTT连接错误: ${errorMsg} (broker: ${brokerUrl})`);
|
|
700
|
+
}
|
|
701
|
+
|
|
697
702
|
const timeSinceLastAttempt = now - lastConnectAttempt;
|
|
698
|
-
|
|
699
|
-
// 避免频繁重试(至少等待1
|
|
703
|
+
|
|
704
|
+
// 避免频繁重试(至少等待1秒)
|
|
700
705
|
if (timeSinceLastAttempt < 1000) {
|
|
701
706
|
setTimeout(() => {
|
|
702
707
|
tryNextBroker();
|
|
703
708
|
}, 1000);
|
|
704
709
|
return;
|
|
705
710
|
}
|
|
706
|
-
|
|
711
|
+
|
|
707
712
|
tryNextBroker();
|
|
708
|
-
|
|
713
|
+
|
|
709
714
|
function tryNextBroker() {
|
|
710
715
|
// 尝试下一个候选地址
|
|
711
716
|
currentCandidateIndex = (currentCandidateIndex + 1) % brokerCandidates.length;
|
|
712
717
|
const nextBroker = brokerCandidates[currentCandidateIndex];
|
|
713
|
-
|
|
718
|
+
|
|
714
719
|
// 如果回到第一个地址,说明所有地址都试过了
|
|
715
720
|
if (currentCandidateIndex === 0) {
|
|
716
721
|
// 判断是否是局域网IP配置(只有一个候选地址)
|
|
717
722
|
const isSingleIpConfig = brokerCandidates.length === 1;
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
node.
|
|
731
|
-
node.
|
|
732
|
-
node.
|
|
733
|
-
node.error('提示:如果Node-RED运行在Docker容器中,可能需要使用host.docker.internal或容器IP [此错误将在10分钟后再次显示]');
|
|
734
|
-
node.lastMqttErrorLog = now;
|
|
723
|
+
|
|
724
|
+
// 使用日志限流,避免长期断网时产生垃圾日志
|
|
725
|
+
const shouldLog = (now - node.lastMqttErrorLog) > node.errorLogInterval;
|
|
726
|
+
|
|
727
|
+
if (shouldLog) {
|
|
728
|
+
if (isSingleIpConfig) {
|
|
729
|
+
// 局域网IP配置失败,使用debug级别(不写入日志文件)
|
|
730
|
+
node.debug(`MQTT连接失败: ${errorMsg}`);
|
|
731
|
+
node.debug(`无法连接到MQTT broker: ${brokerCandidates[0]}`);
|
|
732
|
+
node.debug('请检查:1) MQTT broker是否在该地址运行 2) 网络是否连通 3) 端口是否正确');
|
|
733
|
+
} else {
|
|
734
|
+
// 多个fallback地址都失败,使用debug级别
|
|
735
|
+
node.debug(`MQTT错误: ${errorMsg}`);
|
|
736
|
+
node.debug(`所有MQTT broker候选地址都无法连接: ${brokerCandidates.join(', ')}`);
|
|
737
|
+
node.debug('请检查:1) MQTT broker是否运行 2) 网络连接是否正常 3) broker地址是否正确');
|
|
735
738
|
}
|
|
739
|
+
node.lastMqttErrorLog = now;
|
|
736
740
|
}
|
|
737
|
-
|
|
738
|
-
// 5
|
|
741
|
+
|
|
742
|
+
// 30秒后重试第一个地址(从5秒改为30秒,减少重试频率)
|
|
739
743
|
setTimeout(() => {
|
|
740
744
|
node.debug('重试连接MQTT broker...');
|
|
741
745
|
tryConnect(brokerCandidates[0]);
|
|
742
|
-
},
|
|
746
|
+
}, 30000);
|
|
743
747
|
} else {
|
|
744
748
|
node.debug(`尝试备用MQTT broker: ${nextBroker}`);
|
|
745
749
|
setTimeout(() => {
|
|
@@ -747,7 +751,7 @@ module.exports = function(RED) {
|
|
|
747
751
|
}, 500); // 快速尝试下一个地址
|
|
748
752
|
}
|
|
749
753
|
}
|
|
750
|
-
|
|
754
|
+
|
|
751
755
|
node.updateStatus();
|
|
752
756
|
});
|
|
753
757
|
|
|
@@ -758,16 +762,16 @@ module.exports = function(RED) {
|
|
|
758
762
|
node.mqttClient.on('offline', () => {
|
|
759
763
|
const now = Date.now();
|
|
760
764
|
const shouldLog = (now - node.lastMqttErrorLog) > node.errorLogInterval;
|
|
761
|
-
|
|
765
|
+
|
|
762
766
|
if (shouldLog) {
|
|
763
|
-
node.
|
|
767
|
+
node.debug('MQTT离线,正在尝试重连...');
|
|
764
768
|
node.lastMqttErrorLog = now;
|
|
765
769
|
}
|
|
766
|
-
|
|
770
|
+
|
|
767
771
|
// 尝试下一个候选地址
|
|
768
772
|
currentCandidateIndex = (currentCandidateIndex + 1) % brokerCandidates.length;
|
|
769
773
|
const nextBroker = brokerCandidates[currentCandidateIndex];
|
|
770
|
-
|
|
774
|
+
|
|
771
775
|
setTimeout(() => {
|
|
772
776
|
tryConnect(nextBroker);
|
|
773
777
|
}, 2000);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-symi-modbus",
|
|
3
|
-
"version": "2.7.
|
|
4
|
-
"description": "Node-RED Modbus节点,支持TCP/串口通信、串口自动搜索、多设备轮询、可选MQTT集成(支持纯本地模式和MQTT模式)、Home Assistant自动发现、HomeKit
|
|
3
|
+
"version": "2.7.3",
|
|
4
|
+
"description": "Node-RED Modbus节点,支持TCP/串口通信、串口自动搜索、多设备轮询、可选MQTT集成(支持纯本地模式和MQTT模式)、Home Assistant自动发现、HomeKit网桥、可视化控制看板、自定义协议转换和物理开关面板双向同步,工控机长期稳定运行",
|
|
5
5
|
"main": "nodes/modbus-master.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
"mqtt-server-config": "nodes/mqtt-server-config.js",
|
|
39
39
|
"serial-port-config": "nodes/serial-port-config.js",
|
|
40
40
|
"modbus-debug": "nodes/modbus-debug.js",
|
|
41
|
-
"homekit-bridge": "nodes/homekit-bridge.js"
|
|
41
|
+
"homekit-bridge": "nodes/homekit-bridge.js",
|
|
42
|
+
"modbus-dashboard": "nodes/modbus-dashboard.js",
|
|
43
|
+
"custom-protocol": "nodes/custom-protocol.js"
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
"dependencies": {
|