fix: restart metervalues interval if MeterValueSampleInterval is changed
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 8 Jun 2024 16:26:51 +0000 (18:26 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 8 Jun 2024 16:26:51 +0000 (18:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index 5fad6d150a648ea9ba9a548955e56b5176b54162..47e911a4befd5a6a8b99a07bdd84a0566c2d86a9 100644 (file)
@@ -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)
   }
index 64cefe58653da3c955c6ec1d0537d1597f5a710e..4ab585ff247372cef68074da3b888f1523ea038f 100644 (file)
@@ -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
       }