Enhance OCPP logs / Concur
MODIFY
src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts
src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts
+import Tenant, { TenantComponents } from '../../types/Tenant';
+
import Constants from '../../utils/Constants';
import { LockEntity } from '../../types/Locking';
import LockingManager from '../../locking/LockingManager';
@@ -7,8 +9,6 @@ import { RefundStatus } from '../../types/Refund';
import SchedulerTask from '../SchedulerTask';
import { ServerAction } from '../../types/Server';
import { TaskConfig } from '../../types/TaskConfig';
-import Tenant from '../../types/Tenant';
-import { TenantComponents } from '../../types/Tenant';
import TransactionStorage from '../../storage/mongodb/TransactionStorage';
import Utils from '../../utils/Utils';

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -95,7 +95,7 @@ export default class OCPPService {
// Send Notification (Async)
this.notifyBootNotification(tenant, chargingStation);
// Request OCPP configuration
- this.requestOCPPConfigurationDelayed(tenant, chargingStation, templateUpdateResult, heartbeatIntervalSecs);
+ this.requestOCPPConfigurationAfterBootNotification(tenant, chargingStation, templateUpdateResult, heartbeatIntervalSecs);
// Log
await Logging.logInfo({
tenantID: tenant.id,
@@ -141,7 +141,7 @@ export default class OCPPService {
// Save Heart Beat
await OCPPStorage.saveHeartbeat(tenant, heartbeat);
// Log
- await Logging.logDebug({
+ await Logging.logInfo({
tenantID: tenant.id,
siteID: chargingStation.siteID,
siteAreaID: chargingStation.siteAreaID,
@@ -1951,25 +1951,21 @@ export default class OCPPService {
);
}
- private requestOCPPConfigurationDelayed(tenant: Tenant, chargingStation: ChargingStation, templateUpdateResult: TemplateUpdateResult, heartbeatIntervalSecs: number) {
+ private requestOCPPConfigurationAfterBootNotification(tenant: Tenant, chargingStation: ChargingStation,
+ templateUpdateResult: TemplateUpdateResult, heartbeatIntervalSecs: number) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async () => {
- let result: OCPPChangeConfigurationCommandResult;
// Synchronize heartbeat interval OCPP parameter for charging stations that do not take into account its value in the boot notification response
- let setHeartbeatIntervalOcppParam = false;
- // Change one of the key
for (const heartbeatOcppKey of Constants.OCPP_HEARTBEAT_KEYS) {
- result = await OCPPUtils.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
+ try {
+ const result = await OCPPUtils.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
key: heartbeatOcppKey,
value: heartbeatIntervalSecs.toString()
}, false);
if (result.status === OCPPConfigurationStatus.ACCEPTED ||
result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) {
- setHeartbeatIntervalOcppParam = true;
break;
}
- }
- if (!setHeartbeatIntervalOcppParam) {
await Logging.logError({
tenantID: tenant.id,
action: ServerAction.OCPP_BOOT_NOTIFICATION,
@@ -1978,14 +1974,26 @@ export default class OCPPService {
companyID: chargingStation.companyID,
chargingStationID: chargingStation.id,
module: MODULE_NAME, method: 'requestOCPPConfigurationDelayed',
- message: `Cannot set heartbeat interval OCPP Parameter on '${chargingStation.id}' in Tenant '${tenant.name}' ('${tenant.subdomain}')`,
- detailedMessages: { heartbeatIntervalSecs, chargingStation }
+ message: `Cannot set '${heartbeatOcppKey}' to '${heartbeatIntervalSecs.toString()}' secs: '${result.status}'`
+ });
+ } catch (error) {
+ await Logging.logError({
+ tenantID: tenant.id,
+ action: ServerAction.OCPP_BOOT_NOTIFICATION,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ module: MODULE_NAME, method: 'requestOCPPConfigurationDelayed',
+ message: `Cannot set '${heartbeatOcppKey}' to '${heartbeatIntervalSecs.toString()}' secs: '${error.message as string}'`,
+ detailedMessages: { error: error.stack }
});
}
+ }
// Apply Charging Station Template OCPP configuration
if (templateUpdateResult.ocppStandardUpdated || templateUpdateResult.ocppVendorUpdated) {
- result = await OCPPUtils.applyTemplateOcppParametersToChargingStation(tenant, chargingStation);
- }
+ try {
+ const result = await OCPPUtils.applyTemplateOcppParametersToChargingStation(tenant, chargingStation);
if (result.status !== OCPPConfigurationStatus.ACCEPTED) {
await Logging.logError({
tenantID: tenant.id,
@@ -1995,10 +2003,23 @@ export default class OCPPService {
companyID: chargingStation.companyID,
chargingStationID: chargingStation.id,
module: MODULE_NAME, method: 'requestOCPPConfigurationDelayed',
- message: `Cannot request and save OCPP Parameters from '${chargingStation.id}' in Tenant '${tenant.name}' ('${tenant.subdomain}')`,
- detailedMessages: { result, chargingStation }
+ message: `Cannot apply Template OCPP Parameters: '${result.status}'`
});
}
+ } catch (error) {
+ await Logging.logError({
+ tenantID: tenant.id,
+ action: ServerAction.OCPP_BOOT_NOTIFICATION,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ module: MODULE_NAME, method: 'requestOCPPConfigurationDelayed',
+ message: `Cannot apply Template OCPP Parameters: ${error.message as string}`,
+ detailedMessages: { error: error.stack }
+ });
+ }
+ }
}, Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS);
}

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -319,7 +319,7 @@ export default class TransactionStorage {
endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; tagIDs?: string[]; inactivityStatus?: string[];
ocpiSessionID?: string; ocpiAuthorizationID?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean; oicpSessionID?: string; withSite?: boolean; withSiteArea?: boolean; withCompany?: boolean;
- statistics?: 'refund' | 'history' | 'ongoing'; refundStatus?: string[]; withTag?: boolean; hasUserID?: boolean; withUser?: boolean; withCar?: boolean;
+ statistics?: 'refund' | 'history' | 'ongoing'; refundStatus?: RefundStatus[]; withTag?: boolean; hasUserID?: boolean; withUser?: boolean; withCar?: boolean;
},
dbParams: DbParams, projectFields?: string[]): Promise<TransactionDataResult> {
// Debug
@@ -472,7 +472,7 @@ export default class TransactionStorage {
};
}
// Refund status
- if (params.refundStatus && params.refundStatus.length > 0) {
+ if (!Utils.isEmptyArray(params.refundStatus)) {
const statuses = params.refundStatus.map((status) => status === RefundStatus.NOT_SUBMITTED ? null : status);
filters['refundData.status'] = {
$in: statuses

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -710,7 +710,7 @@ export default class Logging {
method: exception.method,
action: action,
message: exception.message,
- detailedMessages: { stack: exception.stack, ...detailedMessages }
+ detailedMessages: { error: exception.stack, ...detailedMessages }
});
}

Enhance OCPP logs / Concur