Avoid to reopen an already open WebSocket to the OCPP server
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 29 Aug 2022 09:59:50 +0000 (11:59 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 29 Aug 2022 09:59:50 +0000 (11:59 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index d771ebe08ab969147e65dcc2d7efcaa726ed6c2e..c3aea8421acf7f86abdab84edec612fce1f391c9 100644 (file)
@@ -96,12 +96,12 @@ export default class ChargingStation {
   public performanceStatistics!: PerformanceStatistics;
   public heartbeatSetInterval!: NodeJS.Timeout;
   public ocppRequestService!: OCPPRequestService;
+  public bootNotificationRequest!: BootNotificationRequest;
   public bootNotificationResponse!: BootNotificationResponse | null;
   public powerDivider!: number;
   private readonly index: number;
   private configurationFile!: string;
   private configurationFileHash!: string;
-  private bootNotificationRequest!: BootNotificationRequest;
   private connectorsConfigurationHash!: string;
   private ocppIncomingRequestService!: OCPPIncomingRequestService;
   private readonly messageBuffer: Set<string>;
@@ -152,10 +152,6 @@ export default class ChargingStation {
     );
   }
 
-  public getBootNotificationRequest(): BootNotificationRequest {
-    return this.bootNotificationRequest;
-  }
-
   public getRandomIdTag(): string {
     const authorizationFile = ChargingStationUtils.getAuthorizationFile(this.stationInfo);
     const index = Math.floor(
@@ -707,8 +703,15 @@ export default class ChargingStation {
         break;
     }
 
+    if (this.isWebSocketConnectionOpened()) {
+      logger.warn(
+        `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} is already opened`
+      );
+      return;
+    }
+
     logger.info(
-      this.logPrefix() + ' Open OCPP connection to URL ' + this.wsConnectionUrl.toString()
+      `${this.logPrefix()} Open OCPP connection to URL ${this.wsConnectionUrl.toString()}`
     );
 
     this.wsConnection = new WebSocket(this.wsConnectionUrl, protocol, options);
index c35b3e6f61e7a4e6c6e893dd78e2c9d812cb242a..f02709a5963d8f5c21acdf7f92716f907739fdb4 100644 (file)
@@ -1169,17 +1169,17 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
                 chargingStation,
                 OCPP16RequestCommand.BOOT_NOTIFICATION,
                 {
-                  chargePointModel: chargingStation.getBootNotificationRequest().chargePointModel,
-                  chargePointVendor: chargingStation.getBootNotificationRequest().chargePointVendor,
+                  chargePointModel: chargingStation.bootNotificationRequest.chargePointModel,
+                  chargePointVendor: chargingStation.bootNotificationRequest.chargePointVendor,
                   chargeBoxSerialNumber:
-                    chargingStation.getBootNotificationRequest().chargeBoxSerialNumber,
-                  firmwareVersion: chargingStation.getBootNotificationRequest().firmwareVersion,
+                    chargingStation.bootNotificationRequest.chargeBoxSerialNumber,
+                  firmwareVersion: chargingStation.bootNotificationRequest.firmwareVersion,
                   chargePointSerialNumber:
-                    chargingStation.getBootNotificationRequest().chargePointSerialNumber,
-                  iccid: chargingStation.getBootNotificationRequest().iccid,
-                  imsi: chargingStation.getBootNotificationRequest().imsi,
-                  meterSerialNumber: chargingStation.getBootNotificationRequest().meterSerialNumber,
-                  meterType: chargingStation.getBootNotificationRequest().meterType,
+                    chargingStation.bootNotificationRequest.chargePointSerialNumber,
+                  iccid: chargingStation.bootNotificationRequest.iccid,
+                  imsi: chargingStation.bootNotificationRequest.imsi,
+                  meterSerialNumber: chargingStation.bootNotificationRequest.meterSerialNumber,
+                  meterType: chargingStation.bootNotificationRequest.meterType,
                 },
                 { skipBufferingOnError: true, triggerMessage: true }
               )