Add extra log when socket is not found
MODIFY
src/server/ocpp/json/JsonCentralSystemServer.ts
src/server/ocpp/json/JsonCentralSystemServer.ts
@@ -13,9 +13,10 @@ import WSServer from './WSServer';
import global from '../../../types/GlobalType';
import http from 'http';
+const MODULE_NAME = 'JsonCentralSystemServer';
+
export default class JsonCentralSystemServer extends CentralSystemServer {
private serverName: string;
- private MODULE_NAME: string;
private serverConfig: CentralSystemConfiguration;
private wsServer: WSServer;
private jsonChargingStationClients: Map<string, JsonWSConnection>;
@@ -28,7 +29,6 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
super(centralSystemConfig, chargingStationConfig);
// Keep local
this.serverName = 'OCPP';
- this.MODULE_NAME = 'JsonCentralSystemServer';
this.serverConfig = centralSystemConfig;
this.jsonChargingStationClients = new Map<string, JsonWSConnection>();
this.jsonRestClients = new Map<string, JsonRestWSConnection>();
@@ -45,8 +45,21 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
public getChargingStationClient(tenantID: string, chargingStationID: string): ChargingStationClient {
// Build ID
const id = `${tenantID}~${chargingStationID}}`;
- // Return from the cache
- return this.jsonChargingStationClients.get(id)?.getChargingStationClient();
+ // Get the Json Web Socket
+ const jsonWebSocket = this.jsonChargingStationClients.get(id);
+ if (!jsonWebSocket) {
+ Logging.logError({
+ tenantID: tenantID,
+ source: chargingStationID,
+ module: MODULE_NAME, method: 'getChargingStationClient',
+ action: ServerAction.WS_CONNECTION,
+ message: 'No Web Socket Connection found',
+ detailedMessages: { chargingStations: Array.from(this.jsonChargingStationClients.keys()) }
+ });
+ return null;
+ }
+ // Return the client
+ return jsonWebSocket.getChargingStationClient();
}
public get port(): number {
@@ -91,7 +104,7 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
}
Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
- module: this.MODULE_NAME, method: 'verifyClient',
+ module: MODULE_NAME, method: 'verifyClient',
action: ServerAction.EXPRESS_SERVER,
message: `Invalid connection URL ${info.req.url}`
});
@@ -115,7 +128,7 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
}
Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
- module: this.MODULE_NAME, method: 'handleProtocols',
+ module: MODULE_NAME, method: 'handleProtocols',
action: ServerAction.EXPRESS_SERVER,
message: `Invalid protocol ${protocols.toString()}`
});
@@ -149,7 +162,7 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
} catch (error) {
// Log
Logging.logException(
- error, ServerAction.WS_CONNECTION, '', this.MODULE_NAME, 'connection', Constants.DEFAULT_TENANT);
+ error, ServerAction.WS_CONNECTION, '', MODULE_NAME, 'connection', Constants.DEFAULT_TENANT);
// Respond
ws.close(Constants.WS_UNSUPPORTED_DATA, error.message);
}
@@ -164,8 +177,7 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
tenantID: jsonWSConnection.getTenantID(),
source: jsonWSConnection.getChargingStationID(),
action: ServerAction.WS_JSON_CONNECTION_CLOSED,
- module: this.MODULE_NAME,
- method: 'createWSServer',
+ module: MODULE_NAME, method: 'createWSServer',
message: `WebSocket does not respond to ping (IP: ${jsonWSConnection.getClientIP().toString()}), terminating`
});
jsonWSConnection.getWSConnection().terminate();

MODIFY
src/server/ocpp/json/JsonWSConnection.ts
src/server/ocpp/json/JsonWSConnection.ts
@@ -152,7 +152,7 @@ export default class JsonWSConnection extends WSConnection {
}
Logging.logError({
tenantID: this.getTenantID(),
- source: this.getChargingStationID() ? this.getChargingStationID() : '',
+ source: this.getChargingStationID(),
module: MODULE_NAME, method: 'getChargingStationClient',
action: ServerAction.WS_CONNECTION,
message: `Cannot retrieve JSon Client from WS Connection with status '${this.getConnectionStatusString()}'`,

Add extra log when socket is not found