From 16cd35ad01b48377d39077d8b30e6c2055a5f8ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 4 Feb 2022 18:45:01 +0100 Subject: [PATCH] Fix PENDING state boot notification handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 4 +-- src/charging-station/ChargingStation.ts | 26 +++++++++++++++++-- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 6 +++-- src/utils/Constants.ts | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index ccc30d0c..3f5b03c1 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -66,8 +66,8 @@ export default class AutomaticTransactionGenerator { this.stopConnector(connectorId); break; } - if (!this.chargingStation.isRegistered()) { - logger.error(this.logPrefix(connectorId) + ' entered in transaction loop while the charging station is not registered'); + if (!this.chargingStation.isInAcceptedState()) { + logger.error(this.logPrefix(connectorId) + ' entered in transaction loop while the charging station is in accepted state'); this.stopConnector(connectorId); break; } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 565bdb89..018a6fbe 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -122,10 +122,22 @@ export default class ChargingStation { return this?.wsConnection?.readyState === OPEN; } - public isRegistered(): boolean { + public isInPendingState(): boolean { + return this?.bootNotificationResponse?.status === RegistrationStatus.PENDING; + } + + public isInAcceptedState(): boolean { return this?.bootNotificationResponse?.status === RegistrationStatus.ACCEPTED; } + public isInRejectedState(): boolean { + return this?.bootNotificationResponse?.status === RegistrationStatus.REJECTED; + } + + public isRegistered(): boolean { + return this.isInAcceptedState() || this.isInPendingState(); + } + public isChargingStationAvailable(): boolean { return this.getConnectorStatus(0).availability === AvailabilityType.OPERATIVE; } @@ -644,12 +656,22 @@ export default class ChargingStation { await this.ocppRequestService.sendBootNotification(this.bootNotificationRequest.chargePointModel, this.bootNotificationRequest.chargePointVendor, this.bootNotificationRequest.chargeBoxSerialNumber, this.bootNotificationRequest.firmwareVersion); } - if (this.isRegistered()) { + if (this.isInAcceptedState()) { await this.startMessageSequence(); this.stopped && (this.stopped = false); if (this.wsConnectionRestarted && this.isWebSocketConnectionOpened()) { this.flushMessageBuffer(); } + } else if (this.isInPendingState()) { + // The central server shall issue a triggerMessage to the charging station for the boot notification at the end of its configuration process + while (!this.isInAcceptedState()) { + await this.startMessageSequence(); + this.stopped && (this.stopped = false); + if (this.wsConnectionRestarted && this.isWebSocketConnectionOpened()) { + this.flushMessageBuffer(); + } + await Utils.sleep(Constants.CHARGING_STATION_DEFAULT_START_SEQUENCE_DELAY); + } } else { logger.error(`${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`); } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index fa03c535..81ff70b7 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -47,7 +47,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer public async handleRequest(messageId: string, commandName: OCPP16IncomingRequestCommand, commandPayload: Record): Promise { let result: Record; - if (this.chargingStation.isRegistered()) { + if (this.chargingStation.isRegistered() && + !(this.chargingStation.isInPendingState + && (commandName === OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION || commandName === OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION))) { if (this.incomingRequestHandlers.has(commandName)) { try { // Call the method to build the result @@ -295,7 +297,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer if (this.chargingStation.getAuthorizeRemoteTxRequests()) { let authorized = false; if (this.chargingStation.getLocalAuthListEnabled() && this.chargingStation.hasAuthorizedTags() - && this.chargingStation.authorizedTags.find((value) => value === commandPayload.idTag)) { + && this.chargingStation.authorizedTags.find((value) => value === commandPayload.idTag)) { this.chargingStation.getConnectorStatus(transactionConnectorId).localAuthorizeIdTag = commandPayload.idTag; this.chargingStation.getConnectorStatus(transactionConnectorId).idTagLocalAuthorized = true; authorized = true; diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 2e43d376..e6503d78 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -29,6 +29,7 @@ export default class Constants { static readonly OCPP_WEBSOCKET_TIMEOUT = 60000; // Ms static readonly OCPP_TRIGGER_MESSAGE_DELAY = 2000; // Ms + static readonly CHARGING_STATION_DEFAULT_START_SEQUENCE_DELAY = 60000; // Ms static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms static readonly CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS = 0.25; // Hours -- 2.34.1