fix: start heartbeat once
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 29 May 2024 20:07:53 +0000 (22:07 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 29 May 2024 20:07:53 +0000 (22:07 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index 7cfb70f265bc3a9e0bad2f0c9accb8dba76ba038..2d934e066ff07a58470dc6162c342491df1adb93 100644 (file)
@@ -2224,7 +2224,11 @@ export class ChargingStation extends EventEmitter {
     // Start WebSocket ping
     this.startWebSocketPing()
     // Start heartbeat
-    this.startHeartbeat()
+    if (this.heartbeatSetInterval == null) {
+      this.startHeartbeat()
+    } else if (this.getHeartbeatInterval() !== this.bootNotificationResponse?.interval) {
+      this.restartHeartbeat()
+    }
     // Initialize connectors status
     if (this.hasEvses) {
       for (const [evseId, evseStatus] of this.evses) {
index 46c6d40182aad69b84b7e65bf442cd252ccd0af0..409f382ea9e8cfd0351b142eb4100d659e58f620 100644 (file)
@@ -510,29 +510,26 @@ export class OCPP16ResponseService extends OCPPResponseService {
     chargingStation: ChargingStation,
     payload: OCPP16BootNotificationResponse
   ): void {
-    if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
-      addConfigurationKey(
-        chargingStation,
-        OCPP16StandardParametersKey.HeartbeatInterval,
-        payload.interval.toString(),
-        {},
-        { overwrite: true, save: true }
-      )
-      addConfigurationKey(
-        chargingStation,
-        OCPP16StandardParametersKey.HeartBeatInterval,
-        payload.interval.toString(),
-        { visible: false },
-        { overwrite: true, save: true }
-      )
-      OCPP16ServiceUtils.startHeartbeatInterval(chargingStation, payload.interval)
-    }
     if (Object.values(RegistrationStatusEnumType).includes(payload.status)) {
       chargingStation.bootNotificationResponse = payload
       if (chargingStation.isRegistered()) {
         chargingStation.emit(ChargingStationEvents.registered)
         if (chargingStation.inAcceptedState()) {
           chargingStation.emit(ChargingStationEvents.accepted)
+          addConfigurationKey(
+            chargingStation,
+            OCPP16StandardParametersKey.HeartbeatInterval,
+            payload.interval.toString(),
+            {},
+            { overwrite: true, save: true }
+          )
+          addConfigurationKey(
+            chargingStation,
+            OCPP16StandardParametersKey.HeartBeatInterval,
+            payload.interval.toString(),
+            { visible: false },
+            { overwrite: true, save: true }
+          )
         }
       } else if (chargingStation.inRejectedState()) {
         chargingStation.emit(ChargingStationEvents.rejected)
index 1eac7a88df7af3cf2c2807085740d4a42cc10071..77546cfa58fac5dd58b374454f85b8bb95653d3d 100644 (file)
@@ -183,22 +183,19 @@ export class OCPP20ResponseService extends OCPPResponseService {
     chargingStation: ChargingStation,
     payload: OCPP20BootNotificationResponse
   ): void {
-    if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
-      addConfigurationKey(
-        chargingStation,
-        OCPP20OptionalVariableName.HeartbeatInterval,
-        payload.interval.toString(),
-        {},
-        { overwrite: true, save: true }
-      )
-      OCPP20ServiceUtils.startHeartbeatInterval(chargingStation, payload.interval)
-    }
     if (Object.values(RegistrationStatusEnumType).includes(payload.status)) {
       chargingStation.bootNotificationResponse = payload
       if (chargingStation.isRegistered()) {
         chargingStation.emit(ChargingStationEvents.registered)
         if (chargingStation.inAcceptedState()) {
           chargingStation.emit(ChargingStationEvents.accepted)
+          addConfigurationKey(
+            chargingStation,
+            OCPP20OptionalVariableName.HeartbeatInterval,
+            payload.interval.toString(),
+            {},
+            { overwrite: true, save: true }
+          )
         }
       } else if (chargingStation.inRejectedState()) {
         chargingStation.emit(ChargingStationEvents.rejected)
index 9b2fee9cf7bd0d3a5f963bd82e8ecf3f4e1b2f43..69de60cf19eec8617468fbdf47a5807294ad6e67 100644 (file)
@@ -1379,14 +1379,6 @@ export class OCPPServiceUtils {
     }
   }
 
-  public static startHeartbeatInterval (chargingStation: ChargingStation, interval: number): void {
-    if (chargingStation.heartbeatSetInterval == null) {
-      chargingStation.startHeartbeat()
-    } else if (chargingStation.getHeartbeatInterval() !== interval) {
-      chargingStation.restartHeartbeat()
-    }
-  }
-
   protected static parseJsonSchemaFile<T extends JsonType>(
     relativePath: string,
     ocppVersion: OCPPVersion,