}
private checkChargingStation(connectorId?: number): boolean {
- if (this.chargingStation.started === false) {
+ if (this.chargingStation.started === false && this.chargingStation.starting === false) {
logger.warn(`${this.logPrefix(connectorId)} charging station is stopped, cannot proceed`);
+ return false;
}
- return this.chargingStation.started;
+ return true;
}
}
public readonly templateFile: string;
public stationInfo!: ChargingStationInfo;
public started: boolean;
+ public starting: boolean;
public authorizedTagsCache: AuthorizedTagsCache;
public automaticTransactionGenerator!: AutomaticTransactionGenerator;
public ocppConfiguration!: ChargingStationOcppConfiguration;
public bootNotificationRequest!: BootNotificationRequest;
public bootNotificationResponse!: BootNotificationResponse | null;
public powerDivider!: number;
- private starting: boolean;
private stopping: boolean;
private configurationFile!: string;
private configurationFileHash!: string;
options.handshakeTimeout = options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000;
params.closeOpened = params?.closeOpened ?? false;
params.terminateOpened = params?.terminateOpened ?? false;
- if (this.started === false) {
+ if (this.started === false && this.starting === false) {
logger.warn(
`${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} on stopped charging station`
);
);
});
});
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ this.httpServer.on('connect', (req: IncomingMessage, socket: internal.Duplex, head: Buffer) => {
+ if (req.headers?.connection !== 'Upgrade' || req.headers?.upgrade !== 'websocket') {
+ socket.write(`HTTP/1.1 ${StatusCodes.BAD_REQUEST} Bad Request\r\n\r\n`);
+ socket.destroy();
+ }
+ });
this.httpServer.on(
'upgrade',
(req: IncomingMessage, socket: internal.Duplex, head: Buffer): void => {
this.authenticate(req, (err) => {
- if (req.headers?.connection === 'Upgrade' && req.headers?.upgrade === 'websocket') {
- if (err) {
- socket.write(`HTTP/1.1 ${StatusCodes.UNAUTHORIZED} Unauthorized\r\n\r\n`);
- socket.destroy();
- return;
- }
- try {
- this.webSocketServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
- this.webSocketServer.emit('connection', ws, req);
- });
- } catch (error) {
- logger.error(
- `${this.logPrefix(
- moduleName,
- 'start.httpServer.on.upgrade'
- )} Error at handling connection upgrade:`,
- error
- );
- }
- } else {
- socket.write(`HTTP/1.1 ${StatusCodes.BAD_REQUEST} Bad Request\r\n\r\n`);
+ if (err) {
+ socket.write(`HTTP/1.1 ${StatusCodes.UNAUTHORIZED} Unauthorized\r\n\r\n`);
socket.destroy();
+ return;
+ }
+ try {
+ this.webSocketServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
+ this.webSocketServer.emit('connection', ws, req);
+ });
+ } catch (error) {
+ logger.error(
+ `${this.logPrefix(
+ moduleName,
+ 'start.httpServer.on.upgrade'
+ )} Error at handling connection upgrade:`,
+ error
+ );
}
});
}