From 3574dfd3808a5894699e5fe246f723ebfee93de9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 23 Nov 2020 10:06:01 +0100 Subject: [PATCH] Push down more tunables in charging station template. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- docker/config.json | 4 +--- src/assets/config-template.json | 4 +--- src/charging-station/ChargingStation.ts | 28 +++++++++++++++++++++---- src/types/ChargingStationTemplate.ts | 2 ++ src/utils/Configuration.ts | 12 ++++++++--- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/docker/config.json b/docker/config.json index 7dcbd0b1..edd0da85 100644 --- a/docker/config.json +++ b/docker/config.json @@ -2,10 +2,8 @@ "supervisionURLs": [ "ws://server:8010/OCPP16/5c866e81a2d9593de43efdb4" ], - "statisticsDisplayInterval": 60, - "connectionTimeout": 10, - "autoReconnectMaxRetries": 10, "distributeStationsToTenantsEqually": true, + "statisticsDisplayInterval": 60, "useWorkerPool": false, "workerPoolSize": 16, "stationTemplateURLs": [ diff --git a/src/assets/config-template.json b/src/assets/config-template.json index 7b3dc148..adfe80ef 100644 --- a/src/assets/config-template.json +++ b/src/assets/config-template.json @@ -2,10 +2,8 @@ "supervisionURLs": [ "ws://localhost:8010/OCPP16/5be7fb271014d90008992f06" ], - "connectionTimeout": 10, - "autoReconnectMaxRetries": 10, - "statisticsDisplayInterval": 60, "distributeStationsToTenantsEqually": true, + "statisticsDisplayInterval": 60, "useWorkerPool": false, "workerPoolSize": 16, "stationTemplateURLs": [ diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b63bd2c2..1bf867cb 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -63,9 +63,7 @@ export default class ChargingStation { this._hasStopped = false; this._hasSocketRestarted = false; - this._connectionTimeout = Configuration.getConnectionTimeout() * 1000; // Ms, zero for disabling this._autoReconnectRetryCount = 0; - this._autoReconnectMaxRetries = Configuration.getAutoReconnectMaxRetries(); // -1 for unlimited this._requests = {} as Requests; this._messageQueue = [] as string[]; @@ -115,6 +113,8 @@ export default class ChargingStation { this._configuration = this._getTemplateChargingStationConfiguration(); this._supervisionUrl = this._getSupervisionURL(); this._wsConnectionUrl = this._supervisionUrl + '/' + this._stationInfo.name; + this._connectionTimeout = this._getConnectionTimeout() * 1000; // Ms, zero for disabling + this._autoReconnectMaxRetries = this._getAutoReconnectMaxRetries(); // -1 for unlimited // Build connectors if needed const maxConnectors = this._getMaxNumberOfConnectors(); if (maxConnectors <= 0) { @@ -244,6 +244,26 @@ export default class ChargingStation { return trxCount; } + _getConnectionTimeout(): number { + if (!Utils.isUndefined(this._stationInfo.connectionTimeout)) { + return this._stationInfo.connectionTimeout; + } + if (!Utils.isUndefined(Configuration.getConnectionTimeout())) { + return Configuration.getConnectionTimeout(); + } + return 30; + } + + _getAutoReconnectMaxRetries(): number { + if (!Utils.isUndefined(this._stationInfo.autoReconnectMaxRetries)) { + return this._stationInfo.autoReconnectMaxRetries; + } + if (!Utils.isUndefined(Configuration.getAutoReconnectMaxRetries())) { + return Configuration.getAutoReconnectMaxRetries(); + } + return -1; + } + _getPowerDivider(): number { let powerDivider = this._getNumberOfConnectors(); if (this._stationInfo.powerSharedByConnectors) { @@ -395,7 +415,7 @@ export default class ChargingStation { if (webSocketPingInterval > 0 && !this._webSocketPingSetInterval) { this._webSocketPingSetInterval = setInterval(() => { if (this._wsConnection?.readyState === WebSocket.OPEN) { - this._wsConnection.ping((): void => {}); + this._wsConnection.ping((): void => { }); } }, webSocketPingInterval * 1000); logger.info(this._logPrefix() + ' WebSocket ping started every ' + Utils.secondsToHHMMSS(webSocketPingInterval)); @@ -564,7 +584,7 @@ export default class ChargingStation { logger.error(`${this._logPrefix()} Socket: connection retry in ${Utils.roundTo(reconnectDelay, 2)}ms, timeout ${reconnectDelay - 100}ms`); await Utils.sleep(reconnectDelay); logger.error(this._logPrefix() + ' Socket: reconnecting try #' + this._autoReconnectRetryCount.toString()); - this._openWSConnection({ handshakeTimeout : reconnectDelay - 100 }); + this._openWSConnection({ handshakeTimeout: reconnectDelay - 100 }); } else if (this._autoReconnectMaxRetries !== -1) { logger.error(`${this._logPrefix()} Socket: max retries reached (${this._autoReconnectRetryCount}) or retry disabled (${this._autoReconnectMaxRetries})`); } diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 5c2081db..59eebc40 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -40,6 +40,8 @@ export default interface ChargingStationTemplate { useConnectorId0?: boolean; randomConnectors?: boolean; resetTime?: number; + connectionTimeout?: number; + autoReconnectMaxRetries?: number; reconnectExponentialDelay?: boolean; enableStatistics?: boolean; voltageOut?: number; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index fef4d93a..e22d8a8e 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -12,14 +12,20 @@ export default class Configuration { } static getConnectionTimeout(): number { - Configuration.deprecateConfigurationKey('autoReconnectTimeout', 'Use \'connectionTimeout\' instead'); + Configuration.deprecateConfigurationKey('autoReconnectTimeout', 'Use \'connectionTimeout\' in charging station instead'); + Configuration.deprecateConfigurationKey('connectionTimeout', 'Use it in charging station template instead'); // Read conf - return Utils.objectHasOwnProperty(Configuration.getConfig(), 'connectionTimeout') ? Configuration.getConfig().connectionTimeout : 10; + if (Utils.objectHasOwnProperty(Configuration.getConfig(), 'connectionTimeout')) { + return Configuration.getConfig().connectionTimeout; + } } static getAutoReconnectMaxRetries(): number { + Configuration.deprecateConfigurationKey('autoReconnectMaxRetries', 'Use it in charging station template instead'); // Read conf - return Utils.objectHasOwnProperty(Configuration.getConfig(), 'autoReconnectMaxRetries') ? Configuration.getConfig().autoReconnectMaxRetries : -1; + if (Utils.objectHasOwnProperty(Configuration.getConfig(), 'autoReconnectMaxRetries')) { + return Configuration.getConfig().autoReconnectMaxRetries; + } } static getStationTemplateURLs(): StationTemplateURL[] { -- 2.34.1