Check if charging station is offline before sending notification
MODIFY
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
+import ChargingStationClientFactory from '../../client/ocpp/ChargingStationClientFactory';
import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
import { CheckOfflineChargingStationsTaskConfig } from '../../types/TaskConfig';
import Constants from '../../utils/Constants';
@@ -26,6 +27,18 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
offlineSince
}, Constants.DB_PARAMS_MAX_LIMIT);
if (chargingStations.count > 0) {
+ for (let i = 0; i < chargingStations.result.length; i++) {
+ const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant.id, chargingStations.result[i]);
+ if ((await chargingStationClient.getConfiguration({})).configurationKey.length > 0) {
+ // Update Heartbeat
+ chargingStations.result[i].lastHeartBeat = new Date();
+ // Save
+ await ChargingStationStorage.saveChargingStation(tenant.id, chargingStations.result[i]);
+ // Remove from notification
+ chargingStations.result.splice(i);
+ }
+ }
+ if (chargingStations.result.length > 0) {
const chargingStationIDs: string = chargingStations.result.map((chargingStation) => chargingStation.id).join(', ');
// Send notification
await NotificationHandler.sendOfflineChargingStations(
@@ -35,6 +48,7 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
}
);
}
+ }
} catch (error) {
// Log error
Logging.logActionExceptionMessage(tenant.id, ServerAction.OFFLINE_CHARGING_STATION, error);

Check if charging station is offline before sending notification