Only update the timestamp
MODIFY
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
+import moment from 'moment';
import ChargingStationClientFactory from '../../client/ocpp/ChargingStationClientFactory';
-import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
-import { CheckOfflineChargingStationsTaskConfig } from '../../types/TaskConfig';
-import Constants from '../../utils/Constants';
-import { LockEntity } from '../../types/Locking';
import LockingManager from '../../locking/LockingManager';
-import Logging from '../../utils/Logging';
import NotificationHandler from '../../notification/NotificationHandler';
-import SchedulerTask from '../SchedulerTask';
+import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
+import { LockEntity } from '../../types/Locking';
+import { OCPPGetConfigurationCommandResult } from '../../types/ocpp/OCPPClient';
import { ServerAction } from '../../types/Server';
+import { CheckOfflineChargingStationsTaskConfig } from '../../types/TaskConfig';
import Tenant from '../../types/Tenant';
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
import Utils from '../../utils/Utils';
-import moment from 'moment';
+import SchedulerTask from '../SchedulerTask';
export default class CheckOfflineChargingStationsTask extends SchedulerTask {
@@ -28,7 +29,8 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
}, Constants.DB_PARAMS_MAX_LIMIT);
if (chargingStations.count > 0) {
for (let i = chargingStations.result.length - 1; i >= 0; i--) {
- let configuration;
+ let configuration: OCPPGetConfigurationCommandResult;
+ // Check if charging station is still connected
try {
const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant.id, chargingStations.result[i]);
if (chargingStationClient) {
@@ -37,15 +39,17 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
} catch (error) {
continue;
}
+ // Charging Station is still connected: ignore it
if (configuration) {
// Update Heartbeat
await ChargingStationStorage.saveChargingStationHeartBeat(tenant.id, chargingStations.result[i].id,
- { lastHeartBeat: new Date(),
- currentIPAddress: chargingStations.result[i].currentIPAddress });
- // Remove from notification
+ { lastHeartBeat: new Date() }
+ );
+ // Remove charging station from notification
chargingStations.result.splice(i, 1);
}
}
+ // Notify users with the rest of the Charging Stations
if (chargingStations.result.length > 0) {
const chargingStationIDs: string = chargingStations.result.map((chargingStation) => chargingStation.id).join(', ');
// Send notification

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -515,14 +515,14 @@ export default class ChargingStationStorage {
}
public static async saveChargingStationHeartBeat(tenantID: string, id: string,
- params: { lastHeartBeat: Date; currentIPAddress: string | string[] }): Promise<void> {
+ params: { lastHeartBeat: Date; currentIPAddress?: string | string[] }): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'saveChargingStationHeartBeat');
// Check Tenant
await Utils.checkTenant(tenantID);
// Set data
// Modify and return the modified document
- const result = await global.database.getCollection<any>(tenantID, 'chargingstations').findOneAndUpdate(
+ await global.database.getCollection<any>(tenantID, 'chargingstations').findOneAndUpdate(
{ '_id': id },
{ $set: params },
{ upsert: true });

Only update the timestamp