@enyo-energy/sunspec-sdk 0.0.92 → 0.0.94
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/dist/cjs/sunspec-interfaces.d.cts +20 -0
- package/dist/cjs/sunspec-modbus-client.cjs +47 -6
- package/dist/cjs/sunspec-modbus-client.d.cts +19 -5
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-interfaces.d.ts +20 -0
- package/dist/sunspec-modbus-client.d.ts +19 -5
- package/dist/sunspec-modbus-client.js +47 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -16,6 +16,26 @@ export interface IRetryConfig {
|
|
|
16
16
|
phases: IRetryPhase[];
|
|
17
17
|
}
|
|
18
18
|
export declare const DEFAULT_RETRY_CONFIG: IRetryConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Pacing configuration for the Modbus client. Both options are opt-in and default off, so existing
|
|
21
|
+
* consumers are unaffected. The fields mirror the SDK's `ModbusOptions` and are passed straight
|
|
22
|
+
* through to `useModbus().connect()` — the SDK owns the serialization; the client only forwards the
|
|
23
|
+
* config it was constructed with. Omitted fields leave the SDK to apply its own defaults
|
|
24
|
+
* (`noParallelRequests` false, `waitBetweenMessagesMs` 0). Intended for slow devices (e.g. Solax)
|
|
25
|
+
* that choke when frames arrive back-to-back.
|
|
26
|
+
*/
|
|
27
|
+
export interface IModbusPacingConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Serialize reads and writes on the connection through the SDK's internal operation chain so
|
|
30
|
+
* frames don't interleave (SDK `ModbusOptions.noParallelRequests`). Default false.
|
|
31
|
+
*/
|
|
32
|
+
noParallelRequests?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Minimum ms to wait between two consecutive frames. Only honoured when `noParallelRequests` is
|
|
35
|
+
* true (SDK `ModbusOptions.waitBetweenMessagesMs`). Default 0.
|
|
36
|
+
*/
|
|
37
|
+
waitBetweenMessagesMs?: number;
|
|
38
|
+
}
|
|
19
39
|
/**
|
|
20
40
|
* Base interface for all SunSpec blocks
|
|
21
41
|
*/
|
|
@@ -34,12 +34,16 @@ const registryKey = (host, port) => `${host}:${port}`;
|
|
|
34
34
|
/**
|
|
35
35
|
* Get (or create) the singleton SunspecModbusClient for this network device.
|
|
36
36
|
* Increments the refcount; pair with `releaseSunspecClient` on teardown.
|
|
37
|
+
*
|
|
38
|
+
* NOTE: `pacing` is only applied when the client is FIRST created for a given host:port.
|
|
39
|
+
* Because the client is cached and refcounted, a later caller passing a different `pacing`
|
|
40
|
+
* receives the already-created instance and its config is ignored.
|
|
37
41
|
*/
|
|
38
|
-
function getOrCreateSunspecClient(energyApp, host, port = 502) {
|
|
42
|
+
function getOrCreateSunspecClient(energyApp, host, port = 502, pacing) {
|
|
39
43
|
const key = registryKey(host, port);
|
|
40
44
|
let entry = CLIENT_REGISTRY.get(key);
|
|
41
45
|
if (!entry) {
|
|
42
|
-
entry = { client: new SunspecModbusClient(energyApp), refcount: 0 };
|
|
46
|
+
entry = { client: new SunspecModbusClient(energyApp, pacing), refcount: 0 };
|
|
43
47
|
CLIENT_REGISTRY.set(key, entry);
|
|
44
48
|
}
|
|
45
49
|
entry.refcount++;
|
|
@@ -79,6 +83,7 @@ async function releaseSunspecClient(host, port = 502) {
|
|
|
79
83
|
}
|
|
80
84
|
class SunspecModbusClient {
|
|
81
85
|
energyApp;
|
|
86
|
+
pacing;
|
|
82
87
|
// Per-unit Modbus instance/reader/discovered-models maps. One client = one network device,
|
|
83
88
|
// many unit IDs share that client (each unit ID is one EnergyAppModbusInstance underneath).
|
|
84
89
|
modbusInstances = new Map();
|
|
@@ -111,8 +116,13 @@ class SunspecModbusClient {
|
|
|
111
116
|
// operationChain (the connection lock) to avoid re-entrancy: a transaction never waits
|
|
112
117
|
// on a connect/disconnect, and vice versa.
|
|
113
118
|
txChains = new Map();
|
|
114
|
-
constructor(energyApp
|
|
119
|
+
constructor(energyApp,
|
|
120
|
+
// Opt-in pacing (default off). Passed straight through to `useModbus().connect()`, which
|
|
121
|
+
// serializes frames (`noParallelRequests`) and spaces them (`waitBetweenMessagesMs`) on the
|
|
122
|
+
// connection. An empty object leaves both undefined so the SDK applies its own defaults.
|
|
123
|
+
pacing = {}) {
|
|
115
124
|
this.energyApp = energyApp;
|
|
125
|
+
this.pacing = pacing;
|
|
116
126
|
this.connectionHealth = new EnergyAppModbusConnectionHealth_js_1.EnergyAppModbusConnectionHealth();
|
|
117
127
|
this.modbusDataTypeConverter = new EnergyAppModbusDataTypeConverter_js_1.EnergyAppModbusDataTypeConverter();
|
|
118
128
|
}
|
|
@@ -126,8 +136,12 @@ class SunspecModbusClient {
|
|
|
126
136
|
* @param unitId Modbus unit ID (default 1)
|
|
127
137
|
* @param secondaryHost Optional secondary host (ipAddress) for fallback during reconnection
|
|
128
138
|
* @param useTls Whether to use TLS/SSL for the Modbus connection (Modbus Security, typically port 802). Defaults to false.
|
|
139
|
+
* @param tls Optional TLS certificate material for mutual-TLS / custom-CA connections. Only
|
|
140
|
+
* honoured when {@link useTls} is true. `cert`/`key` present a client certificate,
|
|
141
|
+
* `ca` supplies trusted CA certificate(s), and `rejectUnauthorized` controls whether an
|
|
142
|
+
* unverifiable server certificate is rejected.
|
|
129
143
|
*/
|
|
130
|
-
async connect(host, port = 502, unitId = 1, secondaryHost, useTls) {
|
|
144
|
+
async connect(host, port = 502, unitId = 1, secondaryHost, useTls, tls) {
|
|
131
145
|
return this.withConnectionLock(async () => {
|
|
132
146
|
if (this.connectionParams) {
|
|
133
147
|
if (this.connectionParams.primaryHost !== host || this.connectionParams.port !== port) {
|
|
@@ -140,9 +154,30 @@ class SunspecModbusClient {
|
|
|
140
154
|
if (useTls !== undefined) {
|
|
141
155
|
this.connectionParams.useTls = useTls;
|
|
142
156
|
}
|
|
157
|
+
if (tls?.cert !== undefined) {
|
|
158
|
+
this.connectionParams.cert = tls.cert;
|
|
159
|
+
}
|
|
160
|
+
if (tls?.key !== undefined) {
|
|
161
|
+
this.connectionParams.key = tls.key;
|
|
162
|
+
}
|
|
163
|
+
if (tls?.ca !== undefined) {
|
|
164
|
+
this.connectionParams.ca = tls.ca;
|
|
165
|
+
}
|
|
166
|
+
if (tls?.rejectUnauthorized !== undefined) {
|
|
167
|
+
this.connectionParams.rejectUnauthorized = tls.rejectUnauthorized;
|
|
168
|
+
}
|
|
143
169
|
}
|
|
144
170
|
else {
|
|
145
|
-
this.connectionParams = {
|
|
171
|
+
this.connectionParams = {
|
|
172
|
+
primaryHost: host,
|
|
173
|
+
secondaryHost,
|
|
174
|
+
port,
|
|
175
|
+
useTls,
|
|
176
|
+
cert: tls?.cert,
|
|
177
|
+
key: tls?.key,
|
|
178
|
+
ca: tls?.ca,
|
|
179
|
+
rejectUnauthorized: tls?.rejectUnauthorized,
|
|
180
|
+
};
|
|
146
181
|
}
|
|
147
182
|
this.knownUnits.add(unitId);
|
|
148
183
|
if (this.modbusInstances.has(unitId)) {
|
|
@@ -289,7 +324,13 @@ class SunspecModbusClient {
|
|
|
289
324
|
port,
|
|
290
325
|
unitId,
|
|
291
326
|
timeout: 5000,
|
|
292
|
-
useTls: this.connectionParams?.useTls
|
|
327
|
+
useTls: this.connectionParams?.useTls,
|
|
328
|
+
cert: this.connectionParams?.cert,
|
|
329
|
+
key: this.connectionParams?.key,
|
|
330
|
+
ca: this.connectionParams?.ca,
|
|
331
|
+
rejectUnauthorized: this.connectionParams?.rejectUnauthorized,
|
|
332
|
+
noParallelRequests: this.pacing.noParallelRequests,
|
|
333
|
+
waitBetweenMessagesMs: this.pacing.waitBetweenMessagesMs
|
|
293
334
|
});
|
|
294
335
|
if (!candidate) {
|
|
295
336
|
throw new Error(`useModbus().connect returned null for ${host}:${port} unit ${unitId}`);
|
|
@@ -16,15 +16,19 @@
|
|
|
16
16
|
* - pad: 0x8000 (always returns this value)
|
|
17
17
|
* - string: all registers 0x0000 (NULL)
|
|
18
18
|
*/
|
|
19
|
-
import { type SunspecInverterControls, type SunspecInverterData, type SunspecInverterSettings, type SunspecMeterData, type SunspecModel, type SunspecMPPTData, type SunspecBatteryData, type SunspecBatteryBaseData, type SunspecBatteryControls, SunspecStorageMode } from "./sunspec-interfaces.cjs";
|
|
19
|
+
import { type SunspecInverterControls, type SunspecInverterData, type SunspecInverterSettings, type SunspecMeterData, type SunspecModel, type SunspecMPPTData, type SunspecBatteryData, type SunspecBatteryBaseData, type SunspecBatteryControls, SunspecStorageMode, type IModbusPacingConfig } from "./sunspec-interfaces.cjs";
|
|
20
20
|
import { EnergyAppModbusDataType, IConnectionHealth } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/interfaces.js";
|
|
21
21
|
import { EnergyAppModbusInstance } from "@enyo-energy/energy-app-sdk/dist/packages/energy-app-modbus.js";
|
|
22
22
|
import { EnergyApp } from "@enyo-energy/energy-app-sdk";
|
|
23
23
|
/**
|
|
24
24
|
* Get (or create) the singleton SunspecModbusClient for this network device.
|
|
25
25
|
* Increments the refcount; pair with `releaseSunspecClient` on teardown.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: `pacing` is only applied when the client is FIRST created for a given host:port.
|
|
28
|
+
* Because the client is cached and refcounted, a later caller passing a different `pacing`
|
|
29
|
+
* receives the already-created instance and its config is ignored.
|
|
26
30
|
*/
|
|
27
|
-
export declare function getOrCreateSunspecClient(energyApp: EnergyApp, host: string, port?: number): SunspecModbusClient;
|
|
31
|
+
export declare function getOrCreateSunspecClient(energyApp: EnergyApp, host: string, port?: number, pacing?: IModbusPacingConfig): SunspecModbusClient;
|
|
28
32
|
/**
|
|
29
33
|
* Release a refcount on the network-device client. When the last consumer releases,
|
|
30
34
|
* the client is fully disconnected (all units closed) and removed from the registry.
|
|
@@ -35,6 +39,7 @@ export declare function getOrCreateSunspecClient(energyApp: EnergyApp, host: str
|
|
|
35
39
|
export declare function releaseSunspecClient(host: string, port?: number): Promise<void>;
|
|
36
40
|
export declare class SunspecModbusClient {
|
|
37
41
|
private energyApp;
|
|
42
|
+
private pacing;
|
|
38
43
|
private modbusInstances;
|
|
39
44
|
private faultTolerantReaders;
|
|
40
45
|
private discoveredModelsByUnit;
|
|
@@ -48,7 +53,7 @@ export declare class SunspecModbusClient {
|
|
|
48
53
|
private closeCount;
|
|
49
54
|
private operationChain;
|
|
50
55
|
private txChains;
|
|
51
|
-
constructor(energyApp: EnergyApp);
|
|
56
|
+
constructor(energyApp: EnergyApp, pacing?: IModbusPacingConfig);
|
|
52
57
|
/**
|
|
53
58
|
* Connect to a Modbus device unit. Multiple unit IDs on the same network device share this
|
|
54
59
|
* client; calling connect() with different unit IDs adds each as a separately-managed unit.
|
|
@@ -59,8 +64,17 @@ export declare class SunspecModbusClient {
|
|
|
59
64
|
* @param unitId Modbus unit ID (default 1)
|
|
60
65
|
* @param secondaryHost Optional secondary host (ipAddress) for fallback during reconnection
|
|
61
66
|
* @param useTls Whether to use TLS/SSL for the Modbus connection (Modbus Security, typically port 802). Defaults to false.
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
* @param tls Optional TLS certificate material for mutual-TLS / custom-CA connections. Only
|
|
68
|
+
* honoured when {@link useTls} is true. `cert`/`key` present a client certificate,
|
|
69
|
+
* `ca` supplies trusted CA certificate(s), and `rejectUnauthorized` controls whether an
|
|
70
|
+
* unverifiable server certificate is rejected.
|
|
71
|
+
*/
|
|
72
|
+
connect(host: string, port?: number, unitId?: number, secondaryHost?: string, useTls?: boolean, tls?: {
|
|
73
|
+
cert?: string | Buffer;
|
|
74
|
+
key?: string | Buffer;
|
|
75
|
+
ca?: string | Buffer | Array<string | Buffer>;
|
|
76
|
+
rejectUnauthorized?: boolean;
|
|
77
|
+
}): Promise<void>;
|
|
64
78
|
/**
|
|
65
79
|
* Disconnect from all units of this network device.
|
|
66
80
|
*
|
package/dist/cjs/version.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
9
9
|
/**
|
|
10
10
|
* Current version of the enyo Energy App SDK.
|
|
11
11
|
*/
|
|
12
|
-
exports.SDK_VERSION = '0.0.
|
|
12
|
+
exports.SDK_VERSION = '0.0.94';
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current SDK version.
|
|
15
15
|
* @returns The semantic version string of the SDK
|
package/dist/cjs/version.d.cts
CHANGED
|
@@ -16,6 +16,26 @@ export interface IRetryConfig {
|
|
|
16
16
|
phases: IRetryPhase[];
|
|
17
17
|
}
|
|
18
18
|
export declare const DEFAULT_RETRY_CONFIG: IRetryConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Pacing configuration for the Modbus client. Both options are opt-in and default off, so existing
|
|
21
|
+
* consumers are unaffected. The fields mirror the SDK's `ModbusOptions` and are passed straight
|
|
22
|
+
* through to `useModbus().connect()` — the SDK owns the serialization; the client only forwards the
|
|
23
|
+
* config it was constructed with. Omitted fields leave the SDK to apply its own defaults
|
|
24
|
+
* (`noParallelRequests` false, `waitBetweenMessagesMs` 0). Intended for slow devices (e.g. Solax)
|
|
25
|
+
* that choke when frames arrive back-to-back.
|
|
26
|
+
*/
|
|
27
|
+
export interface IModbusPacingConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Serialize reads and writes on the connection through the SDK's internal operation chain so
|
|
30
|
+
* frames don't interleave (SDK `ModbusOptions.noParallelRequests`). Default false.
|
|
31
|
+
*/
|
|
32
|
+
noParallelRequests?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Minimum ms to wait between two consecutive frames. Only honoured when `noParallelRequests` is
|
|
35
|
+
* true (SDK `ModbusOptions.waitBetweenMessagesMs`). Default 0.
|
|
36
|
+
*/
|
|
37
|
+
waitBetweenMessagesMs?: number;
|
|
38
|
+
}
|
|
19
39
|
/**
|
|
20
40
|
* Base interface for all SunSpec blocks
|
|
21
41
|
*/
|
|
@@ -16,15 +16,19 @@
|
|
|
16
16
|
* - pad: 0x8000 (always returns this value)
|
|
17
17
|
* - string: all registers 0x0000 (NULL)
|
|
18
18
|
*/
|
|
19
|
-
import { type SunspecInverterControls, type SunspecInverterData, type SunspecInverterSettings, type SunspecMeterData, type SunspecModel, type SunspecMPPTData, type SunspecBatteryData, type SunspecBatteryBaseData, type SunspecBatteryControls, SunspecStorageMode } from "./sunspec-interfaces.js";
|
|
19
|
+
import { type SunspecInverterControls, type SunspecInverterData, type SunspecInverterSettings, type SunspecMeterData, type SunspecModel, type SunspecMPPTData, type SunspecBatteryData, type SunspecBatteryBaseData, type SunspecBatteryControls, SunspecStorageMode, type IModbusPacingConfig } from "./sunspec-interfaces.js";
|
|
20
20
|
import { EnergyAppModbusDataType, IConnectionHealth } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/interfaces.js";
|
|
21
21
|
import { EnergyAppModbusInstance } from "@enyo-energy/energy-app-sdk/dist/packages/energy-app-modbus.js";
|
|
22
22
|
import { EnergyApp } from "@enyo-energy/energy-app-sdk";
|
|
23
23
|
/**
|
|
24
24
|
* Get (or create) the singleton SunspecModbusClient for this network device.
|
|
25
25
|
* Increments the refcount; pair with `releaseSunspecClient` on teardown.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: `pacing` is only applied when the client is FIRST created for a given host:port.
|
|
28
|
+
* Because the client is cached and refcounted, a later caller passing a different `pacing`
|
|
29
|
+
* receives the already-created instance and its config is ignored.
|
|
26
30
|
*/
|
|
27
|
-
export declare function getOrCreateSunspecClient(energyApp: EnergyApp, host: string, port?: number): SunspecModbusClient;
|
|
31
|
+
export declare function getOrCreateSunspecClient(energyApp: EnergyApp, host: string, port?: number, pacing?: IModbusPacingConfig): SunspecModbusClient;
|
|
28
32
|
/**
|
|
29
33
|
* Release a refcount on the network-device client. When the last consumer releases,
|
|
30
34
|
* the client is fully disconnected (all units closed) and removed from the registry.
|
|
@@ -35,6 +39,7 @@ export declare function getOrCreateSunspecClient(energyApp: EnergyApp, host: str
|
|
|
35
39
|
export declare function releaseSunspecClient(host: string, port?: number): Promise<void>;
|
|
36
40
|
export declare class SunspecModbusClient {
|
|
37
41
|
private energyApp;
|
|
42
|
+
private pacing;
|
|
38
43
|
private modbusInstances;
|
|
39
44
|
private faultTolerantReaders;
|
|
40
45
|
private discoveredModelsByUnit;
|
|
@@ -48,7 +53,7 @@ export declare class SunspecModbusClient {
|
|
|
48
53
|
private closeCount;
|
|
49
54
|
private operationChain;
|
|
50
55
|
private txChains;
|
|
51
|
-
constructor(energyApp: EnergyApp);
|
|
56
|
+
constructor(energyApp: EnergyApp, pacing?: IModbusPacingConfig);
|
|
52
57
|
/**
|
|
53
58
|
* Connect to a Modbus device unit. Multiple unit IDs on the same network device share this
|
|
54
59
|
* client; calling connect() with different unit IDs adds each as a separately-managed unit.
|
|
@@ -59,8 +64,17 @@ export declare class SunspecModbusClient {
|
|
|
59
64
|
* @param unitId Modbus unit ID (default 1)
|
|
60
65
|
* @param secondaryHost Optional secondary host (ipAddress) for fallback during reconnection
|
|
61
66
|
* @param useTls Whether to use TLS/SSL for the Modbus connection (Modbus Security, typically port 802). Defaults to false.
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
* @param tls Optional TLS certificate material for mutual-TLS / custom-CA connections. Only
|
|
68
|
+
* honoured when {@link useTls} is true. `cert`/`key` present a client certificate,
|
|
69
|
+
* `ca` supplies trusted CA certificate(s), and `rejectUnauthorized` controls whether an
|
|
70
|
+
* unverifiable server certificate is rejected.
|
|
71
|
+
*/
|
|
72
|
+
connect(host: string, port?: number, unitId?: number, secondaryHost?: string, useTls?: boolean, tls?: {
|
|
73
|
+
cert?: string | Buffer;
|
|
74
|
+
key?: string | Buffer;
|
|
75
|
+
ca?: string | Buffer | Array<string | Buffer>;
|
|
76
|
+
rejectUnauthorized?: boolean;
|
|
77
|
+
}): Promise<void>;
|
|
64
78
|
/**
|
|
65
79
|
* Disconnect from all units of this network device.
|
|
66
80
|
*
|
|
@@ -29,12 +29,16 @@ const registryKey = (host, port) => `${host}:${port}`;
|
|
|
29
29
|
/**
|
|
30
30
|
* Get (or create) the singleton SunspecModbusClient for this network device.
|
|
31
31
|
* Increments the refcount; pair with `releaseSunspecClient` on teardown.
|
|
32
|
+
*
|
|
33
|
+
* NOTE: `pacing` is only applied when the client is FIRST created for a given host:port.
|
|
34
|
+
* Because the client is cached and refcounted, a later caller passing a different `pacing`
|
|
35
|
+
* receives the already-created instance and its config is ignored.
|
|
32
36
|
*/
|
|
33
|
-
export function getOrCreateSunspecClient(energyApp, host, port = 502) {
|
|
37
|
+
export function getOrCreateSunspecClient(energyApp, host, port = 502, pacing) {
|
|
34
38
|
const key = registryKey(host, port);
|
|
35
39
|
let entry = CLIENT_REGISTRY.get(key);
|
|
36
40
|
if (!entry) {
|
|
37
|
-
entry = { client: new SunspecModbusClient(energyApp), refcount: 0 };
|
|
41
|
+
entry = { client: new SunspecModbusClient(energyApp, pacing), refcount: 0 };
|
|
38
42
|
CLIENT_REGISTRY.set(key, entry);
|
|
39
43
|
}
|
|
40
44
|
entry.refcount++;
|
|
@@ -74,6 +78,7 @@ export async function releaseSunspecClient(host, port = 502) {
|
|
|
74
78
|
}
|
|
75
79
|
export class SunspecModbusClient {
|
|
76
80
|
energyApp;
|
|
81
|
+
pacing;
|
|
77
82
|
// Per-unit Modbus instance/reader/discovered-models maps. One client = one network device,
|
|
78
83
|
// many unit IDs share that client (each unit ID is one EnergyAppModbusInstance underneath).
|
|
79
84
|
modbusInstances = new Map();
|
|
@@ -106,8 +111,13 @@ export class SunspecModbusClient {
|
|
|
106
111
|
// operationChain (the connection lock) to avoid re-entrancy: a transaction never waits
|
|
107
112
|
// on a connect/disconnect, and vice versa.
|
|
108
113
|
txChains = new Map();
|
|
109
|
-
constructor(energyApp
|
|
114
|
+
constructor(energyApp,
|
|
115
|
+
// Opt-in pacing (default off). Passed straight through to `useModbus().connect()`, which
|
|
116
|
+
// serializes frames (`noParallelRequests`) and spaces them (`waitBetweenMessagesMs`) on the
|
|
117
|
+
// connection. An empty object leaves both undefined so the SDK applies its own defaults.
|
|
118
|
+
pacing = {}) {
|
|
110
119
|
this.energyApp = energyApp;
|
|
120
|
+
this.pacing = pacing;
|
|
111
121
|
this.connectionHealth = new EnergyAppModbusConnectionHealth();
|
|
112
122
|
this.modbusDataTypeConverter = new EnergyAppModbusDataTypeConverter();
|
|
113
123
|
}
|
|
@@ -121,8 +131,12 @@ export class SunspecModbusClient {
|
|
|
121
131
|
* @param unitId Modbus unit ID (default 1)
|
|
122
132
|
* @param secondaryHost Optional secondary host (ipAddress) for fallback during reconnection
|
|
123
133
|
* @param useTls Whether to use TLS/SSL for the Modbus connection (Modbus Security, typically port 802). Defaults to false.
|
|
134
|
+
* @param tls Optional TLS certificate material for mutual-TLS / custom-CA connections. Only
|
|
135
|
+
* honoured when {@link useTls} is true. `cert`/`key` present a client certificate,
|
|
136
|
+
* `ca` supplies trusted CA certificate(s), and `rejectUnauthorized` controls whether an
|
|
137
|
+
* unverifiable server certificate is rejected.
|
|
124
138
|
*/
|
|
125
|
-
async connect(host, port = 502, unitId = 1, secondaryHost, useTls) {
|
|
139
|
+
async connect(host, port = 502, unitId = 1, secondaryHost, useTls, tls) {
|
|
126
140
|
return this.withConnectionLock(async () => {
|
|
127
141
|
if (this.connectionParams) {
|
|
128
142
|
if (this.connectionParams.primaryHost !== host || this.connectionParams.port !== port) {
|
|
@@ -135,9 +149,30 @@ export class SunspecModbusClient {
|
|
|
135
149
|
if (useTls !== undefined) {
|
|
136
150
|
this.connectionParams.useTls = useTls;
|
|
137
151
|
}
|
|
152
|
+
if (tls?.cert !== undefined) {
|
|
153
|
+
this.connectionParams.cert = tls.cert;
|
|
154
|
+
}
|
|
155
|
+
if (tls?.key !== undefined) {
|
|
156
|
+
this.connectionParams.key = tls.key;
|
|
157
|
+
}
|
|
158
|
+
if (tls?.ca !== undefined) {
|
|
159
|
+
this.connectionParams.ca = tls.ca;
|
|
160
|
+
}
|
|
161
|
+
if (tls?.rejectUnauthorized !== undefined) {
|
|
162
|
+
this.connectionParams.rejectUnauthorized = tls.rejectUnauthorized;
|
|
163
|
+
}
|
|
138
164
|
}
|
|
139
165
|
else {
|
|
140
|
-
this.connectionParams = {
|
|
166
|
+
this.connectionParams = {
|
|
167
|
+
primaryHost: host,
|
|
168
|
+
secondaryHost,
|
|
169
|
+
port,
|
|
170
|
+
useTls,
|
|
171
|
+
cert: tls?.cert,
|
|
172
|
+
key: tls?.key,
|
|
173
|
+
ca: tls?.ca,
|
|
174
|
+
rejectUnauthorized: tls?.rejectUnauthorized,
|
|
175
|
+
};
|
|
141
176
|
}
|
|
142
177
|
this.knownUnits.add(unitId);
|
|
143
178
|
if (this.modbusInstances.has(unitId)) {
|
|
@@ -284,7 +319,13 @@ export class SunspecModbusClient {
|
|
|
284
319
|
port,
|
|
285
320
|
unitId,
|
|
286
321
|
timeout: 5000,
|
|
287
|
-
useTls: this.connectionParams?.useTls
|
|
322
|
+
useTls: this.connectionParams?.useTls,
|
|
323
|
+
cert: this.connectionParams?.cert,
|
|
324
|
+
key: this.connectionParams?.key,
|
|
325
|
+
ca: this.connectionParams?.ca,
|
|
326
|
+
rejectUnauthorized: this.connectionParams?.rejectUnauthorized,
|
|
327
|
+
noParallelRequests: this.pacing.noParallelRequests,
|
|
328
|
+
waitBetweenMessagesMs: this.pacing.waitBetweenMessagesMs
|
|
288
329
|
});
|
|
289
330
|
if (!candidate) {
|
|
290
331
|
throw new Error(`useModbus().connect returned null for ${host}:${port} unit ${unitId}`);
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enyo-energy/sunspec-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.94",
|
|
4
4
|
"description": "enyo Energy Sunspec SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@enyo-energy/appliance-calibration": "0.0.2",
|
|
44
|
-
"@enyo-energy/energy-app-sdk": "^0.0.
|
|
44
|
+
"@enyo-energy/energy-app-sdk": "^0.0.172"
|
|
45
45
|
},
|
|
46
46
|
"volta": {
|
|
47
47
|
"node": "22.17.0"
|