Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Fix Pending registration status handling at boot notification
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
  • Loading branch information
Jérôme Benoit committed Apr 15, 2022
1 parent 1c959f1 commit 94bb24d
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(
this.logPrefix(),
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 94bb24d

Please sign in to comment.