From: Jérôme Benoit Date: Sun, 18 Oct 2020 14:20:24 +0000 (+0200) Subject: Handle OCPP parameter change to the heartbeat. X-Git-Tag: v1.0.1-0~283 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5c68da4d6ae3d794ba23217b895772ab670d48a6;p=e-mobility-charging-stations-simulator.git Handle OCPP parameter change to the heartbeat. Signed-off-by: Jérôme Benoit --- 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; }