From b8e3363a179fcf79d8bb66f47724b377d4d38a75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 8 Jun 2024 18:26:51 +0200 Subject: [PATCH] fix: restart metervalues interval if MeterValueSampleInterval is changed 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.ts | 5 +++++ .../ocpp/1.6/OCPP16IncomingRequestService.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 5fad6d15..47e911a4 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -671,6 +671,11 @@ export class ChargingStation extends EventEmitter { } } + public restartMeterValues (connectorId: number, interval: number): void { + this.stopMeterValues(connectorId) + this.startMeterValues(connectorId, interval) + } + private add (): void { this.emit(ChargingStationEvents.added) } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 64cefe58..4ab585ff 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -840,6 +840,25 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ) { chargingStation.restartWebSocketPing() } + if ( + (keyToChange.key as OCPP16StandardParametersKey) === + OCPP16StandardParametersKey.MeterValueSampleInterval && + chargingStation.getNumberOfRunningTransactions() > 0 && + valueChanged + ) { + for ( + let connectorId = 1; + connectorId <= chargingStation.getNumberOfConnectors(); + connectorId++ + ) { + if (chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) { + chargingStation.restartMeterValues( + connectorId, + secondsToMilliseconds(convertToInt(value)) + ) + } + } + } if (keyToChange.reboot === true) { return OCPP16Constants.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED } -- 2.34.1