node-red-contrib-ccu 4.10.3 → 4.11.1
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 +46 -0
- package/README.md +1 -5
- package/nodes/ccu-connection.html +11 -0
- package/nodes/ccu-connection.js +121 -41
- package/nodes/lib/cachefile.js +119 -2
- package/nodes/lib/metaprovider.js +26 -8
- package/nodes/locales/de/ccu-connection.html +7 -1
- package/nodes/locales/en-US/ccu-connection.html +3 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,52 @@ Notable changes to node-red-contrib-ccu. Format follows
|
|
|
5
5
|
user-visible symptom and the cause, not the commit list (the release notes
|
|
6
6
|
append commits automatically).
|
|
7
7
|
|
|
8
|
+
## 4.11.1 (2026-11-21)
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **openccu-lite: the interfaces stayed disconnected after the system was
|
|
13
|
+
unreachable for more than about 40 seconds, until Node-RED was restarted
|
|
14
|
+
or the flow deployed again.** During a firmware update, a longer reboot or
|
|
15
|
+
a network outage the connection took three unanswered probes as "this
|
|
16
|
+
system is no longer openccu-lite" and closed lite-rpc; when the system
|
|
17
|
+
answered again, the names came back but the interfaces did not. A system
|
|
18
|
+
that does not answer is now waited for: lite-rpc and the names keep
|
|
19
|
+
reconnecting and pick up where they were once the system is back (the log
|
|
20
|
+
says `the system does not answer … - waiting for it` once). lite-rpc is
|
|
21
|
+
closed only when the system answers as something other than openccu-lite,
|
|
22
|
+
and if it is detected as openccu-lite again later, lite-rpc starts again
|
|
23
|
+
with the same interfaces, without a deploy. (#190, @reini12345)
|
|
24
|
+
|
|
25
|
+
## 4.11.0 (2026-11-20)
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **Far fewer writes to the SD card.** The connection used to rewrite its
|
|
30
|
+
cache files more often than needed: the device table at every start, the
|
|
31
|
+
names file on a CCU at every names re-read (every 15 minutes by default,
|
|
32
|
+
even when nothing had changed), the value cache twice per redeploy or
|
|
33
|
+
restart, and `paramsets.json` (several megabytes) whole after every 30
|
|
34
|
+
fetched descriptions. Now the device table and the names file are written
|
|
35
|
+
only when their content changed, the names file no longer carries system
|
|
36
|
+
variable and program values (they were never read back),
|
|
37
|
+
`paramsets.json` is written once per fetch round and only when it gained a
|
|
38
|
+
new description (the shipped file is read directly instead of being
|
|
39
|
+
copied), and the value cache is written at stop and otherwise at most every
|
|
40
|
+
60 minutes. A redeploy now writes about half as much, and on a CCU the
|
|
41
|
+
connection writes nothing while idle.
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- **Setting "Value cache write (min)"** in the connection node: how often the
|
|
46
|
+
value cache is written while Node-RED runs (default 60, 0 = only at stop).
|
|
47
|
+
A longer interval writes less; after a power cut the cache is at most that
|
|
48
|
+
old, and the values are read fresh from the CCU at the next start anyway.
|
|
49
|
+
- **A warning when the connection's values go into a file context store.**
|
|
50
|
+
Node-RED's `localfilesystem` store rewrites the whole global context on
|
|
51
|
+
every change, which writes a lot with many devices; the help text explains
|
|
52
|
+
it.
|
|
53
|
+
|
|
8
54
|
## 4.10.3 (2026-11-20)
|
|
9
55
|
|
|
10
56
|
### Fixed
|
package/README.md
CHANGED
|
@@ -24,13 +24,9 @@ for installation on a Homematic CCU3 or RaspberryMatic.
|
|
|
24
24
|
|
|
25
25
|
Some example flows can be found in the [RedMatic Wiki](https://github.com/rdmtc/RedMatic/wiki) (German language).
|
|
26
26
|
|
|
27
|
-
**A modern Browser is required, Internet Explorer won't work.**
|
|
28
|
-
|
|
29
|
-
**Starting with Version 3.x these Nodes need Node-RED >= 1.0 to work correctly**
|
|
30
|
-
|
|
31
27
|
## openccu-lite
|
|
32
28
|
|
|
33
|
-
[openccu-lite](https://github.com/
|
|
29
|
+
[openccu-lite](https://github.com/openccu-lite/openccu-lite) is a Homematic CCU firmware based on OpenCCU **without
|
|
34
30
|
ReGaHSS**. The interface processes (`rfd`, `hs485d`, `hmipserver`) are the same, so everything these nodes do over
|
|
35
31
|
BINRPC/XMLRPC works unchanged. Device, channel, room and function names come from the system's metadata API instead of
|
|
36
32
|
ReGaHSS; the connection node detects this at start (`GET /api/meta/v1/version`), nothing has to be configured, and
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
regaPoll: {value: true},
|
|
39
39
|
regaInterval: {value: 30},
|
|
40
40
|
regaMetaInterval: {value: 15},
|
|
41
|
+
valuesSaveInterval: {value: 60},
|
|
41
42
|
|
|
42
43
|
rpcPing: {value: true},
|
|
43
44
|
rpcPingTimeout: {value: 60},
|
|
@@ -92,6 +93,11 @@
|
|
|
92
93
|
$('#node-config-input-regaMetaInterval').val(15);
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
if (typeof this.valuesSaveInterval === 'undefined') {
|
|
97
|
+
this.valuesSaveInterval = 60;
|
|
98
|
+
$('#node-config-input-valuesSaveInterval').val(60);
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
const $nodeConfigInputHost = $('#node-config-input-host');
|
|
96
102
|
const $nodeConfigInputName = $('#node-config-input-name');
|
|
97
103
|
const $nodeConfigInputRpcServerHost = $('#node-config-input-rpcServerHost');
|
|
@@ -423,6 +429,11 @@
|
|
|
423
429
|
<input type="text" id="node-config-input-regaMetaInterval">
|
|
424
430
|
<small>How often channel names, rooms and functions are re-read. 0 = never (the behaviour before 4.3.0).</small>
|
|
425
431
|
</div>
|
|
432
|
+
<div class="form-row">
|
|
433
|
+
<label for="node-config-input-valuesSaveInterval"><i class="icon-tag"></i> Value cache write (min)</label>
|
|
434
|
+
<input type="text" id="node-config-input-valuesSaveInterval">
|
|
435
|
+
<small>The file with the last values (the cache for the next start) is written when Node-RED stops, and while it runs at most this often. 0 = only when stopping: fewest writes to the SD card, but after a power cut the file holds the values of the last stop.</small>
|
|
436
|
+
</div>
|
|
426
437
|
<div class="form-row">
|
|
427
438
|
<label for="node-config-input-queueTimeout"><i class="icon-tag"></i> Queue timeout (ms)</label>
|
|
428
439
|
<input type="text" id="node-config-input-queueTimeout">
|
package/nodes/ccu-connection.js
CHANGED
|
@@ -20,7 +20,14 @@ const metaProvider = require('./lib/metaprovider.js');
|
|
|
20
20
|
const {InitRetry, retryDelay, RETRY_INTERVAL} = require('./lib/initretry.js');
|
|
21
21
|
const lite = require('./lib/lite.js');
|
|
22
22
|
const {Pairings} = require('./lib/pairing.js');
|
|
23
|
-
const {
|
|
23
|
+
const {
|
|
24
|
+
writeJsonAtomic,
|
|
25
|
+
writeJsonIfChanged,
|
|
26
|
+
readText,
|
|
27
|
+
lastWritten,
|
|
28
|
+
contextStoreModule,
|
|
29
|
+
DebouncedSave,
|
|
30
|
+
} = require('./lib/cachefile.js');
|
|
24
31
|
const {SubscriptionIndex, matches: filterMatches} = require('./lib/subscriptions.js');
|
|
25
32
|
const xmlrpc = require('homematic-xmlrpc');
|
|
26
33
|
const binrpc = require('binrpc');
|
|
@@ -667,6 +674,16 @@ module.exports = function (RED) {
|
|
|
667
674
|
|
|
668
675
|
this.globalContext = this.context().global;
|
|
669
676
|
this.contextStore = config.contextStore;
|
|
677
|
+
if (contextStoreModule(RED.settings, this.contextStore) === 'localfilesystem') {
|
|
678
|
+
// the values object goes into the global context once and changes in place: a
|
|
679
|
+
// file store writes the whole global context, these values with it, whenever
|
|
680
|
+
// anything else in it is set
|
|
681
|
+
this.logger.warn(
|
|
682
|
+
'context store "' +
|
|
683
|
+
this.contextStore +
|
|
684
|
+
'" keeps the global context in a file: every change of the global context rewrites it with all values of this connection - a memory store writes nothing to disk',
|
|
685
|
+
);
|
|
686
|
+
}
|
|
670
687
|
|
|
671
688
|
if (ccu.network.listen.includes(config.rpcServerHost)) {
|
|
672
689
|
this.rpcServerHost = config.rpcServerHost;
|
|
@@ -736,6 +753,8 @@ module.exports = function (RED) {
|
|
|
736
753
|
this.liteConfig = config;
|
|
737
754
|
this.lite = null;
|
|
738
755
|
this.liteIfaces = [];
|
|
756
|
+
// B-48: the interfaces lite-rpc carried when onGone closed it, for resumeLite()
|
|
757
|
+
this.liteResume = null;
|
|
739
758
|
// B-44: the scopes the system lists for the lite-rpc credential (undefined: not known)
|
|
740
759
|
// and, per interface, why it cannot be reached (the nodes show it)
|
|
741
760
|
this.liteScopes = undefined;
|
|
@@ -747,6 +766,14 @@ module.exports = function (RED) {
|
|
|
747
766
|
this.regaMetaInterval =
|
|
748
767
|
config.regaMetaInterval === undefined ? 15 : Number.parseInt(config.regaMetaInterval, 10) || 0;
|
|
749
768
|
this.regaInterval = Number.parseInt(config.regaInterval, 10);
|
|
769
|
+
// the values cache file is written at stop, and while running at most every this many
|
|
770
|
+
// minutes (after the start's read of all values, a resync, a prune); 0 = only at stop.
|
|
771
|
+
// A write is the whole file - megabytes on a big system, on the SD card.
|
|
772
|
+
this.valuesSaveInterval =
|
|
773
|
+
config.valuesSaveInterval === undefined || config.valuesSaveInterval === ''
|
|
774
|
+
? 60
|
|
775
|
+
: Math.max(0, Number.parseInt(config.valuesSaveInterval, 10) || 0);
|
|
776
|
+
this.valuesSaveTimer = null;
|
|
750
777
|
this.hadTimeout = new Set();
|
|
751
778
|
|
|
752
779
|
this.enabledIfaces = [];
|
|
@@ -754,7 +781,6 @@ module.exports = function (RED) {
|
|
|
754
781
|
this.clients = {};
|
|
755
782
|
this.servers = {};
|
|
756
783
|
|
|
757
|
-
this.newParamsetDescriptionCount = 0;
|
|
758
784
|
this.paramsetQueue = [];
|
|
759
785
|
// B-36: iface/address/paramset whose description the interface refused
|
|
760
786
|
// with a fault (-2 Invalid device for an address it does not know) - not
|
|
@@ -1219,8 +1245,11 @@ module.exports = function (RED) {
|
|
|
1219
1245
|
*/
|
|
1220
1246
|
writeCache(file, what, data) {
|
|
1221
1247
|
try {
|
|
1222
|
-
|
|
1223
|
-
|
|
1248
|
+
if (writeJsonIfChanged(file, data)) {
|
|
1249
|
+
this.logger.info(what + ' saved to', file);
|
|
1250
|
+
} else {
|
|
1251
|
+
this.logger.debug(what + ' unchanged, not written');
|
|
1252
|
+
}
|
|
1224
1253
|
} catch (error) {
|
|
1225
1254
|
this.logger.error(what + ' not saved to ' + file + ': ' + error.message);
|
|
1226
1255
|
}
|
|
@@ -1240,18 +1269,44 @@ module.exports = function (RED) {
|
|
|
1240
1269
|
rooms: this.rooms,
|
|
1241
1270
|
functions: this.functions,
|
|
1242
1271
|
groups: this.groups,
|
|
1243
|
-
|
|
1244
|
-
|
|
1272
|
+
// no system variables and programs: they are not read back at start (see
|
|
1273
|
+
// loadRegadata), and their values and timestamps made the file differ at every
|
|
1274
|
+
// write, so it was rewritten although nothing it is read for had changed
|
|
1245
1275
|
});
|
|
1246
1276
|
return Promise.resolve();
|
|
1247
1277
|
}
|
|
1248
1278
|
|
|
1249
1279
|
/**
|
|
1250
|
-
*
|
|
1280
|
+
* The values cache file. At stop and after a prune (`now`: datapoints of deleted devices
|
|
1281
|
+
* must leave the file) it is written at once; otherwise at most every `valuesSaveInterval`
|
|
1282
|
+
* minutes, counted from the file's last write (the one at the previous stop too), so a
|
|
1283
|
+
* redeploy or a restart does not write it twice - the values in it are the cache for the
|
|
1284
|
+
* next start, the live ones come from the interfaces.
|
|
1285
|
+
* @param {boolean} [now] write at once
|
|
1251
1286
|
* @returns {Promise<any>}
|
|
1252
1287
|
*/
|
|
1253
|
-
saveValues() {
|
|
1254
|
-
|
|
1288
|
+
saveValues(now) {
|
|
1289
|
+
clearTimeout(this.valuesSaveTimer);
|
|
1290
|
+
this.valuesSaveTimer = null;
|
|
1291
|
+
if (now) {
|
|
1292
|
+
this.writeCache(this.valuesFile, 'values', {values: this.values});
|
|
1293
|
+
return Promise.resolve();
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
if (!this.valuesSaveInterval) {
|
|
1297
|
+
return Promise.resolve();
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
const due = lastWritten(this.valuesFile) + this.valuesSaveInterval * 60000 - Date.now();
|
|
1301
|
+
if (due <= 0) {
|
|
1302
|
+
this.writeCache(this.valuesFile, 'values', {values: this.values});
|
|
1303
|
+
} else {
|
|
1304
|
+
this.valuesSaveTimer = setTimeout(() => this.saveValues(), Math.min(due, 2147483647));
|
|
1305
|
+
if (typeof this.valuesSaveTimer.unref === 'function') {
|
|
1306
|
+
this.valuesSaveTimer.unref();
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1255
1310
|
return Promise.resolve();
|
|
1256
1311
|
}
|
|
1257
1312
|
|
|
@@ -1262,7 +1317,7 @@ module.exports = function (RED) {
|
|
|
1262
1317
|
loadMetadata() {
|
|
1263
1318
|
return new Promise((resolve) => {
|
|
1264
1319
|
try {
|
|
1265
|
-
this.metadata = JSON.parse(
|
|
1320
|
+
this.metadata = JSON.parse(readText(this.metadataFile));
|
|
1266
1321
|
this.logger.info('metadata loaded from', this.metadataFile);
|
|
1267
1322
|
resolve();
|
|
1268
1323
|
} catch {
|
|
@@ -1283,7 +1338,7 @@ module.exports = function (RED) {
|
|
|
1283
1338
|
loadRegadata() {
|
|
1284
1339
|
return new Promise((resolve) => {
|
|
1285
1340
|
try {
|
|
1286
|
-
const regadata = JSON.parse(
|
|
1341
|
+
const regadata = JSON.parse(readText(this.regadataFile));
|
|
1287
1342
|
this.logger.info('regadata loaded from', this.regadataFile);
|
|
1288
1343
|
this.channelNames = regadata.channelNames;
|
|
1289
1344
|
this.regaIdChannel = regadata.regaIdChannel;
|
|
@@ -1301,7 +1356,7 @@ module.exports = function (RED) {
|
|
|
1301
1356
|
this.functions = regadata.functions;
|
|
1302
1357
|
}
|
|
1303
1358
|
|
|
1304
|
-
/*
|
|
1359
|
+
/* system variables and programs are polled anew and no longer saved in the file
|
|
1305
1360
|
this.sysvar = regadata.sysvar;
|
|
1306
1361
|
Object.keys(this.sysvar).forEach(s => {
|
|
1307
1362
|
this.sysvar[s].fromFile = true;
|
|
@@ -1360,7 +1415,8 @@ module.exports = function (RED) {
|
|
|
1360
1415
|
* Merges the descriptions fetched since the last save into the file on disk. The file
|
|
1361
1416
|
* holds every description ever known (the vendored ones and the fetched ones, in the
|
|
1362
1417
|
* format other consumers and the editor read); the memory holds only the present types,
|
|
1363
|
-
* so the file is read, merged and written back atomically (task 28).
|
|
1418
|
+
* so the file is read, merged and written back atomically (task 28). Descriptions the
|
|
1419
|
+
* file holds as they are already are no reason to write it.
|
|
1364
1420
|
* @returns {Promise<any>}
|
|
1365
1421
|
*/
|
|
1366
1422
|
saveParamsets() {
|
|
@@ -1373,16 +1429,25 @@ module.exports = function (RED) {
|
|
|
1373
1429
|
|
|
1374
1430
|
try {
|
|
1375
1431
|
const all = this.readParamsetFile() || {};
|
|
1376
|
-
|
|
1432
|
+
const changed = names.filter(
|
|
1433
|
+
(name) => JSON.stringify(all[name]) !== JSON.stringify(this.paramsetNew[name]),
|
|
1434
|
+
);
|
|
1435
|
+
for (const name of changed) {
|
|
1377
1436
|
all[name] = this.paramsetNew[name];
|
|
1378
1437
|
}
|
|
1379
1438
|
|
|
1380
|
-
writeJsonAtomic(this.paramsetFile, all, ' ');
|
|
1381
1439
|
this.paramsetNew = {};
|
|
1440
|
+
if (changed.length === 0) {
|
|
1441
|
+
this.logger.debug('paramsets: the fetched descriptions are in the file already');
|
|
1442
|
+
resolve();
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
writeJsonAtomic(this.paramsetFile, all, ' ');
|
|
1382
1447
|
this.logger.info(
|
|
1383
1448
|
'paramsets saved to',
|
|
1384
1449
|
this.paramsetFile,
|
|
1385
|
-
|
|
1450
|
+
changed.length,
|
|
1386
1451
|
'new,',
|
|
1387
1452
|
Object.keys(all).length,
|
|
1388
1453
|
'total',
|
|
@@ -1396,23 +1461,18 @@ module.exports = function (RED) {
|
|
|
1396
1461
|
}
|
|
1397
1462
|
|
|
1398
1463
|
/**
|
|
1399
|
-
* Parses the paramsets file - the userDir's, or the
|
|
1400
|
-
* yet
|
|
1464
|
+
* Parses the paramsets file - the userDir's, or the shipped one while the userDir has none
|
|
1465
|
+
* yet. The userDir's is written the first time a description the shipped file lacks is
|
|
1466
|
+
* saved (the whole set, in the same format); a copy of 14 MB at the first start, before,
|
|
1467
|
+
* was a write for nothing on a system whose devices the shipped file knows.
|
|
1401
1468
|
* @returns {object|null} every description the file holds, or null when there is none
|
|
1402
1469
|
*/
|
|
1403
1470
|
readParamsetFile() {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
fs.copyFileSync(vendored, this.paramsetFile);
|
|
1408
|
-
this.logger.info('paramsets copied from', vendored, 'to', this.paramsetFile);
|
|
1409
|
-
} catch (error) {
|
|
1410
|
-
this.logger.error('error copying paramsets ' + error.message);
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1471
|
+
const file = fs.existsSync(this.paramsetFile)
|
|
1472
|
+
? this.paramsetFile
|
|
1473
|
+
: path.join(__dirname, '..', 'paramsets.json');
|
|
1414
1474
|
try {
|
|
1415
|
-
return JSON.parse(fs.readFileSync(
|
|
1475
|
+
return JSON.parse(fs.readFileSync(file));
|
|
1416
1476
|
} catch (error) {
|
|
1417
1477
|
if (error.code === 'ENOENT') {
|
|
1418
1478
|
this.logger.info('paramsets new empty');
|
|
@@ -1569,7 +1629,9 @@ module.exports = function (RED) {
|
|
|
1569
1629
|
|
|
1570
1630
|
this.metadataSave.flush();
|
|
1571
1631
|
this.saveRegadata();
|
|
1572
|
-
this.saveValues();
|
|
1632
|
+
this.saveValues(true);
|
|
1633
|
+
// descriptions fetched since the last save (a stop in the middle of the queue)
|
|
1634
|
+
this.saveParamsets();
|
|
1573
1635
|
|
|
1574
1636
|
this.rpcClose()
|
|
1575
1637
|
.then(() => {
|
|
@@ -1826,7 +1888,24 @@ module.exports = function (RED) {
|
|
|
1826
1888
|
);
|
|
1827
1889
|
}
|
|
1828
1890
|
|
|
1829
|
-
return this.checkLiteScopes()
|
|
1891
|
+
return this.checkLiteScopes()
|
|
1892
|
+
.then(() => this.startMetaProvider())
|
|
1893
|
+
.then(() => this.resumeLite());
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* B-48: openccu-lite detected again after onGone closed lite-rpc - the interfaces it
|
|
1898
|
+
* carried go through it again, without a deploy. A no-op at the first detection.
|
|
1899
|
+
*/
|
|
1900
|
+
resumeLite() {
|
|
1901
|
+
const ifaces = this.liteResume;
|
|
1902
|
+
this.liteResume = null;
|
|
1903
|
+
if (!ifaces || ifaces.length === 0 || this.closing || this.lite) {
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
this.logger.info('openccu-lite detected again: lite-rpc starts again for ' + ifaces.join(', '));
|
|
1908
|
+
this.startLite(ifaces);
|
|
1830
1909
|
}
|
|
1831
1910
|
|
|
1832
1911
|
/**
|
|
@@ -1896,11 +1975,15 @@ module.exports = function (RED) {
|
|
|
1896
1975
|
this.meta = null;
|
|
1897
1976
|
this.lastMetaProbe = 0;
|
|
1898
1977
|
if (this.lite) {
|
|
1899
|
-
// task 14: lite-rpc went with the system's answer; the CCU way needs a deploy
|
|
1978
|
+
// task 14: lite-rpc went with the system's answer; the CCU way needs a deploy.
|
|
1979
|
+
// B-48: the provider calls this only for a system that answers as something
|
|
1980
|
+
// else (never for one that does not answer); should it be openccu-lite again
|
|
1981
|
+
// at the next detection, lite-rpc starts again with the same interfaces
|
|
1982
|
+
this.liteResume = this.liteIfaces.slice();
|
|
1900
1983
|
this.stopLite();
|
|
1901
1984
|
this.liteIfaces.forEach((iface) => this.setIfaceStatus(iface, false));
|
|
1902
1985
|
this.logger.warn(
|
|
1903
|
-
'lite-rpc closed: the system no longer answers as openccu-lite - deploy again to reach the interfaces the CCU way',
|
|
1986
|
+
'lite-rpc closed: the system no longer answers as openccu-lite - deploy again to reach the interfaces the CCU way (lite-rpc starts again by itself if the system answers as openccu-lite again)',
|
|
1904
1987
|
);
|
|
1905
1988
|
}
|
|
1906
1989
|
|
|
@@ -3744,16 +3827,13 @@ module.exports = function (RED) {
|
|
|
3744
3827
|
this.methodCall(iface, 'getParamsetDescription', [address, paramset], {quiet: true})
|
|
3745
3828
|
.then((res) => {
|
|
3746
3829
|
//this.logger.trace('paramsetDescription', name);
|
|
3747
|
-
this.newParamsetDescriptionCount += 1;
|
|
3748
3830
|
this.newParamsetDescription = true;
|
|
3749
3831
|
this.paramsetDescriptions[name] = res;
|
|
3750
3832
|
this.paramsetNew[name] = res;
|
|
3751
3833
|
this.paramsetFileMissing.delete(name);
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
this.saveParamsets();
|
|
3756
|
-
}
|
|
3834
|
+
// saved once the queue is through (or at stop): every save rewrites the
|
|
3835
|
+
// whole file, 14 MB and more - one every 30 descriptions was a dozen
|
|
3836
|
+
// rewrites for a system whose firmwares the shipped file lacks
|
|
3757
3837
|
})
|
|
3758
3838
|
.catch((error) => {
|
|
3759
3839
|
// B-36: one line naming the address and the paramset; a
|
|
@@ -3960,7 +4040,7 @@ module.exports = function (RED) {
|
|
|
3960
4040
|
const pruned = this.pruneValues();
|
|
3961
4041
|
if (pruned) {
|
|
3962
4042
|
this.logger.info('values cache: dropped', pruned, 'values of devices not in the device table');
|
|
3963
|
-
this.saveValues();
|
|
4043
|
+
this.saveValues(true);
|
|
3964
4044
|
}
|
|
3965
4045
|
}
|
|
3966
4046
|
|
|
@@ -3977,7 +4057,7 @@ module.exports = function (RED) {
|
|
|
3977
4057
|
const pruned = this.pruneValues();
|
|
3978
4058
|
if (pruned) {
|
|
3979
4059
|
this.logger.info('values cache: dropped', pruned, 'values of devices not in the device table');
|
|
3980
|
-
this.saveValues();
|
|
4060
|
+
this.saveValues(true);
|
|
3981
4061
|
}
|
|
3982
4062
|
}, this.valuesPruneDelay);
|
|
3983
4063
|
}
|
package/nodes/lib/cachefile.js
CHANGED
|
@@ -8,11 +8,51 @@
|
|
|
8
8
|
* A burst of changes is written once: `DebouncedSave` collects the requests of a short window into
|
|
9
9
|
* one write - at start every interface reports its device list within the same second, and before
|
|
10
10
|
* there was one full rewrite and one log line per interface.
|
|
11
|
+
*
|
|
12
|
+
* Nothing unchanged is written: `writeJsonIfChanged` keeps a digest of what each file holds (what
|
|
13
|
+
* was written, or read at start) and skips a write whose content is the same. On a CCU the names
|
|
14
|
+
* are re-read every 15 minutes and every start re-sent the same device table - each of them was a
|
|
15
|
+
* full rewrite on the SD card before. `lastWritten` lets the values file wait for its interval
|
|
16
|
+
* across a redeploy or a restart.
|
|
11
17
|
*/
|
|
12
18
|
|
|
19
|
+
const crypto = require('crypto');
|
|
13
20
|
const fs = require('fs');
|
|
14
21
|
const path = require('path');
|
|
15
22
|
|
|
23
|
+
/** file -> {hash, ino, size, mtimeMs} of the content it holds, as far as this process knows */
|
|
24
|
+
const digests = new Map();
|
|
25
|
+
|
|
26
|
+
/** @param {string} text @returns {string} */
|
|
27
|
+
function digest(text) {
|
|
28
|
+
return crypto.createHash('sha1').update(text).digest('hex');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** remembers what `file` holds now; its size and time tell a later change from outside */
|
|
32
|
+
function remember(file, hash) {
|
|
33
|
+
try {
|
|
34
|
+
const {ino, size, mtimeMs} = fs.statSync(file);
|
|
35
|
+
digests.set(file, {hash, ino, size, mtimeMs});
|
|
36
|
+
} catch {
|
|
37
|
+
digests.delete(file);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** whether `file` still holds the content with this digest */
|
|
42
|
+
function holds(file, hash) {
|
|
43
|
+
const known = digests.get(file);
|
|
44
|
+
if (!known || known.hash !== hash) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const {ino, size, mtimeMs} = fs.statSync(file);
|
|
50
|
+
return ino === known.ino && size === known.size && mtimeMs === known.mtimeMs;
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
16
56
|
/**
|
|
17
57
|
* Writes `data` as JSON to `file` by way of a temporary file and a rename; an existing file's mode
|
|
18
58
|
* is kept.
|
|
@@ -21,12 +61,21 @@ const path = require('path');
|
|
|
21
61
|
* @param {string|number} [indent] JSON.stringify's third argument
|
|
22
62
|
*/
|
|
23
63
|
function writeJsonAtomic(file, data, indent) {
|
|
64
|
+
writeTextAtomic(file, JSON.stringify(data, null, indent));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Writes `text` to `file` by way of a temporary file and a rename; an existing file's mode is kept.
|
|
69
|
+
* @param {string} file
|
|
70
|
+
* @param {string} text
|
|
71
|
+
*/
|
|
72
|
+
function writeTextAtomic(file, text) {
|
|
24
73
|
const temporary = path.join(
|
|
25
74
|
path.dirname(file),
|
|
26
75
|
'.' + path.basename(file) + '.' + process.pid + '.' + Date.now().toString(36) + '.tmp',
|
|
27
76
|
);
|
|
28
77
|
try {
|
|
29
|
-
fs.writeFileSync(temporary,
|
|
78
|
+
fs.writeFileSync(temporary, text);
|
|
30
79
|
// the rename replaces the inode: an existing file's mode is kept (0600 on a system that
|
|
31
80
|
// made it so), a new one gets the umask's
|
|
32
81
|
let mode;
|
|
@@ -39,7 +88,9 @@ function writeJsonAtomic(file, data, indent) {
|
|
|
39
88
|
}
|
|
40
89
|
|
|
41
90
|
fs.renameSync(temporary, file);
|
|
91
|
+
remember(file, digest(text));
|
|
42
92
|
} catch (error) {
|
|
93
|
+
digests.delete(file);
|
|
43
94
|
try {
|
|
44
95
|
fs.unlinkSync(temporary);
|
|
45
96
|
} catch {}
|
|
@@ -48,6 +99,34 @@ function writeJsonAtomic(file, data, indent) {
|
|
|
48
99
|
}
|
|
49
100
|
}
|
|
50
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Writes `data` as JSON to `file` atomically - unless the file holds exactly that already.
|
|
104
|
+
* @param {string} file
|
|
105
|
+
* @param {*} data
|
|
106
|
+
* @param {string|number} [indent] JSON.stringify's third argument
|
|
107
|
+
* @returns {boolean} whether the file was written
|
|
108
|
+
*/
|
|
109
|
+
function writeJsonIfChanged(file, data, indent) {
|
|
110
|
+
const text = JSON.stringify(data, null, indent);
|
|
111
|
+
if (holds(file, digest(text))) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
writeTextAtomic(file, text);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Reads a file and remembers its digest, so the same content is not written back.
|
|
121
|
+
* @param {string} file
|
|
122
|
+
* @returns {string} the file's text
|
|
123
|
+
*/
|
|
124
|
+
function readText(file) {
|
|
125
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
126
|
+
remember(file, digest(text));
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
|
|
51
130
|
class DebouncedSave {
|
|
52
131
|
/**
|
|
53
132
|
* @param {Function} write does the write; called once per burst
|
|
@@ -102,4 +181,42 @@ class DebouncedSave {
|
|
|
102
181
|
}
|
|
103
182
|
}
|
|
104
183
|
|
|
105
|
-
|
|
184
|
+
/**
|
|
185
|
+
* When `file` was last written, ms since the epoch (its modification time - a write of this
|
|
186
|
+
* process or of the one before a restart), 0 when there is none.
|
|
187
|
+
* @param {string} file
|
|
188
|
+
* @returns {number}
|
|
189
|
+
*/
|
|
190
|
+
function lastWritten(file) {
|
|
191
|
+
try {
|
|
192
|
+
return fs.statSync(file).mtimeMs;
|
|
193
|
+
} catch {
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The module of one of Node-RED's context stores - a file store ('localfilesystem') writes the
|
|
200
|
+
* connection's values to disk with every change of the global context ('memory', 'localfilesystem', ...), undefined
|
|
201
|
+
* when there is no such store. `default` may name another store.
|
|
202
|
+
* @param {object} settings RED.settings
|
|
203
|
+
* @param {string} name
|
|
204
|
+
* @returns {string|undefined}
|
|
205
|
+
*/
|
|
206
|
+
function contextStoreModule(settings, name) {
|
|
207
|
+
let stores;
|
|
208
|
+
try {
|
|
209
|
+
stores = settings.contextStorage;
|
|
210
|
+
} catch {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!stores || !name) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const store = typeof stores[name] === 'string' ? stores[stores[name]] : stores[name];
|
|
219
|
+
return store && typeof store.module === 'string' ? store.module : undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
module.exports = {writeJsonAtomic, writeJsonIfChanged, readText, lastWritten, contextStoreModule, DebouncedSave};
|
|
@@ -487,13 +487,13 @@ class MetaProvider {
|
|
|
487
487
|
this.logger = options.logger || SILENT;
|
|
488
488
|
this.onNames = options.onNames || NOOP;
|
|
489
489
|
this.onStatus = options.onStatus || NOOP;
|
|
490
|
-
// called when the box
|
|
491
|
-
//
|
|
490
|
+
// called when the box answers the version probe, but no longer as openccu-lite (a restored
|
|
491
|
+
// backup, a firmware swap) - B-48: a box that does not answer at all is waited for
|
|
492
492
|
this.onGone = options.onGone || NOOP;
|
|
493
|
-
this.goneAfter = options.goneAfter === undefined ?
|
|
493
|
+
this.goneAfter = options.goneAfter === undefined ? MetaProvider.defaults.goneAfter : options.goneAfter;
|
|
494
494
|
this.requestTimeout = options.requestTimeout || 10000;
|
|
495
|
-
this.retryMin = options.retryMin === undefined ?
|
|
496
|
-
this.retryMax = options.retryMax === undefined ?
|
|
495
|
+
this.retryMin = options.retryMin === undefined ? MetaProvider.defaults.retryMin : options.retryMin;
|
|
496
|
+
this.retryMax = options.retryMax === undefined ? MetaProvider.defaults.retryMax : options.retryMax;
|
|
497
497
|
this.emitDelay = options.emitDelay === undefined ? 100 : options.emitDelay;
|
|
498
498
|
this.attachTimeout = options.attachTimeout === undefined ? 15000 : options.attachTimeout;
|
|
499
499
|
this.createClient = options.createClient;
|
|
@@ -506,6 +506,7 @@ class MetaProvider {
|
|
|
506
506
|
this.streamRefused = false;
|
|
507
507
|
this.refusedLogged = false;
|
|
508
508
|
this.missedProbes = 0;
|
|
509
|
+
this.unanswered = false;
|
|
509
510
|
this.probeRetry = 0;
|
|
510
511
|
this.probeTimeout = null;
|
|
511
512
|
this.emitTimeout = null;
|
|
@@ -685,6 +686,7 @@ class MetaProvider {
|
|
|
685
686
|
_status(state) {
|
|
686
687
|
if (state === 'ready') {
|
|
687
688
|
this.missedProbes = 0;
|
|
689
|
+
this.unanswered = false;
|
|
688
690
|
this.probeRetry = 0;
|
|
689
691
|
clearTimeout(this.probeTimeout);
|
|
690
692
|
this.probeTimeout = null;
|
|
@@ -726,10 +728,14 @@ class MetaProvider {
|
|
|
726
728
|
* The version probe while the copy is not connected: needs no credential, and it is how a box
|
|
727
729
|
* that is no longer an openccu-lite is noticed without a Node-RED restart. A client of its own
|
|
728
730
|
* whose first connect failed is opened again once the system answers.
|
|
731
|
+
*
|
|
732
|
+
* B-48: only an answer counts towards `goneAfter` - a CCU's 404 or HTML. A box that does not
|
|
733
|
+
* answer (a timeout, a refused connection, 502/503/504 while it starts: an update, a reboot)
|
|
734
|
+
* has not become something else; the copy and lite-rpc keep reconnecting until it is back.
|
|
729
735
|
* @returns {Promise<void>}
|
|
730
736
|
*/
|
|
731
737
|
async _probe() {
|
|
732
|
-
const
|
|
738
|
+
const outcome = await detectOutcome({
|
|
733
739
|
host: this.host,
|
|
734
740
|
port: this.port,
|
|
735
741
|
tls: this.tls,
|
|
@@ -741,11 +747,19 @@ class MetaProvider {
|
|
|
741
747
|
return;
|
|
742
748
|
}
|
|
743
749
|
|
|
744
|
-
|
|
750
|
+
const {info} = outcome;
|
|
751
|
+
if (!info && outcome.inconclusive) {
|
|
752
|
+
this.logger[this.unanswered ? 'debug' : 'info'](
|
|
753
|
+
'the system does not answer (' + outcome.reason + ') - waiting for it, the connection is kept',
|
|
754
|
+
);
|
|
755
|
+
this.unanswered = true;
|
|
756
|
+
} else if (!info) {
|
|
745
757
|
this.missedProbes += 1;
|
|
746
758
|
if (this.missedProbes >= this.goneAfter) {
|
|
747
759
|
this.logger.warn(
|
|
748
|
-
'the
|
|
760
|
+
'the system answers, but not as openccu-lite (' +
|
|
761
|
+
outcome.reason +
|
|
762
|
+
', ' +
|
|
749
763
|
this.missedProbes +
|
|
750
764
|
' probes) - falling back to detection from scratch',
|
|
751
765
|
);
|
|
@@ -755,6 +769,7 @@ class MetaProvider {
|
|
|
755
769
|
}
|
|
756
770
|
} else {
|
|
757
771
|
this.missedProbes = 0;
|
|
772
|
+
this.unanswered = false;
|
|
758
773
|
if (this.owned && (this.connectFailed || this.streamRefused)) {
|
|
759
774
|
this.logger.debug('meta api: the system answers - connecting the names client again');
|
|
760
775
|
this._own();
|
|
@@ -786,6 +801,9 @@ class MetaProvider {
|
|
|
786
801
|
}
|
|
787
802
|
}
|
|
788
803
|
|
|
804
|
+
/** the probe's schedule and how many answers that are not openccu-lite end the copy (tests shorten them) */
|
|
805
|
+
MetaProvider.defaults = {retryMin: 5000, retryMax: 60000, goneAfter: 3};
|
|
806
|
+
|
|
789
807
|
module.exports = {
|
|
790
808
|
API_PATH,
|
|
791
809
|
LOCAL_TOKEN_FILE,
|
|
@@ -48,10 +48,16 @@
|
|
|
48
48
|
<li><b>ReGaHSS Poll-Interval</b>:
|
|
49
49
|
Das Zeitintervall in Sekunden in dem Systemvariablen von der CCU abgefragt werden.</li>
|
|
50
50
|
</ul>
|
|
51
|
+
<ul>
|
|
52
|
+
<li><b>Names/rooms refresh (min)</b>: Wie oft Kanalnamen, Räume und Gewerke neu gelesen werden; 0 nie. Die Datei mit den Namen wird nur geschrieben, wenn sich etwas geändert hat.</li>
|
|
53
|
+
</ul>
|
|
54
|
+
<ul>
|
|
55
|
+
<li><b>Value cache write (min)</b>: Der letzte Wert jedes Datenpunkts liegt in einer Datei im Node-RED-Verzeichnis, damit Nodes mit <i>cache</i> gleich nach dem nächsten Start einen Wert haben. Die Datei wird geschrieben, wenn Node-RED beendet oder die Verbindung neu deployt wird, und während es läuft höchstens so oft (nach dem Lesen aller Werte beim Start, nach einem Resync); Voreinstellung 60. 0 schreibt sie nur beim Beenden - die wenigsten Schreibzugriffe auf die SD-Karte, aber nach einem Stromausfall oder Absturz enthält die Datei die Werte vom letzten Beenden. So oder so kommen die aktuellen Werte nach einem Start wieder von der CCU. Auf einem großen System hat die Datei mehrere Megabyte, und jeder Schreibvorgang schreibt die ganze Datei.</li>
|
|
56
|
+
</ul>
|
|
51
57
|
<ul>
|
|
52
58
|
<li><b>Context-Store</b>: Hier wird der Node-RED Context-Store festgelegt in dem RedMatic die Zustände aller Geräte/Variablen vorhält.
|
|
53
59
|
|
|
54
|
-
Weiteres unter <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working</a> with context in der Node-RED Dokumentation.</li>
|
|
60
|
+
Weiteres unter <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working</a> with context in der Node-RED Dokumentation. Am besten ein Speicher-Store (memory): ein Datei-Store (<code>localfilesystem</code>) schreibt den ganzen globalen Kontext - mit allen Werten dieser Verbindung - jedes Mal neu, wenn irgendetwas darin gesetzt wird, und nutzt so die SD-Karte ab; das Log warnt dann.</li>
|
|
55
61
|
</ul>
|
|
56
62
|
<ul>
|
|
57
63
|
<li><b>openccu-lite Token</b>: Nur für <a href="https://github.com/hobbyquaker/openccu-lite" target="_blank">openccu-lite</a>,
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
</li>
|
|
24
24
|
<li><b>RPC ping</b> and <b>RPC ping timeout (s)</b>: How often the connection to the interface processes is checked with a ping, and after how many seconds without an answer it subscribes again. Off means no pings and no timeout-triggered re-init for this connection.</li>
|
|
25
25
|
<li><b>Rega poll</b>: Changes of system variables are not pushed by the CCU. With polling on, the variables and their values are read every <i>Rega poll interval</i> seconds.</li>
|
|
26
|
-
<li><b>Names/rooms refresh (min)</b>: How often channel names, rooms and functions are re-read; 0 never.</li>
|
|
26
|
+
<li><b>Names/rooms refresh (min)</b>: How often channel names, rooms and functions are re-read; 0 never. The names file is only written when something changed.</li>
|
|
27
|
+
<li><b>Value cache write (min)</b>: The last value of every datapoint is kept in a file in Node-RED's directory, so nodes with <i>cache</i> have a value right after the next start. The file is written when Node-RED stops or the connection is redeployed, and while it runs at most this often (after reading all values at the start, after a resync); 60 by default. 0 writes it only when stopping - the fewest writes to the SD card, but after a power cut or a crash the file holds the values of the last stop. Either way the live values come from the CCU again after a start. On a big system the file has several megabytes, and each write is the whole file.</li>
|
|
27
28
|
<li><b>Queue timeout (ms)</b>, <b>Queue pause (ms)</b>: The write queue's timeout per write and the pause between two writes.</li>
|
|
28
|
-
<li><b>Context Store</b>: The Node-RED context store the states of all devices and variables are kept in. See <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working with context</a> in the Node-RED documentation.</li>
|
|
29
|
+
<li><b>Context Store</b>: The Node-RED context store the states of all devices and variables are kept in. See <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working with context</a> in the Node-RED documentation. Use a memory store: a file store (<code>localfilesystem</code>) rewrites the whole global context - all values of this connection with it - every time anything in the global context is set, which wears an SD card; the log warns about it.</li>
|
|
29
30
|
<li><b>openccu-lite token</b>: Only for <a href="https://github.com/hobbyquaker/openccu-lite" target="_blank">openccu-lite</a>, a CCU firmware without ReGaHSS. Names, rooms and functions come from the system's metadata API there, which needs a token made under <i>Users</i> on the system. When Node-RED runs on the system itself (RedMatic) the field stays empty: the local token is read automatically. The token is kept, like the password, in Node-RED's credentials (encrypted in <code>flows_cred.json</code>, never in the flow, never in an export). A CCU, RaspberryMatic or OpenCCU ignores the field. openccu-lite has no system variables, programs or HM-Script; those nodes stay in the flow and report an error per message.</li>
|
|
30
31
|
<li><b>openccu-lite port</b>: Only needed when the system's web server is not on port 80 (443 with TLS).</li>
|
|
31
32
|
<li><b>openccu-lite interfaces</b>: How the interface processes are reached on an openccu-lite system. <i>auto</i> (the default) goes through the system's <b>lite-rpc</b> there - the requests over its web port, the events from a stream this node opens, one subscriber at the processes for every program on the system, the events replayed after a break, no callback server and no <code>init</code> of its own - and the CCU way on a CCU, RaspberryMatic or OpenCCU. The credential is the openccu-lite token above, or on the system itself RedMatic's own token, which the system mints for it; without one, or with a token that lacks <code>rpc:read</code> (one made for the names alone), the direct connection is used and the log says so; lite-rpc needs <code>rpc:read</code> for events and <code>rpc:operate</code> for commands. <i>CCU</i> keeps the direct connection with callbacks on openccu-lite as well (CUxD always goes that way; lite-rpc does not carry it). A flow from before 4.7.0 is moved to lite-rpc once at its first start on openccu-lite - the log says so - and a choice made here is never changed by a later version. The sysvar, program, script and poll nodes stay unavailable on openccu-lite either way.</li>
|