From 5c68da4d6ae3d794ba23217b895772ab670d48a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 18 Oct 2020 16:20:24 +0200 Subject: [PATCH] Handle OCPP parameter change to the heartbeat. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index a99e4887..19841765 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -305,7 +305,7 @@ class ChargingStation { _reconnect(error) { logger.error(this._basicFormatLog() + ' Socket: abnormally closed', error); - // Stop heartbeat interval + // Stop heartbeat if (this._heartbeatSetInterval) { clearInterval(this._heartbeatSetInterval); this._heartbeatSetInterval = null; @@ -430,6 +430,7 @@ class ChargingStation { } async _basicStartMessageSequence() { + // Start heartbeat this._startHeartbeat(this); // Build connectors if (!this._connectors) { @@ -495,8 +496,8 @@ class ChargingStation { handleResponseBootNotification(payload) { if (payload.status === 'Accepted') { this._heartbeatInterval = payload.interval * 1000; - this._addConfigurationKey('HeartBeatInterval', this._heartbeatInterval / 1000); - this._addConfigurationKey('HeartbeatInterval', this._heartbeatInterval / 1000, false, false); + this._addConfigurationKey('HeartBeatInterval', Utils.convertToInt(payload.interval)); + this._addConfigurationKey('HeartbeatInterval', Utils.convertToInt(payload.interval), false, false); this._basicStartMessageSequence(); } else { logger.info(this._basicFormatLog() + ' Boot Notification rejected'); @@ -656,6 +657,16 @@ class ChargingStation { } else if (keyToChange && !Utils.convertToBoolean(keyToChange.readonly)) { const keyIndex = this._configuration.configurationKey.indexOf(keyToChange); this._configuration.configurationKey[keyIndex].value = commandPayload.value; + if (keyToChange.key === 'HeartBeatInterval' || keyToChange === 'HeartbeatInterval') { + this._heartbeatInterval = Utils.convertToInt(commandPayload.value) * 1000; + // Stop heartbeat + if (this._heartbeatSetInterval) { + clearInterval(this._heartbeatSetInterval); + this._heartbeatSetInterval = null; + } + // Start heartbeat + this._startHeartbeat(this); + } if (Utils.convertToBoolean(keyToChange.reboot)) { return Constants.OCPP_RESPONSE_REBOOT_REQUIRED; } -- 2.34.1