node-red-contrib-s7-rust 1.0.5 → 1.2.0

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/CHANGELOG.md CHANGED
@@ -6,6 +6,66 @@ All notable changes to this project are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2026-11-12
10
+
11
+ ### Added
12
+
13
+ - `s7 endpoint`: check of the PLC certificate (S7CommPlus with TLS), option "PLC certificate":
14
+ *pinned fingerprint* (SHA-256, one or more) or *trusted certificate or project CA* (PEM: the
15
+ chain, the validity and the name, by default the host; option "Certificate name"). The
16
+ default is no check, as before. When the check fails, the endpoint stays disconnected with
17
+ an error that names the reason and the fingerprint it got. A check without TLS, a bad
18
+ fingerprint or a bad PEM stops the endpoint with a configuration error.
19
+ - `s7 info`: action `certificate` (S7CommPlus with TLS): subject, issuer, validity, alternative
20
+ names, SHA-256 fingerprint, PEM and the check of the endpoint. The editor of the endpoint reads
21
+ it ("Read from the PLC") and copies the fingerprint and the PEM to the fields. Action `info`:
22
+ new fields `certificateCheck`, `certificateFingerprint`.
23
+ - Rust crate `s7plus`: `TlsOptions::verify` (`CertVerify`: `None`, `Fingerprint`, `Trusted`),
24
+ `Error::Certificate` (also for `verify` together with a caller `config`, which has its own
25
+ verifier), `SessionInfo::peer_cert`, a small X.509 reader (`x509::parse`,
26
+ `x509::pem`); the fake PLC can use a certificate signed by a CA (`enable_tls_signed`).
27
+ - `test/plcsim/live_cert.js`: the check against PLCSIM. Tested on PLCSIM Advanced V8 (S7-1500,
28
+ FW S4.1): the PLC certificate is self-signed (CN `PLC-1/Communication-1`, IP address in the
29
+ alternative names, CA:FALSE); both checks accept it, a wrong fingerprint or name is refused.
30
+
31
+ ## [1.1.0] - 2026-11-12
32
+
33
+ ### Added
34
+
35
+ - `s7 watch`: mode "PLC subscription" (S7CommPlus). The node subscribes to the tags with the
36
+ interval as cycle time, and the PLC sends only the values that changed (no read request per
37
+ cycle). `msg.ts` is the PLC time of the notification when the PLC sends one. After a reconnect
38
+ the node subscribes again; when the PLC refuses the subscription (or for S7comm) it reads
39
+ cyclically. Tested on PLCSIM Advanced V8 (FW S4.1) with TLS: first message with all tags, then
40
+ the changes every cycle, and a write is in the next notification. The default stays "read
41
+ cyclically".
42
+ - `s7 alarms` node (S7CommPlus): one message per PLC alarm event (`msg.state` coming / going,
43
+ `msg.topic` the alarm id, `msg.payload` times, associated values, priority, class, texts). At
44
+ start, and again after a reconnect, it sends the active alarms (`msg.initial`). The status shows
45
+ the number of active alarms. Example flow "05 - S7CommPlus alarms". Tested on PLCSIM Advanced
46
+ V8 (FW S4.1): a Program_Alarm comes about 20 ms after its signal is written.
47
+ - Alarm subscriptions: `AlarmSubOptions::for_plc` selects the layout. S7-1500 FW V4.x accepts the
48
+ TIA Portal layout but sends no alarms with it; it needs the S7CommPlusDriver layout (the S7-1200
49
+ keeps the TIA Portal layout). The `s7 info` action `alarms` also returns `state`, `priority`,
50
+ `alarmClass` and the associated values. The fake PLC sends alarm notifications
51
+ (`FakePlc::raise_alarm`, `FakeModel::alarm_needs_reference`); golden tests decode PLCSIM alarm
52
+ notifications.
53
+ - `test/plcsim/`: the PLCSIM Advanced test program (SIMATIC SD documents of the DBs, the alarm FB
54
+ and OB1), how to load it with TIA Portal (Openness MCP), and two manual live-test scripts
55
+ (`s7 watch` push/poll, `s7 alarms`). `npm test` does not use them.
56
+
57
+ ### Fixed
58
+
59
+ - S7CommPlus: a Bool member of an optimized S7-1500 DB (softdatatype BBool) could not be written
60
+ ("writing BBool is not supported"); reads worked. It is now written like a Bool. Found on
61
+ PLCSIM Advanced V8 (FW S4.1); the fake PLC has a BBool member (`"Data_block_1".BFlag`).
62
+ - S7CommPlus subscriptions on S7-1500 FW V4.x: with cycle time 0 the PLC sends only the first
63
+ notification. `SubOptions::cycle_ms` documents it; the fake PLC models it
64
+ (`FakeModel::sub_needs_cycle`), and golden tests decode FW V4.x notifications (change counter,
65
+ 8-byte timestamp).
66
+ - Addon: a data event with every tag in another order than the tag list now carries the index
67
+ list (before, the values went to the wrong tags; only possible with PLC notifications).
68
+
9
69
  ## [1.0.5] - 2026-11-12
10
70
 
11
71
  ### Fixed
@@ -102,7 +162,9 @@ First release: the next generation of `@oriolrius/node-red-contrib-s7`.
102
162
  - CI: tests on Node-RED 4 and 5, gitleaks, GitGuardian, RustSec and npm audit, CodeQL,
103
163
  OpenSSF Scorecard, Dependabot. License LGPL-3.0-only.
104
164
 
105
- [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.5...HEAD
165
+ [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.0...HEAD
166
+ [1.2.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.1.0...v1.2.0
167
+ [1.1.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.5...v1.1.0
106
168
  [1.0.5]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.4...v1.0.5
107
169
  [1.0.4]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.3...v1.0.4
108
170
  [1.0.3]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.2...v1.0.3
package/README.md CHANGED
@@ -79,11 +79,12 @@ Then restart Node-RED. The nodes are in the **network** category of the palette.
79
79
 
80
80
  | Node | Function |
81
81
  |---|---|
82
- | `s7 endpoint` (config) | One PLC connection: protocol, host, port. S7comm: CPU family, rack/slot or TSAPs, PDU, gap, byte order. S7CommPlus: remote TSAP, TLS, user, password (stored as a credential). |
82
+ | `s7 endpoint` (config) | One PLC connection: protocol, host, port. S7comm: CPU family, rack/slot or TSAPs, PDU, gap, byte order. S7CommPlus: remote TSAP, TLS and the check of the PLC certificate, user, password (stored as a credential). |
83
83
  | `s7 read` | Reads tags when a message arrives. Output: one value, `{tag: value}` or an array. |
84
84
  | `s7 write` | Writes the tag of the node, the tag in `msg.topic`, or `msg.payload = {tag: value, …}` in one request. |
85
- | `s7 watch` | A Rust thread reads the tags at an interval and sends only the changes. Optional conditional rate ("Fast while" a tag is true). |
86
- | `s7 info` | Diagnostics. Both protocols: `status`, `cpuState`. S7comm: `identify`, `szl`, `szlList`, `clock`, `setClock`, `syncClock`, `blocks`, `listBlocks`, `blockInfo`. S7CommPlus: `info`, `dbs`, `browse`, `alarms`, `limits`. |
85
+ | `s7 watch` | Sends only the changes. Mode "read cyclically": a Rust thread reads the tags at an interval, with an optional conditional rate ("Fast while" a tag is true). Mode "PLC subscription" (S7CommPlus): the PLC sends the changes. |
86
+ | `s7 alarms` | S7CommPlus: a message when a PLC alarm comes or goes (alarm subscription; the active alarms at start). |
87
+ | `s7 info` | Diagnostics. Both protocols: `status`, `cpuState`. S7comm: `identify`, `szl`, `szlList`, `clock`, `setClock`, `syncClock`, `blocks`, `listBlocks`, `blockInfo`. S7CommPlus: `info`, `certificate`, `dbs`, `browse`, `alarms`, `limits`. |
87
88
 
88
89
  Every node has full help in the editor sidebar. Bad tags never stop the other tags: they give
89
90
  `null` and an entry in `msg.s7.errors`, or `msg.quality = "bad"` in a watch.
@@ -140,7 +141,7 @@ This map shows each protocol function and where it is available. It is strict: a
140
141
  | Connection | TPKT + COTP, remote TSAP `SIMATIC-ROOT-HMI`, protocol version 1 for the session creation, version 2 after it | ✅ | `s7 endpoint` |
141
142
  | Session | CreateObject 0x04CA (ClientSession), session setup with SetMultiVariables, DeleteObject 0x04D4 at close | ✅ | `s7 endpoint` |
142
143
  | TLS 1.3 | InitSsl 0x05B3, TLS inside COTP | ✅ | `s7 endpoint` (option "TLS") |
143
- | PLC certificate verification | — | ❌ | — (TLS protects against passive capture only) |
144
+ | PLC certificate verification | pinned SHA-256 fingerprint, or chain to a trusted certificate (the PLC certificate or the TIA project CA) with validity and name (IP address or DNS name) | ✅ | `s7 endpoint` (option "PLC certificate"), `s7 info`: `certificate` |
144
145
  | Legitimation (access level password) | challenge from GetVarSubStreamed 0x0586, legacy and new response | ✅ | `s7 endpoint` (password) |
145
146
  | Read | GetMultiVariables 0x054C, symbolic and absolute addresses | ✅ | `s7 read`, `s7 watch` |
146
147
  | Write | SetMultiVariables 0x0542, symbolic and absolute addresses | ✅ | `s7 write` |
@@ -150,8 +151,8 @@ This map shows each protocol function and where it is available. It is strict: a
150
151
  | CPU operating state | read of the PLC program object | ✅ | `s7 info`: `cpuState` |
151
152
  | Communication limits | read of the PLC limit attributes | ✅ | `s7 info`: `limits`, `info` |
152
153
  | Active alarms | alarm objects and text libraries | ✅ | `s7 info`: `alarms` |
153
- | Alarm subscription | CreateObject subscription, notifications | 🔒 | — |
154
- | Variable subscription | CreateObject subscription, notifications | 🔒 | — (`s7 watch` uses polling) |
154
+ | Alarm subscription | CreateObject alarm subscription (TIA Portal or S7CommPlusDriver layout), DAI notifications | ✅ | `s7 alarms` |
155
+ | Variable subscription | CreateObject subscription with a cycle time, notifications, credit limit | ✅ | `s7 watch` (mode "PLC subscription") |
155
156
  | Set CPU operating state (RUN/STOP) | SetVariable 0x04F2 | 🔒 | — |
156
157
  | Block upload / download, program changes | BeginSequence 0x0556, EndSequence 0x0560, Invoke 0x056B | ❌ | — |
157
158
  | Links | AddLink 0x0506, RemoveLink 0x051A, GetLink 0x0524 | ❌ | — |
@@ -176,6 +177,19 @@ Some CPUs accept only TLS sessions (PLCSIM Advanced V8 with FW S4.1, or a CPU wi
176
177
  secure PG/PC and HMI communication"): without TLS the connection fails with "the PLC refused the
177
178
  session without TLS". Turn on TLS in the endpoint.
178
179
 
180
+ **PLC certificate**: without a check, TLS protects only against passive capture (a device between
181
+ Node-RED and the PLC can show its own certificate). In the endpoint, set "PLC certificate" to:
182
+
183
+ - *pinned fingerprint*: the SHA-256 of the PLC certificate (more than one, separated by commas,
184
+ for a change of certificate);
185
+ - *trusted certificate or project CA*: the PLC certificate in PEM, exported from TIA Portal, or
186
+ the CA of the project. The certificate must be valid now and contain the host (the S7-1500
187
+ puts its IP addresses in it); set "Certificate name" when Node-RED uses another address.
188
+
189
+ *Read from the PLC* in the endpoint editor (or `s7 info` action `certificate`) shows the
190
+ certificate of the deployed endpoint: compare it with TIA Portal before you trust it. When the
191
+ check fails, the endpoint stays disconnected and the error shows the fingerprint it got.
192
+
179
193
  ## Addresses
180
194
 
181
195
  One address per line in the node, or in `msg.tags` / `msg.topic`.
@@ -262,8 +276,11 @@ S7-1200 on the same LAN).
262
276
 
263
277
  - The addon runs in the Node-RED process. A fatal error in native code stops Node-RED. The code
264
278
  is safe Rust; the Node-API layer is the only FFI.
265
- - S7CommPlus watch uses polling, not PLC subscriptions.
266
- - S7CommPlus: the PLC certificate is not verified (TLS protects against passive capture only).
279
+ - `s7 watch`, mode "PLC subscription": the cycle time is the interval (100 ms or more; S7-1500
280
+ FW V4.x sends no changes without a cycle time). Each subscription uses one of the PLC
281
+ subscription resources (`s7 info` → `limits`); when the PLC refuses it, the node reads cyclically.
282
+ - S7CommPlus: the PLC certificate is not verified by default (TLS then protects against passive
283
+ capture only); set "PLC certificate" in the endpoint. No revocation check (CRL / OCSP).
267
284
 
268
285
  ## Migration from @oriolrius/node-red-contrib-s7
269
286
 
Binary file
Binary file
@@ -0,0 +1,114 @@
1
+ [
2
+ {
3
+ "id": "c5",
4
+ "type": "comment",
5
+ "name": "PLC alarms with s7 alarms (S7CommPlus)",
6
+ "info": "The node subscribes to the alarms of the CPU (Program_Alarm, ProDiag...).\nAt start it sends the active alarms (msg.initial = true), then one message per coming / going.\nmsg.topic is the alarm id, msg.state is coming or going, msg.payload has the times, the associated values and the texts.\nThe switch sends the coming alarms to the first output and the going alarms to the second one.",
7
+ "x": 230,
8
+ "y": 40,
9
+ "wires": []
10
+ },
11
+ {
12
+ "id": "al5",
13
+ "type": "s7rs-alarms",
14
+ "name": "",
15
+ "endpoint": "ep5",
16
+ "initial": true,
17
+ "layout": "auto",
18
+ "x": 140,
19
+ "y": 100,
20
+ "wires": [
21
+ [
22
+ "sw5"
23
+ ]
24
+ ]
25
+ },
26
+ {
27
+ "id": "sw5",
28
+ "type": "switch",
29
+ "name": "state",
30
+ "property": "state",
31
+ "propertyType": "msg",
32
+ "rules": [
33
+ {
34
+ "t": "eq",
35
+ "v": "coming",
36
+ "vt": "str"
37
+ },
38
+ {
39
+ "t": "eq",
40
+ "v": "going",
41
+ "vt": "str"
42
+ }
43
+ ],
44
+ "checkall": "true",
45
+ "repair": false,
46
+ "outputs": 2,
47
+ "x": 310,
48
+ "y": 100,
49
+ "wires": [
50
+ [
51
+ "d5a"
52
+ ],
53
+ [
54
+ "d5b"
55
+ ]
56
+ ]
57
+ },
58
+ {
59
+ "id": "d5a",
60
+ "type": "debug",
61
+ "name": "coming",
62
+ "active": true,
63
+ "tosidebar": true,
64
+ "console": false,
65
+ "tostatus": false,
66
+ "complete": "payload",
67
+ "targetType": "msg",
68
+ "statusVal": "",
69
+ "statusType": "auto",
70
+ "x": 480,
71
+ "y": 80,
72
+ "wires": []
73
+ },
74
+ {
75
+ "id": "d5b",
76
+ "type": "debug",
77
+ "name": "going",
78
+ "active": true,
79
+ "tosidebar": true,
80
+ "console": false,
81
+ "tostatus": false,
82
+ "complete": "payload",
83
+ "targetType": "msg",
84
+ "statusVal": "",
85
+ "statusType": "auto",
86
+ "x": 480,
87
+ "y": 120,
88
+ "wires": []
89
+ },
90
+ {
91
+ "id": "ep5",
92
+ "type": "s7rs-endpoint",
93
+ "name": "PLC (S7CommPlus, TLS)",
94
+ "protocol": "s7plus",
95
+ "host": "192.168.0.1",
96
+ "port": 102,
97
+ "cpu": "1500",
98
+ "rack": "",
99
+ "slot": "",
100
+ "link": "",
101
+ "localTsap": "",
102
+ "remoteTsap": "",
103
+ "pdu": "",
104
+ "timeout": 5000,
105
+ "attempts": 3,
106
+ "reconnect": 5000,
107
+ "gap": 5,
108
+ "byteOrder": "big",
109
+ "logLevel": "warn",
110
+ "tsap": "SIMATIC-ROOT-HMI",
111
+ "tls": true,
112
+ "username": ""
113
+ }
114
+ ]
@@ -5,7 +5,7 @@
5
5
  //
6
6
  // API (Promise based, events 'status', 'data', 'log'):
7
7
  // open(params) close(conn) read(conn, tags) write(conn, [{tag, value}])
8
- // subscribe(params) unsubscribe(sub) status(conn) call(conn, action, args) stop()
8
+ // subscribe(params) subscribeAlarms(params) unsubscribe(sub) status(conn) call(conn, action, args) stop()
9
9
  // acquire()/release(): one shared instance per Node-RED runtime.
10
10
 
11
11
  const { EventEmitter } = require('node:events');
@@ -64,6 +64,12 @@ class NapiBridge extends EventEmitter {
64
64
  this.native = new S7Native(
65
65
  (conn, state, detail) => this.emit('status', { event: 'status', conn, state, detail }),
66
66
  (ev) => {
67
+ if (ev.alarms !== undefined) {
68
+ if (!this.subTags.has(ev.sub)) return; // unsubscribed meanwhile
69
+ const a = JSON.parse(ev.alarms);
70
+ this.emit('alarms', { event: 'alarms', sub: ev.sub, conn: ev.conn, alarms: a.alarms, snapshot: a.snapshot, ts: ev.ts });
71
+ return;
72
+ }
67
73
  const tags = this.subTags.get(ev.sub);
68
74
  if (!tags) return; // unsubscribed meanwhile
69
75
  this.emit('data', { event: 'data', sub: ev.sub, conn: ev.conn, values: rows(tags, ev.vals, ev.errs, ev.idx), ts: ev.ts, ms: ev.ms });
@@ -105,13 +111,21 @@ class NapiBridge extends EventEmitter {
105
111
  return { results, nativeMs: r.nativeMs };
106
112
  }
107
113
 
108
- // subscribe({conn, sub, tags, intervalMs, onChange, condTag, condIntervalMs}) -> {invalid}
114
+ // subscribe({conn, sub, tags, intervalMs, onChange, condTag, condIntervalMs, push}) -> {invalid}
109
115
  async subscribe(p) {
110
116
  this.start();
111
117
  this.subTags.set(p.sub, p.tags);
112
118
  return { invalid: await this.native.subscribe(p) };
113
119
  }
114
120
 
121
+ // subscribeAlarms({conn, sub, initial, layout}): 'alarms' events {sub, conn, alarms, snapshot, ts};
122
+ // snapshot: a new PLC subscription (start or reconnect), the receiver forgets the alarms it knew
123
+ async subscribeAlarms(p) {
124
+ this.start();
125
+ this.subTags.set(p.sub, []);
126
+ this.native.subscribeAlarms(p);
127
+ }
128
+
115
129
  async unsubscribe(sub) {
116
130
  this.subTags.delete(sub);
117
131
  if (this.native) this.native.unsubscribe(sub);
@@ -0,0 +1,35 @@
1
+ <script type="text/html" data-help-name="s7rs-alarms">
2
+ <p>Sends a message when a PLC alarm comes or goes (S7CommPlus, S7-1200/1500). The PLC sends the
3
+ alarms: there is no polling.</p>
4
+ <h3>Outputs</h3>
5
+ <dl class="message-properties">
6
+ <dt>topic <span class="property-type">string</span></dt>
7
+ <dd>the alarm id (CPU alarm id, hex): source block RID and alarm number.</dd>
8
+ <dt>state <span class="property-type">string</span></dt>
9
+ <dd><code>coming</code> (the alarm is active) or <code>going</code>.</dd>
10
+ <dt>payload <span class="property-type">object</span></dt>
11
+ <dd>the alarm: <code>id</code>, <code>name</code>, <code>state</code>, <code>allStates</code>,
12
+ <code>coming</code> and <code>going</code> (<code>time</code>, <code>ackTime</code>,
13
+ <code>values</code>: the associated values as PLC bytes), <code>priority</code>,
14
+ <code>alarmClass</code>, <code>seq</code>, <code>texts</code> (<code>lang</code>, <code>id</code>,
15
+ <code>text</code>).</dd>
16
+ <dt class="optional">initial <span class="property-type">boolean</span></dt>
17
+ <dd>true for the alarms that were active when the subscription started.</dd>
18
+ <dt>ts <span class="property-type">string</span></dt>
19
+ <dd>receive time (ISO, UTC). The PLC time is in <code>payload.coming.time</code> or
20
+ <code>payload.going.time</code>.</dd>
21
+ </dl>
22
+ <h3>Details</h3>
23
+ <p>At start, and again after a reconnect, the node subscribes to the alarms of the CPU and
24
+ (option) sends the active alarms with <code>msg.initial</code>. Then one message per alarm
25
+ event. The node status shows the number of active alarms; it starts again from the PLC list on
26
+ each new subscription (alarms that went while the PLC was not reachable are gone). Without "send
27
+ the active alarms at start" it counts only the alarms that came since the last subscription.</p>
28
+ <h4>Subscription</h4>
29
+ <p>The CPU families need different subscription layouts. <b>automatic</b> uses the TIA Portal layout
30
+ for an S7-1200 and the S7CommPlusDriver layout for the other CPUs (an S7-1500 FW V4.x accepts the
31
+ TIA Portal layout but sends no alarms with it). Select a layout when the automatic one gets no
32
+ alarms.</p>
33
+ <p>Alarm texts come from the PLC when the project has them (alarm text of the Program_Alarm
34
+ instance). Acknowledging alarms is not supported.</p>
35
+ </script>
@@ -0,0 +1,24 @@
1
+ {
2
+ "s7rs-alarms": {
3
+ "label": {
4
+ "name": "Name",
5
+ "endpoint": "PLC",
6
+ "initial": "send the active alarms at start",
7
+ "layout": "Subscription"
8
+ },
9
+ "layout": {
10
+ "auto": "automatic (by CPU)",
11
+ "tia": "TIA Portal layout (S7-1200)",
12
+ "reference": "S7CommPlusDriver layout (S7-1500)"
13
+ },
14
+ "portLabel": {
15
+ "out": "alarm events"
16
+ },
17
+ "status": {
18
+ "active": "__n__ active"
19
+ },
20
+ "errors": {
21
+ "subscribe": "alarm subscription: __error__"
22
+ }
23
+ }
24
+ }
@@ -13,8 +13,24 @@
13
13
  (S7-300: slot 2; S7-1200/1500: slot 1). With TSAPs set, rack and slot are not used.</p>
14
14
  <p>Gap: tags in the same area and DB that are closer than N bytes are read as one block.</p>
15
15
  <h4>S7CommPlus</h4>
16
- <p>Symbols are resolved once per session (a reconnect resolves them again). The PLC
17
- certificate is not verified. The password is stored as a Node-RED credential.</p>
16
+ <p>Symbols are resolved once per session (a reconnect resolves them again). The password is
17
+ stored as a Node-RED credential.</p>
18
+ <h4>PLC certificate (TLS)</h4>
19
+ <p>Without a check, TLS protects only against passive capture: a device between Node-RED and
20
+ the PLC can show its own certificate. Set one of these checks:</p>
21
+ <ul>
22
+ <li><b>pinned fingerprint</b>: the SHA-256 of the PLC certificate. More fingerprints,
23
+ separated by commas, allow a change of the certificate.</li>
24
+ <li><b>trusted certificate or project CA</b>: the PLC certificate in PEM (exported from
25
+ TIA Portal: device configuration, Protection &amp; Security, certificate manager), or the
26
+ CA of the project when the project CA signs the PLC certificates. The certificate must be
27
+ valid now and contain the certificate name: by default the host (the S7-1500 puts its IP
28
+ addresses in the certificate). Set the name when Node-RED uses another address (NAT).</li>
29
+ </ul>
30
+ <p><i>Read from the PLC</i> shows the certificate of the deployed endpoint, and
31
+ <i>Use this certificate</i> copies its fingerprint and PEM to the fields. Compare it with the
32
+ certificate in TIA Portal before you trust it. When the check fails, the endpoint stays
33
+ disconnected and the error shows the fingerprint of the certificate it got.</p>
18
34
  <p>Some CPUs accept only TLS sessions (for example PLCSIM Advanced V8, FW S4.1). If the
19
35
  connection fails with "the PLC refused the session without TLS", turn on TLS.</p>
20
36
  <h4>Log</h4>
@@ -17,6 +17,10 @@
17
17
  "byteOrder": "Byte order",
18
18
  "remoteTsap": "Remote TSAP",
19
19
  "tls": "TLS 1.3 (S7-1500 ≥ V2.9, S7-1200 ≥ V4.5)",
20
+ "certVerify": "PLC certificate",
21
+ "certFingerprint": "SHA-256",
22
+ "certTrusted": "Trusted (PEM)",
23
+ "certName": "Certificate name",
20
24
  "username": "User",
21
25
  "password": "Password",
22
26
  "logLevel": "Log"
@@ -25,6 +29,18 @@
25
29
  "s7": "S7comm (classic, PUT/GET)",
26
30
  "s7plus": "S7CommPlus (S7-1200/1500, symbols)"
27
31
  },
32
+ "certVerify": {
33
+ "none": "not checked",
34
+ "fingerprint": "pinned fingerprint (SHA-256)",
35
+ "trusted": "trusted certificate or project CA (PEM)"
36
+ },
37
+ "cert": {
38
+ "read": "Read from the PLC",
39
+ "use": "Use this certificate",
40
+ "reading": "reading…",
41
+ "issuer": "issuer",
42
+ "notDeployed": "deploy the endpoint with TLS first"
43
+ },
28
44
  "link": {
29
45
  "default": "CPU default",
30
46
  "basic": "S7 Basic / other"
@@ -39,7 +55,8 @@
39
55
  "placeholder": {
40
56
  "default": "default",
41
57
  "username": "empty: legacy password only",
42
- "password": "empty: no legitimation"
58
+ "password": "empty: no legitimation",
59
+ "certName": "empty: the host (IP address or DNS name)"
43
60
  },
44
61
  "hint": {
45
62
  "gap": "merge reads closer than N bytes; -1 = off"
@@ -30,6 +30,10 @@
30
30
  <h4>S7CommPlus</h4>
31
31
  <ul>
32
32
  <li><code>info</code>: session, PAOM string, limits</li>
33
+ <li><code>certificate</code>: the PLC certificate of the TLS session: <code>subject</code>,
34
+ <code>issuer</code>, <code>notBefore</code>, <code>notAfter</code>, <code>altNames</code>,
35
+ <code>fingerprint</code> (SHA-256), <code>pem</code>, and <code>check</code> (the check
36
+ of the endpoint)</li>
33
37
  <li><code>dbs</code>: data blocks; <code>browse</code>: all symbols with their types</li>
34
38
  <li><code>alarms {all}</code>: active alarms; <code>limits</code>: system limits</li>
35
39
  </ul>
@@ -1,5 +1,6 @@
1
1
  <script type="text/html" data-help-name="s7rs-watch">
2
- <p>Reads tags at a fixed interval and sends a message when a value changes.</p>
2
+ <p>Sends a message when a tag value changes: it reads the tags at a fixed interval, or
3
+ (S7CommPlus) the PLC sends the changes.</p>
3
4
  <h3>Outputs</h3>
4
5
  <dl class="message-properties">
5
6
  <dt>payload <span class="property-type">any | object</span></dt>
@@ -10,7 +11,8 @@
10
11
  <dt class="optional">changed <span class="property-type">array</span></dt>
11
12
  <dd>all tags mode only: the tags that changed in this cycle.</dd>
12
13
  <dt>ts <span class="property-type">string</span></dt>
13
- <dd>start time of the read cycle (ISO, UTC).</dd>
14
+ <dd>start time of the read cycle (ISO, UTC). PLC subscription: the PLC time of the
15
+ notification, when the PLC sends one (S7-1500), else the receive time.</dd>
14
16
  </dl>
15
17
  <h3>Details</h3>
16
18
  <p>A Rust thread reads the tags and compares the raw PLC bytes. Node-RED gets no message when
@@ -19,6 +21,12 @@
19
21
  <h4>Fast while</h4>
20
22
  <p>Conditional rate: while this tag is true (or not zero), the node reads every <code>N</code> ms
21
23
  instead of the interval. The node does not send the condition tag, unless it is also in the list.</p>
22
- <h4>S7CommPlus</h4>
23
- <p>The watch uses polling, not PLC subscriptions.</p>
24
+ <h4>Mode</h4>
25
+ <p><b>read cyclically</b>: the node reads every interval (all protocols).</p>
26
+ <p><b>PLC subscription</b> (S7CommPlus): the node subscribes to the tags with the interval as
27
+ cycle time (100 ms or more). The PLC checks the tags each cycle and sends only the values that
28
+ changed, so there is no read request per cycle. The first message has all tags. "Fast while" and
29
+ "send only values that changed" do not apply. After a reconnect the node subscribes again. If
30
+ the PLC refuses the subscription (for example, no free subscription resources) or the protocol is
31
+ S7comm, the node reads cyclically and logs a warning (S7CommPlus).</p>
24
32
  </script>
@@ -4,6 +4,7 @@
4
4
  "name": "Name",
5
5
  "endpoint": "PLC",
6
6
  "tags": "Tags",
7
+ "mode": "Mode",
7
8
  "interval": "Interval (ms)",
8
9
  "condTag": "Fast while",
9
10
  "onChange": "send only values that changed",
@@ -15,6 +16,10 @@
15
16
  "condTag": "optional condition tag, e.g. M0.0",
16
17
  "topic": "object mode only"
17
18
  },
19
+ "mode": {
20
+ "poll": "read cyclically",
21
+ "push": "PLC subscription (S7CommPlus)"
22
+ },
18
23
  "output": {
19
24
  "each": "one message per tag (topic = tag)",
20
25
  "object": "one message with all tags"
@@ -0,0 +1,46 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('s7rs-alarms', {
3
+ category: 'network',
4
+ color: '#3FADB5',
5
+ defaults: {
6
+ name: { value: '' },
7
+ endpoint: { value: '', type: 's7rs-endpoint', required: true },
8
+ initial: { value: true },
9
+ layout: { value: 'auto' },
10
+ },
11
+ inputs: 0,
12
+ outputs: 1,
13
+ icon: 'font-awesome/fa-bell',
14
+ paletteLabel: 's7 alarms',
15
+ label: function () {
16
+ return this.name || 's7 alarms';
17
+ },
18
+ outputLabels: function () {
19
+ return this._('s7rs-alarms.portLabel.out');
20
+ },
21
+ });
22
+ </script>
23
+
24
+ <script type="text/html" data-template-name="s7rs-alarms">
25
+ <div class="form-row">
26
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7rs-alarms.label.name"></span></label>
27
+ <input type="text" id="node-input-name" />
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-endpoint"><i class="fa fa-plug"></i> <span data-i18n="s7rs-alarms.label.endpoint"></span></label>
31
+ <input type="text" id="node-input-endpoint" />
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-initial">&nbsp;</label>
35
+ <input type="checkbox" id="node-input-initial" style="width: auto; display: inline-block" />
36
+ <span data-i18n="s7rs-alarms.label.initial"></span>
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-layout" data-i18n="s7rs-alarms.label.layout"></label>
40
+ <select id="node-input-layout">
41
+ <option value="auto" data-i18n="s7rs-alarms.layout.auto"></option>
42
+ <option value="tia" data-i18n="s7rs-alarms.layout.tia"></option>
43
+ <option value="reference" data-i18n="s7rs-alarms.layout.reference"></option>
44
+ </select>
45
+ </div>
46
+ </script>
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+ // s7rs-alarms: a PLC alarm subscription (S7CommPlus). One message per alarm
3
+ // event (coming / going); the active alarms first, and again after a reconnect.
4
+
5
+ const { text, getEndpoint } = require('../lib/common');
6
+
7
+ module.exports = function (RED) {
8
+ function S7rsAlarms(config) {
9
+ RED.nodes.createNode(this, config);
10
+ const node = this;
11
+ const ep = getEndpoint(RED, node, config);
12
+ if (!ep) return;
13
+ const active = new Map(); // id -> alarm
14
+
15
+ const showCount = () =>
16
+ node.status({ fill: active.size ? 'yellow' : 'green', shape: 'dot', text: text(RED, 's7rs-alarms.status.active', { n: active.size }) });
17
+
18
+ const onAlarms = (ev) => {
19
+ if (ev.sub !== node.id) return;
20
+ // a new subscription (start or reconnect): the alarms that went meanwhile are gone
21
+ if (ev.snapshot) active.clear();
22
+ for (const a of ev.alarms) {
23
+ if (a.state === 'coming') active.set(a.id, a);
24
+ else active.delete(a.id);
25
+ const msg = { topic: a.id, payload: a, state: a.state, ts: ev.ts };
26
+ if (a.initial) msg.initial = true;
27
+ node.send(msg);
28
+ }
29
+ showCount();
30
+ };
31
+ ep.bridge.on('alarms', onAlarms);
32
+
33
+ ep.ready
34
+ .then(() =>
35
+ ep.bridge.subscribeAlarms({ conn: ep.id, sub: node.id, initial: config.initial !== false, layout: config.layout || 'auto' }),
36
+ )
37
+ .catch((err) => node.error(text(RED, 's7rs-alarms.errors.subscribe', { error: err.message })));
38
+
39
+ node.on('close', (removed, done) => {
40
+ ep.bridge.off('alarms', onAlarms);
41
+ ep.bridge
42
+ .unsubscribe(node.id)
43
+ .catch(() => {})
44
+ .finally(() => done());
45
+ });
46
+ }
47
+ RED.nodes.registerType('s7rs-alarms', S7rsAlarms);
48
+ };
@@ -21,6 +21,10 @@
21
21
  logLevel: { value: 'warn' },
22
22
  tsap: { value: 'SIMATIC-ROOT-HMI' },
23
23
  tls: { value: false },
24
+ certVerify: { value: 'none' },
25
+ certFingerprint: { value: '' },
26
+ certTrusted: { value: '' },
27
+ certName: { value: '' },
24
28
  username: { value: '' },
25
29
  },
26
30
  credentials: {
@@ -31,13 +35,35 @@
31
35
  return this.name || (this.host ? `${p} ${this.host}:${this.port || 102}` : 's7 endpoint');
32
36
  },
33
37
  oneditprepare: function () {
38
+ const node = this;
34
39
  const sync = () => {
35
40
  const plus = $('#node-config-input-protocol').val() === 's7plus';
41
+ const tls = plus && $('#node-config-input-tls').prop('checked');
42
+ const v = $('#node-config-input-certVerify').val();
36
43
  $('.s7rs-classic').toggle(!plus);
37
44
  $('.s7rs-plus').toggle(plus);
45
+ $('.s7rs-tls').toggle(tls);
46
+ $('.s7rs-cert-fp').toggle(tls && v === 'fingerprint');
47
+ $('.s7rs-cert-trusted').toggle(tls && v === 'trusted');
38
48
  };
39
- $('#node-config-input-protocol').on('change', sync);
49
+ $('#node-config-input-protocol, #node-config-input-tls, #node-config-input-certVerify').on('change', sync);
40
50
  sync();
51
+ // reads the certificate of the deployed endpoint (the user checks it before trusting it)
52
+ $('#s7rs-cert-read').on('click', () => {
53
+ const out = $('#s7rs-cert-info').text(node._('s7rs-endpoint.cert.reading'));
54
+ $.getJSON(`s7rs/call/${encodeURIComponent(node.id)}/certificate`)
55
+ .done((c) => {
56
+ out.text(`${c.subject}\n${node._('s7rs-endpoint.cert.issuer')}: ${c.issuer}\n${c.notBefore} - ${c.notAfter}\n${(c.altNames || []).join(', ')}\nSHA-256 ${c.fingerprint}`);
57
+ $('#s7rs-cert-use').show().off('click').on('click', () => {
58
+ $('#node-config-input-certFingerprint').val(c.fingerprint);
59
+ $('#node-config-input-certTrusted').val(c.pem);
60
+ });
61
+ })
62
+ .fail((x) => {
63
+ out.text((x.responseJSON && x.responseJSON.error) || node._('s7rs-endpoint.cert.notDeployed'));
64
+ $('#s7rs-cert-use').hide();
65
+ });
66
+ });
41
67
  },
42
68
  });
43
69
  </script>
@@ -129,6 +155,32 @@
129
155
  <input type="checkbox" id="node-config-input-tls" style="width: auto; display: inline-block" />
130
156
  <span data-i18n="s7rs-endpoint.label.tls"></span>
131
157
  </div>
158
+ <div class="form-row s7rs-tls">
159
+ <label for="node-config-input-certVerify"><i class="fa fa-certificate"></i> <span data-i18n="s7rs-endpoint.label.certVerify"></span></label>
160
+ <select id="node-config-input-certVerify">
161
+ <option value="none" data-i18n="s7rs-endpoint.certVerify.none"></option>
162
+ <option value="fingerprint" data-i18n="s7rs-endpoint.certVerify.fingerprint"></option>
163
+ <option value="trusted" data-i18n="s7rs-endpoint.certVerify.trusted"></option>
164
+ </select>
165
+ </div>
166
+ <div class="form-row s7rs-cert-fp">
167
+ <label for="node-config-input-certFingerprint" data-i18n="s7rs-endpoint.label.certFingerprint"></label>
168
+ <input type="text" id="node-config-input-certFingerprint" placeholder="AB:9F:2B:..." style="font-family: monospace" />
169
+ </div>
170
+ <div class="form-row s7rs-cert-trusted">
171
+ <label for="node-config-input-certTrusted" data-i18n="s7rs-endpoint.label.certTrusted"></label>
172
+ <textarea id="node-config-input-certTrusted" rows="6" placeholder="-----BEGIN CERTIFICATE-----" style="width: 70%; font-family: monospace; font-size: 11px"></textarea>
173
+ </div>
174
+ <div class="form-row s7rs-cert-trusted">
175
+ <label for="node-config-input-certName" data-i18n="s7rs-endpoint.label.certName"></label>
176
+ <input type="text" id="node-config-input-certName" data-i18n="[placeholder]s7rs-endpoint.placeholder.certName" />
177
+ </div>
178
+ <div class="form-row s7rs-tls">
179
+ <label>&nbsp;</label>
180
+ <button type="button" class="red-ui-button" id="s7rs-cert-read" data-i18n="s7rs-endpoint.cert.read"></button>
181
+ <button type="button" class="red-ui-button" id="s7rs-cert-use" style="display: none" data-i18n="s7rs-endpoint.cert.use"></button>
182
+ <pre id="s7rs-cert-info" style="margin: 6px 0 0 104px; white-space: pre-wrap; font-size: 11px"></pre>
183
+ </div>
132
184
  <div class="form-row s7rs-plus">
133
185
  <label for="node-config-input-username"><i class="fa fa-user"></i> <span data-i18n="s7rs-endpoint.label.username"></span></label>
134
186
  <input type="text" id="node-config-input-username" data-i18n="[placeholder]s7rs-endpoint.placeholder.username" />
@@ -9,7 +9,7 @@ const { text, intOrUndef } = require('../lib/common');
9
9
  // Diagnostics the editor may call through the admin API (read-only actions).
10
10
  const ADMIN_ACTIONS = new Set([
11
11
  'identify', 'cpuState', 'szl', 'szlList', 'clock', 'blocks', 'listBlocks', 'blockInfo',
12
- 'info', 'limits', 'dbs', 'browse', 'alarms',
12
+ 'info', 'certificate', 'limits', 'dbs', 'browse', 'alarms',
13
13
  ]);
14
14
 
15
15
  module.exports = function (RED) {
@@ -46,6 +46,10 @@ module.exports = function (RED) {
46
46
  logLevel: config.logLevel || 'warn',
47
47
  tsap: config.tsap || '',
48
48
  tls: config.tls === true || config.tls === 'true',
49
+ certVerify: config.certVerify || 'none',
50
+ certFingerprint: config.certFingerprint || '',
51
+ certTrusted: config.certTrusted || '',
52
+ certName: String(config.certName || '').trim(),
49
53
  username: config.username || '',
50
54
  password: creds.password || '',
51
55
  host: String(config.host || '').trim(),
@@ -58,6 +58,7 @@
58
58
  </optgroup>
59
59
  <optgroup label="S7CommPlus">
60
60
  <option value="info">info</option>
61
+ <option value="certificate">certificate (TLS)</option>
61
62
  <option value="dbs">dbs</option>
62
63
  <option value="browse">browse</option>
63
64
  <option value="alarms">alarms {all}</option>
@@ -12,6 +12,7 @@
12
12
  topic: { value: '' },
13
13
  condTag: { value: '' },
14
14
  condInterval: { value: 100, validate: RED.validators.number(true) },
15
+ mode: { value: 'poll' },
15
16
  },
16
17
  inputs: 0,
17
18
  outputs: 1,
@@ -19,7 +20,16 @@
19
20
  paletteLabel: 's7 watch',
20
21
  label: function () {
21
22
  const n = (this.tags || '').split('\n').filter((s) => s.trim()).length;
22
- return this.name || `s7 watch (${n} @ ${this.interval} ms)`;
23
+ const how = this.mode === 'push' ? 'sub' : '@';
24
+ return this.name || `s7 watch (${n} ${how} ${this.interval} ms)`;
25
+ },
26
+ oneditprepare: function () {
27
+ // a PLC subscription has no conditional rate and sends changes only
28
+ $('#node-input-mode')
29
+ .on('change', function () {
30
+ $('.s7rs-watch-poll').toggle($(this).val() !== 'push');
31
+ })
32
+ .trigger('change');
23
33
  },
24
34
  outputLabels: function () {
25
35
  return this._('s7rs-watch.portLabel.out');
@@ -41,16 +51,23 @@
41
51
  <textarea id="node-input-tags" rows="8" style="width: 70%; font-family: monospace"
42
52
  data-i18n="[placeholder]s7rs-watch.placeholder.tags"></textarea>
43
53
  </div>
54
+ <div class="form-row">
55
+ <label for="node-input-mode"><i class="fa fa-exchange"></i> <span data-i18n="s7rs-watch.label.mode"></span></label>
56
+ <select id="node-input-mode">
57
+ <option value="poll" data-i18n="s7rs-watch.mode.poll"></option>
58
+ <option value="push" data-i18n="s7rs-watch.mode.push"></option>
59
+ </select>
60
+ </div>
44
61
  <div class="form-row">
45
62
  <label for="node-input-interval"><i class="fa fa-clock-o"></i> <span data-i18n="s7rs-watch.label.interval"></span></label>
46
63
  <input type="text" id="node-input-interval" style="width: 80px" />
47
64
  </div>
48
- <div class="form-row">
65
+ <div class="form-row s7rs-watch-poll">
49
66
  <label for="node-input-condTag"><i class="fa fa-bolt"></i> <span data-i18n="s7rs-watch.label.condTag"></span></label>
50
67
  <input type="text" id="node-input-condTag" data-i18n="[placeholder]s7rs-watch.placeholder.condTag" style="width: 45%; font-family: monospace" />
51
68
  <input type="text" id="node-input-condInterval" style="width: 60px" /> ms
52
69
  </div>
53
- <div class="form-row">
70
+ <div class="form-row s7rs-watch-poll">
54
71
  <label for="node-input-onChange">&nbsp;</label>
55
72
  <input type="checkbox" id="node-input-onChange" style="width: auto; display: inline-block" />
56
73
  <span data-i18n="s7rs-watch.label.onChange"></span>
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
- // s7rs-watch: a Rust thread reads the tags at a fixed (or conditional) rate and
3
- // the node sends only the values that changed.
2
+ // s7rs-watch: a Rust thread reads the tags at a fixed (or conditional) rate, or
3
+ // (mode push, S7CommPlus) a PLC subscription sends the changes; the node sends
4
+ // only the values that changed.
4
5
 
5
6
  const { text, parseTags, getEndpoint } = require('../lib/common');
6
7
 
@@ -53,6 +54,8 @@ module.exports = function (RED) {
53
54
  // conditional rate: while condTag is true (or non-zero), read every condInterval ms
54
55
  condTag: String(config.condTag || '').trim() || undefined,
55
56
  condIntervalMs: Number(config.condInterval) || 100,
57
+ // PLC subscription with the interval as cycle time (falls back to cyclic reads)
58
+ push: config.mode === 'push',
56
59
  };
57
60
  ep.ready
58
61
  .then(() => ep.bridge.subscribe(params))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-s7-rust",
3
- "version": "1.0.5",
3
+ "version": "1.2.0",
4
4
  "description": "Siemens S7 nodes for Node-RED: S7comm and S7CommPlus (S7-1200/1500 symbolic access) clients written in Rust, running in-process (Node-API). Linux x64.",
5
5
  "keywords": [
6
6
  "node-red",
@@ -55,7 +55,8 @@
55
55
  "s7rs-read": "nodes/s7rs-read.js",
56
56
  "s7rs-write": "nodes/s7rs-write.js",
57
57
  "s7rs-watch": "nodes/s7rs-watch.js",
58
- "s7rs-info": "nodes/s7rs-info.js"
58
+ "s7rs-info": "nodes/s7rs-info.js",
59
+ "s7rs-alarms": "nodes/s7rs-alarms.js"
59
60
  }
60
61
  },
61
62
  "scripts": {