From: Jérôme Benoit Date: Mon, 29 Aug 2022 09:59:50 +0000 (+0200) Subject: Avoid to reopen an already open WebSocket to the OCPP server X-Git-Tag: v1.1.68~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0a03f36ceab67bba06bef67d4df771b9bf4e6a29;p=e-mobility-charging-stations-simulator.git Avoid to reopen an already open WebSocket to the OCPP server Signed-off-by: Jérôme Benoit --- 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 } )