ocppj - prevent last seen update on REST WS calls
MODIFY
src/client/ocpp/json/JsonRestChargingStationClient.ts
src/client/ocpp/json/JsonRestChargingStationClient.ts
@@ -264,6 +264,10 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
private async sendMessage(request: OCPPOutgoingRequest): Promise<any> {
// Return a promise
+ if (Date.now() - this.chargingStation.lastSeen.getTime() > Configuration.getChargingStationConfig().pingIntervalOCPPJSecs * 1000) {
+ // Charging station is not connected to the server - let's abort the current operation
+ throw new Error(`Charging station is not connected to the server - request '${request[2]}' has been aborted`);
+ }
// eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor
return new Promise(async (resolve, reject) => {
try {

MODIFY
src/server/ocpp/json/web-socket/WSConnection.ts
src/server/ocpp/json/web-socket/WSConnection.ts
import ChargingStation, { Command } from '../../../../types/ChargingStation';
import { FctOCPPReject, FctOCPPResponse, OCPPErrorType, OCPPIncomingRequest, OCPPIncomingResponse, OCPPMessageType, OCPPRequest } from '../../../../types/ocpp/OCPPCommon';
+import { ServerAction, WSServerProtocol } from '../../../../types/Server';
import BackendError from '../../../../exception/BackendError';
import Constants from '../../../../utils/Constants';
import Logging from '../../../../utils/Logging';
import OCPPError from '../../../../exception/OcppError';
import OCPPUtils from '../../utils/OCPPUtils';
-import { ServerAction } from '../../../../types/Server';
import Tenant from '../../../../types/Tenant';
import Utils from '../../../../utils/Utils';
import WSWrapper from './WSWrapper';
@@ -37,9 +37,14 @@ export default abstract class WSConnection {
}
public async initialize(): Promise<void> {
+ // Do not update the lastSeen when the caller is the REST server!
+ const updateChargingStationData = (this.ws.protocol !== WSServerProtocol.REST);
// Check and Get Charging Station data
const { tenant, chargingStation } = await OCPPUtils.checkAndGetChargingStationConnectionData(
- ServerAction.WS_SERVER_CONNECTION, this.getTenantID(), this.getChargingStationID(), this.getTokenID());
+ ServerAction.WS_SERVER_CONNECTION,
+ this.getTenantID(),
+ this.getChargingStationID(), this.getTokenID(),
+ updateChargingStationData);
// Set
this.setTenant(tenant);
this.setChargingStation(chargingStation);

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -1231,7 +1231,7 @@ export default class OCPPUtils {
}
public static async checkAndGetChargingStationConnectionData(action: ServerAction, tenantID: string, chargingStationID: string,
- tokenID: string): Promise<{ tenant: Tenant; chargingStation?: ChargingStation; token?: RegistrationToken }> {
+ tokenID: string, updateChargingStationData = true): Promise<{ tenant: Tenant; chargingStation?: ChargingStation; token?: RegistrationToken }> {
// Check parameters
OCPPUtils.checkChargingStationConnectionData(
ServerAction.WS_SERVER_CONNECTION, tenantID, tokenID, chargingStationID);
@@ -1294,6 +1294,7 @@ export default class OCPPUtils {
message: 'Charging Station has been forced as inactive!'
});
}
+ if (updateChargingStationData) {
// Reassign to the Charging station
chargingStation.lastSeen = new Date();
chargingStation.tokenID = tokenID;
@@ -1306,6 +1307,7 @@ export default class OCPPUtils {
cloudHostIP: chargingStation.cloudHostIP,
cloudHostName: chargingStation.cloudHostName,
});
+ }
return { tenant, chargingStation, token };
}

ocppj - prevent last seen update on REST WS calls