From 95571a001b81a9344e2b97163b441def2fbf9062 Mon Sep 17 00:00:00 2001 From: marcel Date: Wed, 18 Dec 2024 00:53:14 +0100 Subject: [PATCH] Undo changes in IFF-Agent --- NgsildAgent/lib/CloudProxy.js | 9 +++------ NgsildAgent/lib/ConnectionError.js | 4 ++-- NgsildAgent/lib/SparkplugbConnector.js | 2 +- NgsildAgent/package.json | 1 - 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/NgsildAgent/lib/CloudProxy.js b/NgsildAgent/lib/CloudProxy.js index 48921984..c961ade1 100644 --- a/NgsildAgent/lib/CloudProxy.js +++ b/NgsildAgent/lib/CloudProxy.js @@ -37,9 +37,6 @@ function updateToken (token) { const parsedToken = JSON.parse(token); common.saveToDeviceConfig('device_token', parsedToken.access_token); common.saveToDeviceConfig('refresh_token', parsedToken.refresh_token); - // Update device_token_expire - const expireTime = parsedToken.exp ? parsedToken.exp * 1000 : new Date().getTime() + 3600 * 1000; - common.saveToDeviceConfig('device_token_expire', expireTime); } function updateSecrets (me) { @@ -145,15 +142,15 @@ class CloudProxy { } } - async init() { + async init () { try { await this.spBProxy.init(); } catch (err) { - if (err.name === 'ConnectionError' && err.errno === 1) { + if (err instanceof ConnectionError && err.errno === 1) { this.logger.error('SparkplugB MQTT NBIRTH Metric not sent. Trying to refresh token.'); await this.checkDeviceToken(); return 1; - } else { + } else { // unrecoverable this.logger.error('Unexpected Error: ' + err.stack); return 2; } diff --git a/NgsildAgent/lib/ConnectionError.js b/NgsildAgent/lib/ConnectionError.js index 04a80456..a8c0fe77 100644 --- a/NgsildAgent/lib/ConnectionError.js +++ b/NgsildAgent/lib/ConnectionError.js @@ -30,9 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 2: other */ class ConnectionError extends Error { - constructor(errno, message) { + constructor (message, errno) { super(message); - this.name = 'ConnectionError'; + this.name = 'ConnectorError'; this.errno = errno; } } diff --git a/NgsildAgent/lib/SparkplugbConnector.js b/NgsildAgent/lib/SparkplugbConnector.js index 0006ecef..ed686808 100644 --- a/NgsildAgent/lib/SparkplugbConnector.js +++ b/NgsildAgent/lib/SparkplugbConnector.js @@ -178,7 +178,7 @@ class SparkplugbConnector { this.client.disconnect(); }; - updateDeviceInfo(deviceInfo) { + updateDeviceInfo = function (deviceInfo) { const me = this; me.client.updateDeviceInfo(deviceInfo); }; diff --git a/NgsildAgent/package.json b/NgsildAgent/package.json index bde885f4..dbe81978 100644 --- a/NgsildAgent/package.json +++ b/NgsildAgent/package.json @@ -17,7 +17,6 @@ "json-schema": "^0.4.0", "jwt-decode": "^2.2.0", "mqtt": "^5.3.4", - "request": "^2.88.0", "sqlite3": "^5.1.6", "validate-iri": "^1.0.1", "winston": "^3.7.2"