}
public start(): void {
+ if (this.checkChargingStation() === false) {
+ return;
+ }
if (this.started === true) {
logger.warn(`${this.logPrefix()} is already started`);
return;
}
public startConnector(connectorId: number): void {
+ if (this.checkChargingStation(connectorId) === false) {
+ return;
+ }
if (this.connectorsStatus.has(connectorId) === false) {
logger.error(`${this.logPrefix(connectorId)} starting on non existing connector`);
throw new BaseError(`Connector ${connectorId} does not exist`);
this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++;
}
}
+
+ private checkChargingStation(connectorId?: number): boolean {
+ if (this.chargingStation.started === false) {
+ logger.warn(`${this.logPrefix(connectorId)} charging station is stopped, cannot proceed`);
+ }
+ return this.chargingStation.started;
+ }
}
options.handshakeTimeout = options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000;
params.closeOpened = params?.closeOpened ?? false;
params.terminateOpened = params?.terminateOpened ?? false;
+ if (this.started === false) {
+ logger.warn(
+ `${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} on stopped charging station`
+ );
+ return;
+ }
if (
!Utils.isNullOrUndefined(this.stationInfo.supervisionUser) &&
!Utils.isNullOrUndefined(this.stationInfo.supervisionPassword)
'upgrade',
(req: IncomingMessage, socket: internal.Duplex, head: Buffer): void => {
this.authenticate(req, (err) => {
- if (err) {
- socket.write(`HTTP/1.1 ${StatusCodes.UNAUTHORIZED} Unauthorized\r\n\r\n`);
+ 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`);
socket.destroy();
- return;
}
- this.webSocketServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
- this.webSocketServer.emit('connection', ws, req);
- });
});
}
);