iobroker.sigenergy 1.2.5 → 1.3.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 +13 -0
- package/io-package.json +13 -13
- package/lib/modbus.js +257 -235
- package/lib/registers.js +1607 -185
- package/lib/statistics.js +272 -196
- package/main.js +639 -581
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -156,6 +156,15 @@ MIT License — Copyright (c) 2025 ioBroker Community
|
|
|
156
156
|
---
|
|
157
157
|
|
|
158
158
|
## Changelog
|
|
159
|
+
### 1.3.3 (2026-03-13)
|
|
160
|
+
* (ssbingo) Fix duplicate @param JSDoc warning caused by missing closing tag in modbus.js
|
|
161
|
+
|
|
162
|
+
### 1.3.2 (2026-03-13)
|
|
163
|
+
* (ssbingo) Code quality fixes: unused variables removed, JSDoc documentation completed, lexical declaration in switch-case fixed
|
|
164
|
+
|
|
165
|
+
### 1.3.0 (2026-03-13)
|
|
166
|
+
* (ssbingo) Multilingual documentation updated
|
|
167
|
+
|
|
159
168
|
### 1.2.5 (2026-03-12)
|
|
160
169
|
* (ssbingo) fixes
|
|
161
170
|
|
|
@@ -292,3 +301,7 @@ MIT License — Copyright (c) 2025 ioBroker Community
|
|
|
292
301
|
- 🇷🇺 [Документация на русском](doc/ru/README.md)
|
|
293
302
|
- 🇳🇱 [Nederlandse documentatie](doc/nl/README.md)
|
|
294
303
|
- 🇫🇷 [Documentation française](doc/fr/README.md)
|
|
304
|
+
- 🇮🇹 [Documentazione italiana](doc/it/README.md)
|
|
305
|
+
- 🇪🇸 [Documentación en español](doc/es/README.md)
|
|
306
|
+
- 🇵🇱 [Dokumentacja polska](doc/pl/README.md)
|
|
307
|
+
- 🇵🇹 [Documentação portuguesa](doc/pt/README.md)
|
package/io-package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "sigenergy",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.3",
|
|
5
5
|
"news": {
|
|
6
|
-
"1.
|
|
7
|
-
"en": "
|
|
8
|
-
"de": "
|
|
9
|
-
"ru": "
|
|
10
|
-
"pt": "
|
|
11
|
-
"nl": "
|
|
12
|
-
"fr": "
|
|
13
|
-
"it": "
|
|
14
|
-
"es": "
|
|
15
|
-
"pl": "
|
|
16
|
-
"uk": "
|
|
17
|
-
"zh-cn": "修复"
|
|
6
|
+
"1.3.3": {
|
|
7
|
+
"en": "Fix duplicate @param JSDoc warning caused by missing closing tag in modbus.js",
|
|
8
|
+
"de": "Doppelten @param JSDoc-Hinweis durch fehlendes schließendes Tag in modbus.js behoben",
|
|
9
|
+
"ru": "Исправлено дублирующее предупреждение @param JSDoc из-за отсутствующего закрывающего тега в modbus.js",
|
|
10
|
+
"pt": "Corrigido aviso JSDoc @param duplicado causado por tag de fechamento ausente em modbus.js",
|
|
11
|
+
"nl": "Dubbele @param JSDoc-waarschuwing verholpen door ontbrekend sluitend label in modbus.js",
|
|
12
|
+
"fr": "Correction de l'avertissement JSDoc @param en double causé par une balise fermante manquante dans modbus.js",
|
|
13
|
+
"it": "Corretto avviso JSDoc @param duplicato causato da tag di chiusura mancante in modbus.js",
|
|
14
|
+
"es": "Corregida advertencia JSDoc @param duplicada causada por etiqueta de cierre faltante en modbus.js",
|
|
15
|
+
"pl": "Poprawiono zduplikowane ostrzeżenie JSDoc @param spowodowane brakującym tagiem zamykającym w modbus.js",
|
|
16
|
+
"uk": "Виправлено дубльоване попередження JSDoc @param через відсутній закриваючий тег у modbus.js",
|
|
17
|
+
"zh-cn": "修复modbus.js中因缺少闭合标签导致的重复@param JSDoc警告"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"titleLang": {
|
package/lib/modbus.js
CHANGED
|
@@ -1,245 +1,267 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const ModbusRTU = require(
|
|
3
|
+
const ModbusRTU = require('modbus-serial');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* ModbusConnection - Handles Modbus TCP and Serial connections
|
|
7
7
|
* for Sigenergy solar systems
|
|
8
8
|
*/
|
|
9
9
|
class ModbusConnection {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param {object} config - Connection configuration
|
|
12
|
+
* @param {Function} logFn - Logging function
|
|
13
|
+
*/
|
|
14
|
+
constructor(config, logFn) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.log = logFn || console;
|
|
17
|
+
this.client = new ModbusRTU();
|
|
18
|
+
this.connected = false;
|
|
19
|
+
this.connecting = false;
|
|
20
|
+
this._reconnectTimer = null;
|
|
21
|
+
this._requestQueue = [];
|
|
22
|
+
this._processing = false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Connect to Modbus device
|
|
27
|
+
*
|
|
28
|
+
* @returns {Promise<boolean>} Resolves to true if connection succeeded, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
async connect() {
|
|
31
|
+
if (this.connecting) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
this.connecting = true;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
if (this.client.isOpen) {
|
|
38
|
+
await this.client.close();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.client = new ModbusRTU();
|
|
42
|
+
this.client.setTimeout(this.config.timeout || 5000);
|
|
43
|
+
|
|
44
|
+
if (this.config.connectionType === 'tcp') {
|
|
45
|
+
this.log.debug(`Connecting Modbus TCP to ${this.config.tcpHost}:${this.config.tcpPort}`);
|
|
46
|
+
const connectTimeout = this.config.timeout || 5000;
|
|
47
|
+
await Promise.race([
|
|
48
|
+
this.client.connectTCP(this.config.tcpHost, {
|
|
49
|
+
port: this.config.tcpPort || 502,
|
|
50
|
+
}),
|
|
51
|
+
new Promise((_, reject) =>
|
|
52
|
+
setTimeout(
|
|
53
|
+
() => reject(new Error(`TCP connection timeout after ${connectTimeout}ms`)),
|
|
54
|
+
connectTimeout,
|
|
55
|
+
),
|
|
56
|
+
),
|
|
57
|
+
]);
|
|
58
|
+
} else {
|
|
59
|
+
// Serial RTU
|
|
60
|
+
this.log.debug(`Connecting Modbus RTU on ${this.config.serialPort}`);
|
|
61
|
+
await this.client.connectRTUBuffered(this.config.serialPort, {
|
|
62
|
+
baudRate: this.config.serialBaudRate || 9600,
|
|
63
|
+
dataBits: this.config.serialDataBits || 8,
|
|
64
|
+
parity: this.config.serialParity || 'none',
|
|
65
|
+
stopBits: this.config.serialStopBits || 1,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.connected = true;
|
|
70
|
+
this.connecting = false;
|
|
71
|
+
this.log.info('Modbus connection established');
|
|
72
|
+
return true;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
this.connected = false;
|
|
75
|
+
this.connecting = false;
|
|
76
|
+
this.log.error(`Modbus connection failed: ${err.message}`);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Disconnect from Modbus device
|
|
83
|
+
*/
|
|
84
|
+
async disconnect() {
|
|
85
|
+
if (this._reconnectTimer) {
|
|
86
|
+
clearTimeout(this._reconnectTimer);
|
|
87
|
+
this._reconnectTimer = null;
|
|
88
|
+
}
|
|
89
|
+
if (this.client && this.client.isOpen) {
|
|
90
|
+
try {
|
|
91
|
+
await this.client.close();
|
|
92
|
+
} catch {
|
|
93
|
+
// ignore
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.connected = false;
|
|
97
|
+
this.log.info('Modbus disconnected');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Read input registers (function code 0x04)
|
|
102
|
+
*
|
|
103
|
+
* @param {number} slaveId - Slave address
|
|
104
|
+
* @param {number} address - Register start address
|
|
105
|
+
* @param {number} qty - Number of registers to read
|
|
106
|
+
* @returns {Promise<number[]>} Resolves with an array of register values
|
|
107
|
+
*/
|
|
108
|
+
async readInputRegisters(slaveId, address, qty) {
|
|
109
|
+
if (!this.connected) {
|
|
110
|
+
throw new Error('Not connected');
|
|
111
|
+
}
|
|
112
|
+
this.client.setID(slaveId);
|
|
113
|
+
const result = await this.client.readInputRegisters(address, qty);
|
|
114
|
+
return result.data;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Read holding registers (function code 0x03)
|
|
119
|
+
*
|
|
120
|
+
* @param {number} slaveId - Slave address
|
|
121
|
+
* @param {number} address - Register start address
|
|
122
|
+
* @param {number} qty - Number of registers to read
|
|
123
|
+
* @returns {Promise<number[]>} Resolves with an array of register values
|
|
124
|
+
*/
|
|
125
|
+
async readHoldingRegisters(slaveId, address, qty) {
|
|
126
|
+
if (!this.connected) {
|
|
127
|
+
throw new Error('Not connected');
|
|
128
|
+
}
|
|
129
|
+
this.client.setID(slaveId);
|
|
130
|
+
const result = await this.client.readHoldingRegisters(address, qty);
|
|
131
|
+
return result.data;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Write single register (function code 0x06)
|
|
136
|
+
*
|
|
137
|
+
* @param {number} slaveId - Slave address
|
|
138
|
+
* @param {number} address - Register address
|
|
139
|
+
* @param {number} value - Value to write
|
|
140
|
+
* @returns {Promise<void>} Resolves when the register has been written
|
|
141
|
+
*/
|
|
142
|
+
async writeSingleRegister(slaveId, address, value) {
|
|
143
|
+
if (!this.connected) {
|
|
144
|
+
throw new Error('Not connected');
|
|
145
|
+
}
|
|
146
|
+
this.client.setID(slaveId);
|
|
147
|
+
await this.client.writeRegister(address, value);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Write multiple registers (function code 0x10)
|
|
152
|
+
*
|
|
153
|
+
* @param {number} slaveId - Slave address
|
|
154
|
+
* @param {number} address - Start address
|
|
155
|
+
* @param {number[]} values - Values array
|
|
156
|
+
* @returns {Promise<void>} Resolves when all registers have been written
|
|
157
|
+
*/
|
|
158
|
+
async writeMultipleRegisters(slaveId, address, values) {
|
|
159
|
+
if (!this.connected) {
|
|
160
|
+
throw new Error('Not connected');
|
|
161
|
+
}
|
|
162
|
+
this.client.setID(slaveId);
|
|
163
|
+
await this.client.writeRegisters(address, values);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Test connection - used from admin
|
|
168
|
+
*
|
|
169
|
+
* @returns {Promise<{success: boolean, message: string}>} Result object with success flag and human-readable message
|
|
170
|
+
*/
|
|
171
|
+
async testConnection() {
|
|
172
|
+
try {
|
|
173
|
+
const wasConnected = this.connected;
|
|
174
|
+
if (!this.connected) {
|
|
175
|
+
const ok = await this.connect();
|
|
176
|
+
if (!ok) {
|
|
177
|
+
return { success: false, message: 'Connection failed - check host/port settings' };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Try reading plant system time as connectivity check
|
|
182
|
+
this.client.setID(247);
|
|
183
|
+
await this.client.readInputRegisters(30000, 2);
|
|
184
|
+
|
|
185
|
+
if (!wasConnected) {
|
|
186
|
+
await this.disconnect();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
success: true,
|
|
191
|
+
message: `Connection OK - Plant system time register accessible`,
|
|
192
|
+
};
|
|
193
|
+
} catch (err) {
|
|
194
|
+
this.connected = false;
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
message: `Connection test failed: ${err.message}`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Parse register value based on data type
|
|
204
|
+
*
|
|
205
|
+
* @param {number[]} rawData - Raw register data
|
|
206
|
+
* @param {string} type - Data type (U16, S16, U32, S32, U64, STRING)
|
|
207
|
+
* @param {number|null} gain - Scaling factor
|
|
208
|
+
* @returns {number|string} Parsed and optionally scaled register value; string for STRING type
|
|
209
|
+
*/
|
|
210
|
+
static parseValue(rawData, type, gain) {
|
|
211
|
+
let raw;
|
|
212
|
+
|
|
213
|
+
switch (type) {
|
|
214
|
+
case 'U16':
|
|
215
|
+
raw = rawData[0];
|
|
216
|
+
break;
|
|
217
|
+
case 'S16':
|
|
218
|
+
raw = rawData[0];
|
|
219
|
+
if (raw > 32767) {
|
|
220
|
+
raw -= 65536;
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
case 'U32':
|
|
224
|
+
raw = (rawData[0] << 16) | rawData[1];
|
|
225
|
+
raw = raw >>> 0; // ensure unsigned
|
|
226
|
+
break;
|
|
227
|
+
case 'S32':
|
|
228
|
+
raw = (rawData[0] << 16) | rawData[1];
|
|
229
|
+
if (raw > 2147483647) {
|
|
230
|
+
raw -= 4294967296;
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
case 'U64':
|
|
234
|
+
// JavaScript can't handle 64-bit integers precisely, use approximation
|
|
235
|
+
raw =
|
|
236
|
+
rawData[0] * Math.pow(2, 48) +
|
|
237
|
+
rawData[1] * Math.pow(2, 32) +
|
|
238
|
+
rawData[2] * Math.pow(2, 16) +
|
|
239
|
+
rawData[3];
|
|
240
|
+
break;
|
|
241
|
+
case 'STRING': {
|
|
242
|
+
// Each register holds 2 ASCII chars
|
|
243
|
+
let str = '';
|
|
244
|
+
for (let i = 0; i < rawData.length; i++) {
|
|
245
|
+
const high = (rawData[i] >> 8) & 0xff;
|
|
246
|
+
const low = rawData[i] & 0xff;
|
|
247
|
+
if (high !== 0) {
|
|
248
|
+
str += String.fromCharCode(high);
|
|
249
|
+
}
|
|
250
|
+
if (low !== 0) {
|
|
251
|
+
str += String.fromCharCode(low);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return str.trim();
|
|
255
|
+
}
|
|
256
|
+
default:
|
|
257
|
+
raw = rawData[0];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (gain && gain !== 1 && gain !== null) {
|
|
261
|
+
return raw / gain;
|
|
262
|
+
}
|
|
263
|
+
return raw;
|
|
264
|
+
}
|
|
243
265
|
}
|
|
244
266
|
|
|
245
267
|
module.exports = ModbusConnection;
|