Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Add status notification support to trigger message OCPP command
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Apr 18, 2022
1 parent 87fed8a commit dc66170
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
) {
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
}
// TODO: factor out the check on connector id
if (commandPayload?.connectorId < 0) {
logger.warn(
`${this.chargingStation.logPrefix()} ${
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE
} incoming request received with invalid connectorId ${commandPayload.connectorId}`
);
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED;
}
try {
switch (commandPayload.requestedMessage) {
case MessageTrigger.BootNotification:
Expand Down Expand Up @@ -999,6 +1008,49 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
});
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
case MessageTrigger.StatusNotification:
setTimeout(() => {
if (commandPayload?.connectorId) {
this.chargingStation.ocppRequestService
.requestHandler<OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId: commandPayload.connectorId,
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
status: this.chargingStation.getConnectorStatus(commandPayload.connectorId)
.status,
},
{
triggerMessage: true,
}
)
.catch(() => {
/* This is intentional */
});
} else {
for (const connectorId of this.chargingStation.connectors.keys()) {
this.chargingStation.ocppRequestService
.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId,
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
status: this.chargingStation.getConnectorStatus(connectorId).status,
},
{
triggerMessage: true,
}
)
.catch(() => {
/* This is intentional */
});
}
}
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
default:
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
}
Expand Down

0 comments on commit dc66170

Please sign in to comment.