diff --git a/README.md b/README.md index bf3e459..d8af334 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ Remark: This feature is limited to the subnet of the ioBroker host. ### **WORK IN PROGRESS** --> +### 1.0.6 04.03.2024 +* (Jey Cee) Reduce system load during discovery process to prevent adapter crash + ### 1.0.5 04.02.2024 * (Jey Cee) remove discovery adapter as dependency * (Jey Cee) add possibility to choose the interface which will be used for ping operations diff --git a/io-package.json b/io-package.json index 4379dfb..c8ab310 100644 --- a/io-package.json +++ b/io-package.json @@ -1,8 +1,12 @@ { "common": { "name": "net-tools", - "version": "1.0.5", + "version": "1.0.6", "news": { + "1.0.6": { + "en": "Reduce system load during discovery process to prevent adapter crash", + "de": "Systemlast verringert während des Discovery prozess, um einen Absturz des Adapters zu verhindern." + }, "1.0.5": { "en": "remove discovery adapter as dependency \nadd possibility to choose the interface which will be used for ping operations \nadd possibility to enter IP range for device discovery \nadd auto search by configurable schedule \nfix/catch crash if device was deleted in objects and not in device management \nfix ping rights on lxc containers which prevent to ping devices", "de": "Discovery-Adapter als Abhängigkeit entfernen \nMöglichkeit hinzufügen, die Schnittstelle zu wählen, die für Ping-Operationen verwendet werden soll \nHinzufügen der Möglichkeit, einen IP-Bereich für die Geräteerkennung einzugeben \nautomatische Suche nach konfigurierbarem Zeitplan hinzufügen \nBehebung eines Absturzes, wenn ein Gerät in Objekten und nicht in der Geräteverwaltung gelöscht wurde \nPing-Rechte auf lxc-Containern beheben, die das Anpingen von Geräten verhindern" diff --git a/lib/devicemgmt.js b/lib/devicemgmt.js index 4b326b7..43504d3 100644 --- a/lib/devicemgmt.js +++ b/lib/devicemgmt.js @@ -251,7 +251,7 @@ class dmNetTools extends dmUtils.DeviceManagement { async handleDiscover(context) { context.showMessage( 'Dicovery started. This process will take a few minutes until all devices are discovered. You can close this dialog and continue working in the meantime.'); - const result = await this.adapter.discover(); + this.adapter.discover(); return { refresh: false }; } diff --git a/main.js b/main.js index 96bf975..88b969b 100644 --- a/main.js +++ b/main.js @@ -25,6 +25,25 @@ let wolTries = 3; let wolTimer = null; let discoverTimeout = null; let pingTimeout = null; +/** + * @type {Array.} + * + * Represents a list of tasks to be executed. + * + * Each element in the taskList array is an object with specific properties. It looks like: + * ``` + * { + * host: '192.168.11.15', // IP of the host + * extendedInfo: true, // Indicates if extended information should be obtained + * pingInterval: 60, // Time interval in seconds between two consecutive pings + * retries: 0, // The number of retries already made + * retryCounter: 0, // Used to count the number of retries + * stateAlive: { channel: '84b8b87e0294', state: 'alive' }, // Information about the 'alive' state + * stateTime: { channel: '84b8b87e0294', state: 'time' }, // Information about 'time' state + * stateRps: { channel: '84b8b87e0294', state: 'rps' } // Information about 'rps' state + * } + * ``` + */ let taskList = []; let cronJob = null; @@ -42,7 +61,7 @@ class NetTools extends utils.Adapter { }); this.on('ready', this.onReady.bind(this)); this.on('stateChange', this.onStateChange.bind(this)); - // this.on('objectChange', this.onObjectChange.bind(this)); + this.on('objectChange', this.onObjectChange.bind(this)); this.on('message', this.onMessage.bind(this)); this.on('unload', this.onUnload.bind(this)); @@ -89,6 +108,8 @@ class NetTools extends utils.Adapter { this.subscribeStates('*discover'); this.subscribeStates('*wol'); this.subscribeStates('*scan'); + this.subscribeObjects('*'); + } } @@ -127,20 +148,29 @@ class NetTools extends utils.Adapter { // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. - // /** - // * Is called if a subscribed object changes - // * @param {string} id - // * @param {ioBroker.Object | null | undefined} obj - // */ - // onObjectChange(id, obj) { - // if (obj) { - // // The object was changed - // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // this.log.info(`object ${id} deleted`); - // } - // } + /** + * Is called if a subscribed object changes + * @param {string} id + * @param {ioBroker.Object | null | undefined} obj + */ + onObjectChange(id, obj) { + if (obj) { + // The object was changed + + if (obj.type === 'device') { + // Look if ther is a host entry in taskList for the ip + const hostEntry = taskList.find(entry => entry.host === obj.native.ip); + if (hostEntry) { + hostEntry.pingInterval = obj.native.pingInterval; + hostEntry.retries = obj.native.retries; + } + taskList = taskList.map(entry => entry.host === hostEntry.host ? hostEntry : entry); + } + } else { + // The object was deleted + //this.log.info(`object ${id} deleted`); + } + } /** * Is called if a subscribed state changes @@ -187,7 +217,7 @@ class NetTools extends utils.Adapter { } } else { // The state was deleted - this.log.info(`state ${id} deleted`); + //this.log.info(`state ${id} deleted`); } } @@ -332,6 +362,8 @@ class NetTools extends utils.Adapter { } await Promise.all(promises); } + this.log.info('Discovery finished') + return true; } catch (err) { this.log.warn('Discovery faild: ' + err); return false; diff --git a/package.json b/package.json index 305d5e4..5f03a53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iobroker.net-tools", - "version": "1.0.5", + "version": "1.0.6", "description": "This adapter cyclic polls configured IPs, can send wake-on-lan packages and scan for open ports.", "author": { "name": "Jey Cee",