1 import * as url from
'url';
3 import { ChangeAvailabilityRequest
, ChangeConfigurationRequest
, ClearChargingProfileRequest
, GetConfigurationRequest
, GetDiagnosticsRequest
, OCPP16AvailabilityType
, OCPP16IncomingRequestCommand
, RemoteStartTransactionRequest
, RemoteStopTransactionRequest
, ResetRequest
, SetChargingProfileRequest
, UnlockConnectorRequest
} from
'../../../types/ocpp/1.6/Requests';
4 import { ChangeAvailabilityResponse
, ChangeConfigurationResponse
, ClearChargingProfileResponse
, GetConfigurationResponse
, GetDiagnosticsResponse
, SetChargingProfileResponse
, UnlockConnectorResponse
} from
'../../../types/ocpp/1.6/Responses';
5 import { ChargingProfilePurposeType
, OCPP16ChargingProfile
} from
'../../../types/ocpp/1.6/ChargingProfile';
6 import { Client
, FTPResponse
} from
'basic-ftp';
7 import { IncomingRequestCommand
, RequestCommand
} from
'../../../types/ocpp/Requests';
8 import { OCPP16AuthorizationStatus
, OCPP16StopTransactionReason
} from
'../../../types/ocpp/1.6/Transaction';
10 import Constants from
'../../../utils/Constants';
11 import { DefaultResponse
} from
'../../../types/ocpp/Responses';
12 import { ErrorType
} from
'../../../types/ocpp/ErrorType';
13 import { MessageType
} from
'../../../types/ocpp/MessageType';
14 import { OCPP16ChargePointStatus
} from
'../../../types/ocpp/1.6/ChargePointStatus';
15 import { OCPP16DiagnosticsStatus
} from
'../../../types/ocpp/1.6/DiagnosticsStatus';
16 import { OCPP16StandardParametersKey
} from
'../../../types/ocpp/1.6/Configuration';
17 import { OCPPConfigurationKey
} from
'../../../types/ocpp/Configuration';
18 import OCPPError from
'../../OCPPError';
19 import OCPPIncomingRequestService from
'../OCPPIncomingRequestService';
20 import Utils from
'../../../utils/Utils';
22 import logger from
'../../../utils/Logger';
23 import path from
'path';
24 import tar from
'tar';
26 export default class OCPP16IncomingRequestService
extends OCPPIncomingRequestService
{
27 public async handleRequest(messageId
: string, commandName
: OCPP16IncomingRequestCommand
, commandPayload
: Record
<string, unknown
>): Promise
<void> {
29 const methodName
= `handleRequest${commandName}`;
31 if (typeof this[methodName
] === 'function') {
33 // Call the method to build the response
34 response
= await this[methodName
](commandPayload
);
37 logger
.error(this.chargingStation
.logPrefix() + ' Handle request error: %j', error
);
38 // Send back an error response to inform backend
39 await this.chargingStation
.ocppRequestService
.sendError(messageId
, error
, commandName
);
44 await this.chargingStation
.ocppRequestService
.sendError(messageId
, new OCPPError(ErrorType
.NOT_IMPLEMENTED
, `${commandName} is not implemented`, {}), commandName
);
45 throw new Error(`${commandName} is not implemented to handle payload ${JSON.stringify(commandPayload)}`);
47 // Send the built response
48 await this.chargingStation
.ocppRequestService
.sendMessage(messageId
, response
, MessageType
.CALL_RESULT_MESSAGE
, commandName
);
51 // Simulate charging station restart
52 private handleRequestReset(commandPayload
: ResetRequest
): DefaultResponse
{
53 // eslint-disable-next-line @typescript-eslint/no-misused-promises
54 setImmediate(async (): Promise
<void> => {
55 await this.chargingStation
.stop(commandPayload
.type + 'Reset' as OCPP16StopTransactionReason
);
56 await Utils
.sleep(this.chargingStation
.stationInfo
.resetTime
);
57 this.chargingStation
.start();
59 logger
.info(`${this.chargingStation.logPrefix()} ${commandPayload.type} reset command received, simulating it. The station will be back online in ${Utils.milliSecondsToHHMMSS(this.chargingStation.stationInfo.resetTime)}`);
60 return Constants
.OCPP_RESPONSE_ACCEPTED
;
63 private handleRequestClearCache(): DefaultResponse
{
64 return Constants
.OCPP_RESPONSE_ACCEPTED
;
67 private async handleRequestUnlockConnector(commandPayload
: UnlockConnectorRequest
): Promise
<UnlockConnectorResponse
> {
68 const connectorId
= commandPayload
.connectorId
;
69 if (connectorId
=== 0) {
70 logger
.error(this.chargingStation
.logPrefix() + ' Trying to unlock connector ' + connectorId
.toString());
71 return Constants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
73 if (this.chargingStation
.getConnector(connectorId
)?.transactionStarted
) {
74 const transactionId
= this.chargingStation
.getConnector(connectorId
).transactionId
;
75 const stopResponse
= await this.chargingStation
.ocppRequestService
.sendStopTransaction(transactionId
,
76 this.chargingStation
.getEnergyActiveImportRegisterByTransactionId(transactionId
),
77 this.chargingStation
.getTransactionIdTag(transactionId
),
78 OCPP16StopTransactionReason
.UNLOCK_COMMAND
);
79 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
80 return Constants
.OCPP_RESPONSE_UNLOCKED
;
82 return Constants
.OCPP_RESPONSE_UNLOCK_FAILED
;
84 await this.chargingStation
.ocppRequestService
.sendStatusNotification(connectorId
, OCPP16ChargePointStatus
.AVAILABLE
);
85 this.chargingStation
.getConnector(connectorId
).status = OCPP16ChargePointStatus
.AVAILABLE
;
86 return Constants
.OCPP_RESPONSE_UNLOCKED
;
89 private handleRequestGetConfiguration(commandPayload
: GetConfigurationRequest
): GetConfigurationResponse
{
90 const configurationKey
: OCPPConfigurationKey
[] = [];
91 const unknownKey
: string[] = [];
92 if (Utils
.isEmptyArray(commandPayload
.key
)) {
93 for (const configuration
of this.chargingStation
.configuration
.configurationKey
) {
94 if (Utils
.isUndefined(configuration
.visible
)) {
95 configuration
.visible
= true;
97 if (!configuration
.visible
) {
100 configurationKey
.push({
101 key
: configuration
.key
,
102 readonly: configuration
.readonly,
103 value
: configuration
.value
,
107 for (const key
of commandPayload
.key
) {
108 const keyFound
= this.chargingStation
.getConfigurationKey(key
);
110 if (Utils
.isUndefined(keyFound
.visible
)) {
111 keyFound
.visible
= true;
113 if (!keyFound
.visible
) {
116 configurationKey
.push({
118 readonly: keyFound
.readonly,
119 value
: keyFound
.value
,
122 unknownKey
.push(key
);
132 private handleRequestChangeConfiguration(commandPayload
: ChangeConfigurationRequest
): ChangeConfigurationResponse
{
133 // JSON request fields type sanity check
134 if (!Utils
.isString(commandPayload
.key
)) {
135 logger
.error(`${this.chargingStation.logPrefix()} ${RequestCommand.CHANGE_CONFIGURATION} request key field is not a string:`, commandPayload
);
137 if (!Utils
.isString(commandPayload
.value
)) {
138 logger
.error(`${this.chargingStation.logPrefix()} ${RequestCommand.CHANGE_CONFIGURATION} request value field is not a string:`, commandPayload
);
140 const keyToChange
= this.chargingStation
.getConfigurationKey(commandPayload
.key
, true);
142 return Constants
.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
;
143 } else if (keyToChange
&& keyToChange
.readonly) {
144 return Constants
.OCPP_CONFIGURATION_RESPONSE_REJECTED
;
145 } else if (keyToChange
&& !keyToChange
.readonly) {
146 const keyIndex
= this.chargingStation
.configuration
.configurationKey
.indexOf(keyToChange
);
147 let valueChanged
= false;
148 if (this.chargingStation
.configuration
.configurationKey
[keyIndex
].value
!== commandPayload
.value
) {
149 this.chargingStation
.configuration
.configurationKey
[keyIndex
].value
= commandPayload
.value
;
152 let triggerHeartbeatRestart
= false;
153 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartBeatInterval
&& valueChanged
) {
154 this.chargingStation
.setConfigurationKeyValue(OCPP16StandardParametersKey
.HeartbeatInterval
, commandPayload
.value
);
155 triggerHeartbeatRestart
= true;
157 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartbeatInterval
&& valueChanged
) {
158 this.chargingStation
.setConfigurationKeyValue(OCPP16StandardParametersKey
.HeartBeatInterval
, commandPayload
.value
);
159 triggerHeartbeatRestart
= true;
161 if (triggerHeartbeatRestart
) {
162 this.chargingStation
.restartHeartbeat();
164 if (keyToChange
.key
=== OCPP16StandardParametersKey
.WebSocketPingInterval
&& valueChanged
) {
165 this.chargingStation
.restartWebSocketPing();
167 if (keyToChange
.reboot
) {
168 return Constants
.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED
;
170 return Constants
.OCPP_CONFIGURATION_RESPONSE_ACCEPTED
;
174 private handleRequestSetChargingProfile(commandPayload
: SetChargingProfileRequest
): SetChargingProfileResponse
{
175 if (!this.chargingStation
.getConnector(commandPayload
.connectorId
)) {
176 logger
.error(`${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
177 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
179 if (commandPayload
.csChargingProfiles
.chargingProfilePurpose
=== ChargingProfilePurposeType
.CHARGE_POINT_MAX_PROFILE
&& commandPayload
.connectorId
!== 0) {
180 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
182 if (commandPayload
.csChargingProfiles
.chargingProfilePurpose
=== ChargingProfilePurposeType
.TX_PROFILE
&& (commandPayload
.connectorId
=== 0 || !this.chargingStation
.getConnector(commandPayload
.connectorId
)?.transactionStarted
)) {
183 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
185 this.chargingStation
.setChargingProfile(commandPayload
.connectorId
, commandPayload
.csChargingProfiles
);
186 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`, this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
);
187 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
190 private handleRequestClearChargingProfile(commandPayload
: ClearChargingProfileRequest
): ClearChargingProfileResponse
{
191 if (!this.chargingStation
.getConnector(commandPayload
.connectorId
)) {
192 logger
.error(`${this.chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
193 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
195 if (commandPayload
.connectorId
&& !Utils
.isEmptyArray(this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
)) {
196 this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
= [];
197 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
);
198 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
200 if (!commandPayload
.connectorId
) {
201 let clearedCP
= false;
202 for (const connector
in this.chargingStation
.connectors
) {
203 if (!Utils
.isEmptyArray(this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).chargingProfiles
)) {
204 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).chargingProfiles
?.forEach((chargingProfile
: OCPP16ChargingProfile
, index
: number) => {
205 let clearCurrentCP
= false;
206 if (chargingProfile
.chargingProfileId
=== commandPayload
.id
) {
207 clearCurrentCP
= true;
209 if (!commandPayload
.chargingProfilePurpose
&& chargingProfile
.stackLevel
=== commandPayload
.stackLevel
) {
210 clearCurrentCP
= true;
212 if (!chargingProfile
.stackLevel
&& chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
) {
213 clearCurrentCP
= true;
215 if (chargingProfile
.stackLevel
=== commandPayload
.stackLevel
&& chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
) {
216 clearCurrentCP
= true;
218 if (clearCurrentCP
) {
219 this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
[index
] = {} as OCPP16ChargingProfile
;
220 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
);
227 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
230 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
233 private async handleRequestChangeAvailability(commandPayload
: ChangeAvailabilityRequest
): Promise
<ChangeAvailabilityResponse
> {
234 const connectorId
: number = commandPayload
.connectorId
;
235 if (!this.chargingStation
.getConnector(connectorId
)) {
236 logger
.error(`${this.chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`);
237 return Constants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
239 const chargePointStatus
: OCPP16ChargePointStatus
= commandPayload
.type === OCPP16AvailabilityType
.OPERATIVE
? OCPP16ChargePointStatus
.AVAILABLE
: OCPP16ChargePointStatus
.UNAVAILABLE
;
240 if (connectorId
=== 0) {
241 let response
: ChangeAvailabilityResponse
= Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
242 for (const connector
in this.chargingStation
.connectors
) {
243 if (this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).transactionStarted
) {
244 response
= Constants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
246 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).availability
= commandPayload
.type;
247 if (response
=== Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
) {
248 await this.chargingStation
.ocppRequestService
.sendStatusNotification(Utils
.convertToInt(connector
), chargePointStatus
);
249 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).status = chargePointStatus
;
253 } else if (connectorId
> 0 && (this.chargingStation
.getConnector(0).availability
=== OCPP16AvailabilityType
.OPERATIVE
|| (this.chargingStation
.getConnector(0).availability
=== OCPP16AvailabilityType
.INOPERATIVE
&& commandPayload
.type === OCPP16AvailabilityType
.INOPERATIVE
))) {
254 if (this.chargingStation
.getConnector(connectorId
)?.transactionStarted
) {
255 this.chargingStation
.getConnector(connectorId
).availability
= commandPayload
.type;
256 return Constants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
258 this.chargingStation
.getConnector(connectorId
).availability
= commandPayload
.type;
259 await this.chargingStation
.ocppRequestService
.sendStatusNotification(connectorId
, chargePointStatus
);
260 this.chargingStation
.getConnector(connectorId
).status = chargePointStatus
;
261 return Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
263 return Constants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
266 private async handleRequestRemoteStartTransaction(commandPayload
: RemoteStartTransactionRequest
): Promise
<DefaultResponse
> {
267 const transactionConnectorId
: number = commandPayload
.connectorId
;
268 if (transactionConnectorId
) {
269 await this.chargingStation
.ocppRequestService
.sendStatusNotification(transactionConnectorId
, OCPP16ChargePointStatus
.PREPARING
);
270 this.chargingStation
.getConnector(transactionConnectorId
).status = OCPP16ChargePointStatus
.PREPARING
;
271 if (this.chargingStation
.isChargingStationAvailable() && this.chargingStation
.isConnectorAvailable(transactionConnectorId
)) {
272 // Check if authorized
273 if (this.chargingStation
.getAuthorizeRemoteTxRequests()) {
274 let authorized
= false;
275 if (this.chargingStation
.getLocalAuthListEnabled() && this.chargingStation
.hasAuthorizedTags()
276 && this.chargingStation
.authorizedTags
.find((value
) => value
=== commandPayload
.idTag
)) {
279 if (!authorized
|| (authorized
&& this.chargingStation
.getMayAuthorizeAtRemoteStart())) {
280 const authorizeResponse
= await this.chargingStation
.ocppRequestService
.sendAuthorize(transactionConnectorId
, commandPayload
.idTag
);
281 if (authorizeResponse
?.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
288 // Authorization successful, start transaction
289 if (this.setRemoteStartTransactionChargingProfile(transactionConnectorId
, commandPayload
.chargingProfile
)) {
290 if ((await this.chargingStation
.ocppRequestService
.sendStartTransaction(transactionConnectorId
, commandPayload
.idTag
)).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
291 logger
.debug(this.chargingStation
.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation
.stationInfo
.chargingStationId
+ '#' + transactionConnectorId
.toString() + ' for idTag ' + commandPayload
.idTag
);
292 return Constants
.OCPP_RESPONSE_ACCEPTED
;
294 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
296 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
298 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
300 // No authorization check required, start transaction
301 if (this.setRemoteStartTransactionChargingProfile(transactionConnectorId
, commandPayload
.chargingProfile
)) {
302 if ((await this.chargingStation
.ocppRequestService
.sendStartTransaction(transactionConnectorId
, commandPayload
.idTag
)).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
303 logger
.debug(this.chargingStation
.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation
.stationInfo
.chargingStationId
+ '#' + transactionConnectorId
.toString() + ' for idTag ' + commandPayload
.idTag
);
304 return Constants
.OCPP_RESPONSE_ACCEPTED
;
306 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
308 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
310 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
312 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
315 private async notifyRemoteStartTransactionRejected(connectorId
: number, idTag
: string): Promise
<DefaultResponse
> {
316 if (this.chargingStation
.getConnector(connectorId
).status !== OCPP16ChargePointStatus
.AVAILABLE
) {
317 await this.chargingStation
.ocppRequestService
.sendStatusNotification(connectorId
, OCPP16ChargePointStatus
.AVAILABLE
);
318 this.chargingStation
.getConnector(connectorId
).status = OCPP16ChargePointStatus
.AVAILABLE
;
320 logger
.warn(this.chargingStation
.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + connectorId
.toString() + ', idTag ' + idTag
+ ', availability ' + this.chargingStation
.getConnector(connectorId
).availability
+ ', status ' + this.chargingStation
.getConnector(connectorId
).status);
321 return Constants
.OCPP_RESPONSE_REJECTED
;
324 private setRemoteStartTransactionChargingProfile(connectorId
: number, cp
: OCPP16ChargingProfile
): boolean {
325 if (cp
&& cp
.chargingProfilePurpose
=== ChargingProfilePurposeType
.TX_PROFILE
) {
326 this.chargingStation
.setChargingProfile(connectorId
, cp
);
327 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction, dump their stack: %j`, this.chargingStation
.getConnector(connectorId
).chargingProfiles
);
329 } else if (cp
&& cp
.chargingProfilePurpose
!== ChargingProfilePurposeType
.TX_PROFILE
) {
330 logger
.warn(`${this.chargingStation.logPrefix()} Not allowed to set ${cp.chargingProfilePurpose} charging profile(s) at remote start transaction`);
337 private async handleRequestRemoteStopTransaction(commandPayload
: RemoteStopTransactionRequest
): Promise
<DefaultResponse
> {
338 const transactionId
= commandPayload
.transactionId
;
339 for (const connector
in this.chargingStation
.connectors
) {
340 if (Utils
.convertToInt(connector
) > 0 && this.chargingStation
.getConnector(Utils
.convertToInt(connector
))?.transactionId
=== transactionId
) {
341 await this.chargingStation
.ocppRequestService
.sendStatusNotification(Utils
.convertToInt(connector
), OCPP16ChargePointStatus
.FINISHING
);
342 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).status = OCPP16ChargePointStatus
.FINISHING
;
343 await this.chargingStation
.ocppRequestService
.sendStopTransaction(transactionId
, this.chargingStation
.getEnergyActiveImportRegisterByTransactionId(transactionId
),
344 this.chargingStation
.getTransactionIdTag(transactionId
));
345 return Constants
.OCPP_RESPONSE_ACCEPTED
;
348 logger
.info(this.chargingStation
.logPrefix() + ' Trying to remote stop a non existing transaction ' + transactionId
.toString());
349 return Constants
.OCPP_RESPONSE_REJECTED
;
352 private async handleRequestGetDiagnostics(commandPayload
: GetDiagnosticsRequest
): Promise
<GetDiagnosticsResponse
> {
353 logger
.debug(this.chargingStation
.logPrefix() + ' ' + IncomingRequestCommand
.GET_DIAGNOSTICS
+ ' request received: %j', commandPayload
);
354 const uri
= new url
.URL(commandPayload
.location
);
355 if (uri
.protocol
.startsWith('ftp:')) {
356 let ftpClient
: Client
;
358 const logFiles
= fs
.readdirSync(path
.resolve(__dirname
, '../../../../')).filter((file
) => file
.endsWith('.log')).map((file
) => path
.join('./', file
));
359 const diagnosticsArchive
= this.chargingStation
.stationInfo
.chargingStationId
+ '_logs.tar.gz';
360 tar
.create({ gzip
: true }, logFiles
).pipe(fs
.createWriteStream(diagnosticsArchive
));
361 ftpClient
= new Client();
362 const accessResponse
= await ftpClient
.access({
364 ...(uri
.port
!== '') && { port
: Utils
.convertToInt(uri
.port
) },
365 ...(uri
.username
!== '') && { user
: uri
.username
},
366 ...(uri
.password
!== '') && { password
: uri
.password
},
368 let uploadResponse
: FTPResponse
;
369 if (accessResponse
.code
=== 220) {
370 // eslint-disable-next-line @typescript-eslint/no-misused-promises
371 ftpClient
.trackProgress(async (info
) => {
372 logger
.info(`${this.chargingStation.logPrefix()} ${info.bytes / 1024} bytes transferred from diagnostics archive ${info.name}`);
373 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.Uploading
);
375 uploadResponse
= await ftpClient
.uploadFrom(path
.join(path
.resolve(__dirname
, '../../../../'), diagnosticsArchive
), uri
.pathname
+ diagnosticsArchive
);
376 if (uploadResponse
.code
=== 226) {
377 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.Uploaded
);
381 return { fileName
: diagnosticsArchive
};
383 throw new Error(`Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`);
385 throw new Error(`Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`);
387 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.UploadFailed
);
391 return this.handleIncomingRequestError(IncomingRequestCommand
.GET_DIAGNOSTICS
, error
, Constants
.OCPP_RESPONSE_EMPTY
);
394 logger
.error(`${this.chargingStation.logPrefix()} Unsupported protocol ${uri.protocol} to transfer the diagnostic logs archive`);
395 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.UploadFailed
);
396 return Constants
.OCPP_RESPONSE_EMPTY
;