From 0a03f36ceab67bba06bef67d4df771b9bf4e6a29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 29 Aug 2022 11:59:50 +0200 Subject: [PATCH] Avoid to reopen an already open WebSocket to the OCPP server 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 | 15 +++++++++------ .../ocpp/1.6/OCPP16IncomingRequestService.ts | 18 +++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d771ebe0..c3aea842 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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; @@ -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); diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index c35b3e6f..f02709a5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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 } ) -- 2.34.1