From 94bb24d5f341349896da43a0d9abcfff9f8abe7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 15 Apr 2022 19:41:21 +0200 Subject: [PATCH] Fix Pending registration status handling at boot notification 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 | 58 ++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index bfd3eb6f..1efcf5c4 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -541,6 +541,27 @@ export default class ChargingStation { this.performanceStatistics.start(); } this.openWSConnection(); + // Handle WebSocket message + this.wsConnection.on( + 'message', + this.onMessage.bind(this) as (this: WebSocket, data: RawData, isBinary: boolean) => void + ); + // Handle WebSocket error + this.wsConnection.on( + 'error', + this.onError.bind(this) as (this: WebSocket, error: Error) => void + ); + // Handle WebSocket close + this.wsConnection.on( + 'close', + this.onClose.bind(this) as (this: WebSocket, code: number, reason: Buffer) => void + ); + // Handle WebSocket open + this.wsConnection.on('open', this.onOpen.bind(this) as (this: WebSocket) => void); + // Handle WebSocket ping + this.wsConnection.on('ping', this.onPing.bind(this) as (this: WebSocket, data: Buffer) => void); + // Handle WebSocket pong + this.wsConnection.on('pong', this.onPong.bind(this) as (this: WebSocket, data: Buffer) => void); // Monitor authorization file FileUtils.watchJsonFile( this.logPrefix(), @@ -587,27 +608,6 @@ export default class ChargingStation { } } ); - // Handle WebSocket message - this.wsConnection.on( - 'message', - this.onMessage.bind(this) as (this: WebSocket, data: RawData, isBinary: boolean) => void - ); - // Handle WebSocket error - this.wsConnection.on( - 'error', - this.onError.bind(this) as (this: WebSocket, error: Error) => void - ); - // Handle WebSocket close - this.wsConnection.on( - 'close', - this.onClose.bind(this) as (this: WebSocket, code: number, reason: Buffer) => void - ); - // Handle WebSocket open - this.wsConnection.on('open', this.onOpen.bind(this) as (this: WebSocket) => void); - // Handle WebSocket ping - this.wsConnection.on('ping', this.onPing.bind(this) as (this: WebSocket, data: Buffer) => void); - // Handle WebSocket pong - this.wsConnection.on('pong', this.onPong.bind(this) as (this: WebSocket, data: Buffer) => void); parentPort.postMessage({ id: ChargingStationWorkerMessageEvents.STARTED, data: { id: this.stationInfo.chargingStationId }, @@ -1387,7 +1387,7 @@ export default class ChargingStation { logger.info( `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded` ); - if (!this.isInAcceptedState()) { + if (!this.isRegistered()) { // Send BootNotification let registrationRetryCount = 0; do { @@ -1409,7 +1409,7 @@ export default class ChargingStation { }, { skipBufferingOnError: true } ); - if (!this.isInAcceptedState()) { + if (!this.isRegistered()) { this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++; await Utils.sleep( this.bootNotificationResponse?.interval @@ -1418,22 +1418,22 @@ export default class ChargingStation { ); } } while ( - !this.isInAcceptedState() && + !this.isRegistered() && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1) ); } - if (this.isInAcceptedState()) { - await this.startMessageSequence(); - this.stopped && (this.stopped = false); - if (this.wsConnectionRestarted) { - this.flushMessageBuffer(); + if (this.isRegistered()) { + if (this.isInAcceptedState()) { + await this.startMessageSequence(); + this.wsConnectionRestarted && this.flushMessageBuffer(); } } else { logger.error( `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})` ); } + this.stopped && (this.stopped = false); this.autoReconnectRetryCount = 0; this.wsConnectionRestarted = false; } else { -- 2.34.1