+
+ private handleRequestTriggerMessage(
+ chargingStation: ChargingStation,
+ commandPayload: OCPP16TriggerMessageRequest
+ ): OCPP16TriggerMessageResponse {
+ if (
+ !OCPP16ServiceUtils.checkFeatureProfile(
+ chargingStation,
+ OCPP16SupportedFeatureProfiles.RemoteTrigger,
+ OCPP16IncomingRequestCommand.TRIGGER_MESSAGE
+ )
+ ) {
+ return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
+ }
+ // TODO: factor out the check on connector id
+ if (commandPayload?.connectorId < 0) {
+ logger.warn(
+ `${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:
+ setTimeout(() => {
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
+ chargingStation,
+ OCPP16RequestCommand.BOOT_NOTIFICATION,
+ {
+ chargePointModel: chargingStation.getBootNotificationRequest().chargePointModel,
+ chargePointVendor: chargingStation.getBootNotificationRequest().chargePointVendor,
+ chargeBoxSerialNumber:
+ chargingStation.getBootNotificationRequest().chargeBoxSerialNumber,
+ firmwareVersion: chargingStation.getBootNotificationRequest().firmwareVersion,
+ chargePointSerialNumber:
+ chargingStation.getBootNotificationRequest().chargePointSerialNumber,
+ iccid: chargingStation.getBootNotificationRequest().iccid,
+ imsi: chargingStation.getBootNotificationRequest().imsi,
+ meterSerialNumber: chargingStation.getBootNotificationRequest().meterSerialNumber,
+ meterType: chargingStation.getBootNotificationRequest().meterType,
+ },
+ { skipBufferingOnError: true, triggerMessage: true }
+ )
+ .then((value) => {
+ chargingStation.bootNotificationResponse = value;
+ })
+ .catch(() => {
+ /* This is intentional */
+ });
+ }, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
+ return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
+ case MessageTrigger.Heartbeat:
+ setTimeout(() => {
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
+ chargingStation,
+ OCPP16RequestCommand.HEARTBEAT,
+ null,
+ {
+ triggerMessage: true,
+ }
+ )
+ .catch(() => {
+ /* This is intentional */
+ });
+ }, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
+ return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
+ case MessageTrigger.StatusNotification:
+ setTimeout(() => {
+ if (commandPayload?.connectorId) {
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse>(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: commandPayload.connectorId,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: chargingStation.getConnectorStatus(commandPayload.connectorId).status,
+ },
+ {
+ triggerMessage: true,
+ }
+ )
+ .catch(() => {
+ /* This is intentional */
+ });
+ } else {
+ for (const connectorId of chargingStation.connectors.keys()) {
+ chargingStation.ocppRequestService
+ .requestHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: 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;
+ }
+ } catch (error) {
+ return this.handleIncomingRequestError(
+ chargingStation,
+ OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
+ error as Error,
+ { errorResponse: Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED }
+ );
+ }
+ }