firstTry on GetDiagnostics
ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingstation-action-get-diagnostics.json
+{
+ "title": "Get Charging Station diagnostics (endpoint)",
+ "type": "object",
+ "properties": {
+ "chargingStationID": {
+ "$ref": "chargingstation.json#/definitions/id"
+ },
+ "args": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "retries": {
+ "type": "number",
+ "sanitize": "mongo"
+ },
+ "retryInterval": {
+ "type": "number",
+ "sanitize": "mongo"
+ },
+ "startTime": {
+ "type": "string",
+ "format": "date-time",
+ "sanitize": "mongo"
+ },
+ "stopTime": {
+ "type": "string",
+ "format": "date-time",
+ "sanitize": "mongo"
+ }
+ },
+ "required": [
+ "location"
+ ]
+ }
+ },
+ "required": [
+ "chargingStationID"
+ ]
+}

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -47,6 +47,7 @@ import UserStorage from '../../../../storage/mongodb/UserStorage';
import UserToken from '../../../../types/UserToken';
import Utils from '../../../../utils/Utils';
import UtilsService from './UtilsService';
+import { filter } from 'lodash';
const MODULE_NAME = 'ChargingStationService';
@@ -1149,6 +1150,16 @@ export default class ChargingStationService {
// Get the Charging station
const chargingStation = await UtilsService.checkAndGetChargingStationAuthorization(
req.tenant, req.user, filteredRequest.chargingStationID, action, null, { withSite: true, withSiteArea: true });
+ // Get the OCPP Client
+ const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(req.tenant, chargingStation);
+ if (!chargingStationClient) {
+ throw new BackendError({
+ source: chargingStation.id,
+ action: action,
+ module: MODULE_NAME, method: 'handleChargingStationCommand',
+ message: 'Charging Station is not connected to the backend',
+ });
+ }
let result: any;
switch (command) {
// Remote Stop Transaction / Unlock Connector
@@ -1177,11 +1188,26 @@ export default class ChargingStationService {
value: chargingStation.id
});
}
+ switch (command) {
+ // Get diagnostic
+ case Command.GET_DIAGNOSTICS:
+ // const filteredRequest = ChargingStationValidator.validateChargingStationGetDiagnostics(params);
+ filteredRequest = ChargingStationValidator.getInstance().validateChargingStationGetDiagnostics(req.body);
+ result = await chargingStationClient.getDiagnostics({
+ location: filteredRequest.args.location,
+ retries: filteredRequest.args.retries,
+ retryInterval: filteredRequest.args.retryInterval,
+ startTime: filteredRequest.args.startTime,
+ stopTime: filteredRequest.args.stopTime
+ });
+ break;
+ default:
// Execute it
result = await ChargingStationService.executeChargingStationCommand(
req.tenant, req.user, chargingStation, action, command, filteredRequest.args);
break;
}
+ }
res.json(result);
next();
}
@@ -1574,16 +1600,6 @@ export default class ChargingStationService {
type: params.type
});
break;
- // Get diagnostic
- case Command.GET_DIAGNOSTICS:
- result = await chargingStationClient.getDiagnostics({
- location: params.location,
- retries: params.retries,
- retryInterval: params.retryInterval,
- startTime: params.startTime,
- stopTime: params.stopTime
- });
- break;
// Update Firmware
case Command.UPDATE_FIRMWARE:
result = await chargingStationClient.updateFirmware({

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
-import { HttpChargingProfilesRequest, HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationOcppRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationsInErrorRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
+import { HttpChargingProfilesRequest, HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetDiagnostics, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationOcppRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationsInErrorRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
import { ChargingProfile } from '../../../../types/ChargingProfile';
import HttpDatabaseRequest from '../../../../types/requests/HttpDatabaseRequest';
@@ -21,6 +21,7 @@ export default class ChargingStationValidator extends SchemaValidator {
private chargingStationUpdateParameters: Schema;
private chargingStationLimitPower: Schema;
private chargingStationFirmwareDownload: Schema;
+ private chargingStationGetDiagnostics: Schema;
private smartChargingTrigger: Schema;
private chargingStationInErrorGet: Schema;
private chargingProfileCreate: Schema;
@@ -43,6 +44,7 @@ export default class ChargingStationValidator extends SchemaValidator {
this.chargingStationUpdateParameters = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-update-parameters.json`, 'utf8'));
this.chargingStationLimitPower = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-limit-power.json`, 'utf8'));
this.chargingStationFirmwareDownload = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-firmware-download.json`, 'utf8'));
+ this.chargingStationGetDiagnostics = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-action-get-diagnostics.json`, 'utf8'));
this.smartChargingTrigger = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/smartcharging-trigger.json`, 'utf8'));
this.chargingStationInErrorGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstations-inerror-get.json`, 'utf8'));
this.chargingProfileCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingprofile-create.json`, 'utf8'));
@@ -131,6 +133,12 @@ export default class ChargingStationValidator extends SchemaValidator {
return data;
}
+ public validateChargingStationGetDiagnostics(data: HttpChargingStationGetDiagnostics): HttpChargingStationGetDiagnostics {
+ // Validate schema
+ this.validate(this.chargingStationGetDiagnostics, data);
+ return data;
+ }
+
public validateSmartChargingTriggerReq(data: any): HttpTriggerSmartChargingRequest {
// Validate schema
this.validate(this.smartChargingTrigger, data);

MODIFY
src/types/requests/HttpChargingStationRequest.ts
src/types/requests/HttpChargingStationRequest.ts
@@ -121,3 +121,14 @@ export interface HttpIsAuthorizedRequest {
export interface HttpChargingStationGetFirmwareRequest {
FileName: string;
}
+
+export interface HttpChargingStationGetDiagnostics {
+ chargingStationID: string,
+ args: {
+ location: string,
+ retries?: number,
+ retryInterval?: number,
+ startTime?: Date,
+ stopTime?: Date
+ }
+}

firstTry on GetDiagnostics