)}`,
);
while (this.connectorsStatus.get(connectorId)?.start === true) {
+ await this.waitChargingStationServiceInitialization(connectorId);
+ await this.waitChargingStationAvailable(connectorId);
+ await this.waitConnectorAvailable(connectorId);
if (!this.canStartConnector(connectorId)) {
this.stopConnector(connectorId);
break;
}
- if (!this.chargingStation?.ocppRequestService) {
- logger.info(
- `${this.logPrefix(
- connectorId,
- )} transaction loop waiting for charging station service to be initialized`,
- );
- do {
- await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
- } while (!this.chargingStation?.ocppRequestService);
- }
const wait = secondsToMilliseconds(
getRandomInteger(
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
return true;
}
+ private async waitChargingStationServiceInitialization(connectorId: number): Promise<void> {
+ if (!this.chargingStation?.ocppRequestService) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} transaction loop waiting for charging station service to be initialized`,
+ );
+ do {
+ await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
+ } while (!this.chargingStation?.ocppRequestService);
+ }
+ }
+
+ private async waitChargingStationAvailable(connectorId: number): Promise<void> {
+ if (!this.chargingStation.isChargingStationAvailable()) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} transaction loop waiting for charging station to be available`,
+ );
+ do {
+ await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
+ } while (!this.chargingStation.isChargingStationAvailable());
+ }
+ }
+
+ private async waitConnectorAvailable(connectorId: number): Promise<void> {
+ if (!this.chargingStation.isConnectorAvailable(connectorId)) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} transaction loop waiting for connector ${connectorId} to be available`,
+ );
+ do {
+ await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
+ } while (!this.chargingStation.isConnectorAvailable(connectorId));
+ }
+ }
+
private initializeConnectorsStatus(): void {
if (this.chargingStation.hasEvses) {
for (const [evseId, evseStatus] of this.chargingStation.evses) {
public setSupervisionUrl(url: string): void {
if (
- this.stationInfo?.supervisionUrlOcppConfiguration &&
+ this.stationInfo?.supervisionUrlOcppConfiguration === true &&
isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey)
) {
setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey!, url);
}
}
- private handleUnsupportedVersion(version: OCPPVersion) {
+ private handleUnsupportedVersion(version: OCPPVersion | undefined) {
const errorMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
logger.error(`${this.logPrefix()} ${errorMsg}`);
throw new BaseError(errorMsg);
this.ocppConfiguration = this.getOcppConfiguration();
this.initializeOcppConfiguration();
this.initializeOcppServices();
+ this.once(ChargingStationEvents.accepted, () => {
+ this.startMessageSequence().catch((error) => {
+ logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error);
+ });
+ });
if (this.stationInfo?.autoRegister === true) {
this.bootNotificationResponse = {
currentTime: new Date(),
this.emit(ChargingStationEvents.registered);
if (this.inAcceptedState() === true) {
this.emit(ChargingStationEvents.accepted);
- await this.startMessageSequence();
}
} else {
logger.error(
this.stopWebSocketPing();
// Stop heartbeat
this.stopHeartbeat();
- // Stop ongoing transactions
- stopTransactions && (await this.stopRunningTransactions(reason));
// Stop the ATG
if (this.automaticTransactionGenerator?.started === true) {
this.stopAutomaticTransactionGenerator();
}
+ // Stop ongoing transactions
+ stopTransactions && (await this.stopRunningTransactions(reason));
if (this.hasEvses) {
for (const [evseId, evseStatus] of this.evses) {
if (evseId > 0) {
type AuthorizeRequest,
type AuthorizeResponse,
ChargePointErrorCode,
+ ChargingStationEvents,
type ConnectorStatus,
type ConnectorStatusEnum,
ErrorType,
);
}
chargingStation.getConnectorStatus(connectorId)!.status = status;
+ chargingStation.emit(ChargingStationEvents.connectorStatusChanged, {
+ connectorId,
+ ...chargingStation.getConnectorStatus(connectorId),
+ });
}
public static async isIdTagAuthorized(
registered = 'registered',
accepted = 'accepted',
updated = 'updated',
+ connectorStatusChanged = 'connectorStatusChanged',
}
static readonly DEFAULT_METER_VALUES_INTERVAL = 60000; // Ms
static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms
+ static readonly CHARGING_STATION_ATG_AVAILABILITY_TIME = 1000; // Ms
static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms
static readonly DEFAULT_ATG_CONFIGURATION: AutomaticTransactionGeneratorConfiguration =