Fixed wss via REST should have protocol 'rest'
Remove check on 'upgrade' HTTP header not sent by Cahors CS!
MODIFY
src/client/ocpp/json/JsonRestChargingStationClient.ts
src/client/ocpp/json/JsonRestChargingStationClient.ts
@@ -127,9 +127,9 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
// Create WS
const wsClientOptions: WSClientOptions = {
wsOptions: {
- protocol: WSServerProtocol.REST,
handshakeTimeout: 5000,
},
+ protocols: WSServerProtocol.REST,
logTenantID: this.tenantID
};
// Create and Open the WS
@@ -173,7 +173,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
chargingStationID: this.chargingStation.id,
action: ServerAction.WS_REST_CLIENT_CONNECTION_ERROR,
module: MODULE_NAME, method: 'onError',
- message: `Connection error to '${this.serverURL}: ${error.toString()}`,
+ message: `Connection error to '${this.serverURL}: ${error?.message}`,
detailedMessages: { error: error.stack }
});
// Terminate WS in error

MODIFY
src/client/websocket/WSClient.ts
src/client/websocket/WSClient.ts
@@ -157,7 +157,7 @@ export default class WSClient {
module: MODULE_NAME, method: 'onError',
action: ServerAction.WS_CLIENT_ERROR,
message: `Connection error to '${this.url}': ${error?.message as string}`,
- detailedMessages: { error }
+ detailedMessages: { error: error.stack }
});
} else {
!Utils.isProductionEnv() && Logging.logConsoleError(`WSClient connection error to '${this.url}': ${error?.message as string}`);

MODIFY
src/server/ocpp/json/JsonCentralSystemServer.ts
src/server/ocpp/json/JsonCentralSystemServer.ts
@@ -123,37 +123,37 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
res.onAborted(() => {
// If no handler here, it crashes!!!
});
- const upgrade = req.getHeader('upgrade');
- if (upgrade !== 'websocket') {
+ // Check URI (/OCPP16/<TENANT_ID>/<TOKEN_ID>/<CHARGING_STATION_ID> or /REST/<TENANT_ID>/<TOKEN_ID>/<CHARGING_STATION_ID>)
+ const url = req.getUrl();
+ if (!url.startsWith('/OCPP16') && !url.startsWith('/REST')) {
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'onUpgrade',
action: ServerAction.WS_CONNECTION,
- message: `WS Connection - Invalid: No WS 'upgrade' HTTP Header for '${req.getUrl()}'`
+ message: `WS Connection - Invalid: No 'OCPP16' or 'REST' path in '${req.getUrl()}'`
});
res.close();
return;
}
- // Check URI (/OCPP16/<TENANT_ID>/<TOKEN_ID>/<CHARGING_STATION_ID>)
- const url = req.getUrl();
- if (!url.startsWith('/OCPP16') && !url.startsWith('/REST')) {
+ // Check Protocol (ocpp1.6 / rest)
+ const protocol = req.getHeader('sec-websocket-protocol');
+ if (url.startsWith('/OCPP16') && (protocol !== WSServerProtocol.OCPP16)) {
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'onUpgrade',
action: ServerAction.WS_CONNECTION,
- message: `WS Connection - Invalid: No 'OCPP16' or 'REST' path in '${req.getUrl()}'`
+ message: `WS Connection - Invalid: No valid protocol (expected: 'ocpp1.6') for '${req.getUrl()}'`,
+ detailedMessages: { protocol }
});
res.close();
return;
}
- // Check Protocol (ocpp1.6)
- const protocol = req.getHeader('sec-websocket-protocol');
- if (protocol !== WSServerProtocol.OCPP16) {
+ if (url.startsWith('/REST') && (protocol !== WSServerProtocol.REST)) {
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'onUpgrade',
action: ServerAction.WS_CONNECTION,
- message: `WS Connection - Invalid: No valid protocol (expected: 'ocpp1.6') for '${req.getUrl()}'`,
+ message: `WS Connection - Invalid: No valid protocol (expected: 'rest') for '${req.getUrl()}'`,
detailedMessages: { protocol }
});
res.close();

Fixed wss via REST should have protocol 'rest'
Remove check on 'upgrade' HTTP header not sent by Cahors CS!