SupervisionUrlDistribution,
SupportedFeatureProfiles,
VendorParametersKey,
+ Voltage,
type WSError,
WebSocketCloseEventStatusCode,
type WsOptions,
public get stationInfo(): ChargingStationInfo {
return {
- ...this.internalStationInfo,
...{
enableStatistics: false,
remoteAuthorization: true,
currentOutType: CurrentType.AC,
+ mainVoltageMeterValues: true,
+ phaseLineToLineVoltageMeterValues: false,
+ customValueLimitationMeterValues: true,
ocppStrictCompliance: true,
outOfOrderEndMeterValues: false,
beginEndMeterValues: false,
meteringPerTransaction: true,
transactionDataMeterValues: false,
- mainVoltageMeterValues: true,
- phaseLineToLineVoltageMeterValues: false,
- customValueLimitationMeterValues: true,
supervisionUrlOcppConfiguration: false,
supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl,
ocppVersion: OCPPVersion.VERSION_16,
reconnectExponentialDelay: false,
stopTransactionsOnStopped: true,
},
+ ...this.internalStationInfo,
};
}
private get wsConnectionUrl(): URL {
return new URL(
`${
- this.stationInfo?.supervisionUrlOcppConfiguration &&
+ this.stationInfo?.supervisionUrlOcppConfiguration === true &&
isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
isNotEmptyString(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)?.value)
? getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)!.value
const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo;
switch (this.getCurrentOutType(stationInfo)) {
case CurrentType.AC:
- return !isUndefined(localStationInfo.numberOfPhases) ? localStationInfo.numberOfPhases! : 3;
+ return localStationInfo.numberOfPhases ?? 3;
case CurrentType.DC:
return 0;
}
this,
StandardParametersKey.AuthorizeRemoteTxRequests,
);
- return authorizeRemoteTxRequests ? convertToBoolean(authorizeRemoteTxRequests.value) : false;
+ return authorizeRemoteTxRequests !== undefined
+ ? convertToBoolean(authorizeRemoteTxRequests.value)
+ : false;
}
public getLocalAuthListEnabled(): boolean {
this,
StandardParametersKey.LocalAuthListEnabled,
);
- return localAuthListEnabled ? convertToBoolean(localAuthListEnabled.value) : false;
+ return localAuthListEnabled !== undefined
+ ? convertToBoolean(localAuthListEnabled.value)
+ : false;
}
public getHeartbeatInterval(): number {
const HeartbeatInterval = getConfigurationKey(this, StandardParametersKey.HeartbeatInterval);
- if (HeartbeatInterval) {
+ if (HeartbeatInterval !== undefined) {
return secondsToMilliseconds(convertToInt(HeartbeatInterval.value));
}
const HeartBeatInterval = getConfigurationKey(this, StandardParametersKey.HeartBeatInterval);
- if (HeartBeatInterval) {
+ if (HeartBeatInterval !== undefined) {
return secondsToMilliseconds(convertToInt(HeartBeatInterval.value));
}
this.stationInfo?.autoRegister === false &&
public setSupervisionUrl(url: string): void {
if (
- this.stationInfo?.supervisionUrlOcppConfiguration &&
+ this.stationInfo?.supervisionUrlOcppConfiguration === true &&
isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey)
) {
setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey!, url);
public async addReservation(reservation: Reservation): Promise<void> {
const reservationFound = this.getReservationBy('reservationId', reservation.reservationId);
- if (!isUndefined(reservationFound)) {
- await this.removeReservation(
- reservationFound!,
- ReservationTerminationReason.REPLACE_EXISTING,
- );
+ if (reservationFound !== undefined) {
+ await this.removeReservation(reservationFound, ReservationTerminationReason.REPLACE_EXISTING);
}
this.getConnectorStatus(reservation.connectorId)!.reservation = reservation;
await OCPPServiceUtils.sendAndSetConnectorStatus(
[, , commandName] = JSON.parse(message) as OutgoingRequest;
beginId = PerformanceStatistics.beginMeasure(commandName);
}
- this.wsConnection?.send(message);
- isRequest && PerformanceStatistics.endMeasure(commandName!, beginId!);
- logger.debug(
- `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString(
- messageType,
- )} payload sent: ${message}`,
- );
- this.messageBuffer.delete(message);
+ this.wsConnection?.send(message, (error?: Error) => {
+ isRequest && PerformanceStatistics.endMeasure(commandName!, beginId!);
+ if (isNullOrUndefined(error)) {
+ logger.debug(
+ `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString(
+ messageType,
+ )} payload sent: ${message}`,
+ );
+ this.messageBuffer.delete(message);
+ }
+ });
}
}
}
stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate);
stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
createSerialNumber(stationTemplate, stationInfo);
+ stationInfo.voltageOut = this.getVoltageOut(stationInfo);
if (isNotEmptyArray(stationTemplate?.power)) {
stationTemplate.power = stationTemplate.power as number[];
const powerArrayRandomIndex = Math.floor(secureRandom() * stationTemplate.power.length);
? stationTemplate.power * 1000
: stationTemplate.power;
}
+ stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo);
stationInfo.firmwareVersionPattern =
stationTemplate?.firmwareVersionPattern ?? Constants.SEMVER_PATTERN;
if (
stationInfo.resetTime = !isNullOrUndefined(stationTemplate?.resetTime)
? secondsToMilliseconds(stationTemplate.resetTime!)
: Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
- stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo);
return stationInfo;
}
}
}
- 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(),
}
private initializeOcppConfiguration(): void {
- if (!getConfigurationKey(this, StandardParametersKey.HeartbeatInterval)) {
+ if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.HeartbeatInterval))) {
addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0');
}
- if (!getConfigurationKey(this, StandardParametersKey.HeartBeatInterval)) {
+ if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.HeartBeatInterval))) {
addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false });
}
if (
- this.stationInfo?.supervisionUrlOcppConfiguration &&
+ this.stationInfo?.supervisionUrlOcppConfiguration === true &&
isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
- !getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)
+ isNullOrUndefined(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!))
) {
addConfigurationKey(
this,
{ reboot: true },
);
} else if (
- !this.stationInfo?.supervisionUrlOcppConfiguration &&
+ this.stationInfo?.supervisionUrlOcppConfiguration === false &&
isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)
) {
}
if (
isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
- !getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)
+ isNullOrUndefined(getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!))
) {
addConfigurationKey(
this,
).toString(),
);
}
- if (!getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)) {
+ if (
+ isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles))
+ ) {
addConfigurationKey(
this,
StandardParametersKey.SupportedFeatureProfiles,
{ readonly: true },
{ overwrite: true },
);
- if (!getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData)) {
+ if (
+ isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData))
+ ) {
addConfigurationKey(
this,
StandardParametersKey.MeterValuesSampledData,
MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
);
}
- if (!getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation)) {
+ if (
+ isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation))
+ ) {
const connectorsPhaseRotation: string[] = [];
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
connectorsPhaseRotation.toString(),
);
}
- if (!getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests)) {
+ if (
+ isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests))
+ ) {
addConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests, 'true');
}
if (
- !getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled) &&
+ isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled)) &&
getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)?.value?.includes(
SupportedFeatureProfiles.LocalAuthListManagement,
)
) {
addConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled, 'false');
}
- if (!getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) {
+ if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut))) {
addConfigurationKey(
this,
StandardParametersKey.ConnectionTimeOut,
logger.info(
`${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`,
);
+ let registrationRetryCount = 0;
if (this.isRegistered() === false) {
// Send BootNotification
- let registrationRetryCount = 0;
do {
this.bootNotificationResponse = await this.ocppRequestService.requestHandler<
BootNotificationRequest,
this.emit(ChargingStationEvents.registered);
if (this.inAcceptedState() === true) {
this.emit(ChargingStationEvents.accepted);
- await this.startMessageSequence();
}
} else {
logger.error(
- `${this.logPrefix()} Registration failure: max retries reached or retry disabled (${this
+ `${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${this
.stationInfo?.registrationMaxRetries})`,
);
}
}
}
- private async onClose(code: number, reason: Buffer): Promise<void> {
+ private async onClose(code: WebSocketCloseEventStatusCode, reason: Buffer): Promise<void> {
switch (code) {
// Normal close
case WebSocketCloseEventStatusCode.CLOSE_NORMAL:
private async onMessage(data: RawData): Promise<void> {
let request: IncomingRequest | Response | ErrorResponse | undefined;
- let messageType: number | undefined;
+ let messageType: MessageType | undefined;
let errorMsg: string;
try {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
// 0 for disabling
private getConnectionTimeout(): number {
- if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) {
- return (
- parseInt(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value!) ??
- Constants.DEFAULT_CONNECTION_TIMEOUT
+ if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut) !== undefined) {
+ return convertToInt(
+ getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value! ??
+ Constants.DEFAULT_CONNECTION_TIMEOUT,
);
}
return Constants.DEFAULT_CONNECTION_TIMEOUT;
private getPowerDivider(): number {
let powerDivider = this.hasEvses ? this.getNumberOfEvses() : this.getNumberOfConnectors();
- if (this.stationInfo?.powerSharedByConnectors) {
+ if (this.stationInfo?.powerSharedByConnectors === true) {
powerDivider = this.getNumberOfRunningTransactions();
}
return powerDivider;
}
private getCurrentOutType(stationInfo?: ChargingStationInfo): CurrentType {
- return (stationInfo ?? this.stationInfo).currentOutType!;
+ return (stationInfo ?? this.stationInfo).currentOutType ?? CurrentType.AC;
}
- private getVoltageOut(stationInfo?: ChargingStationInfo): number {
- const defaultVoltageOut = getDefaultVoltageOut(
- this.getCurrentOutType(stationInfo),
- this.logPrefix(),
- this.templateFile,
+ private getVoltageOut(stationInfo?: ChargingStationInfo): Voltage {
+ return (
+ (stationInfo ?? this.stationInfo).voltageOut ??
+ getDefaultVoltageOut(this.getCurrentOutType(stationInfo), this.logPrefix(), this.templateFile)
);
- return (stationInfo ?? this.stationInfo).voltageOut ?? defaultVoltageOut;
}
private getAmperageLimitation(): number | undefined {
if (
isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
- getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)
+ getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) !== undefined
) {
return (
convertToInt(
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) {
}
private startWebSocketPing(): void {
- const webSocketPingInterval: number = getConfigurationKey(
- this,
- StandardParametersKey.WebSocketPingInterval,
- )
- ? convertToInt(getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value)
- : 0;
+ const webSocketPingInterval: number =
+ getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) !== undefined
+ ? convertToInt(
+ getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value,
+ )
+ : 0;
if (webSocketPingInterval > 0 && !this.webSocketPingSetInterval) {
this.webSocketPingSetInterval = setInterval(() => {
if (this.isWebSocketConnectionOpened() === true) {