Apply dependencies update
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16IncomingRequestService.ts
index 6e66807df9409c1c331354b8939d62f650bc1ce5..8dc9135fa7b80e314b0880214fd029f0f7c9a8db 100644 (file)
@@ -4,12 +4,16 @@ import {
   ChangeAvailabilityRequest,
   ChangeConfigurationRequest,
   ClearChargingProfileRequest,
+  DiagnosticsStatusNotificationRequest,
   GetConfigurationRequest,
   GetDiagnosticsRequest,
   MessageTrigger,
   OCPP16AvailabilityType,
+  OCPP16BootNotificationRequest,
+  OCPP16HeartbeatRequest,
   OCPP16IncomingRequestCommand,
   OCPP16RequestCommand,
+  OCPP16StatusNotificationRequest,
   OCPP16TriggerMessageRequest,
   RemoteStartTransactionRequest,
   RemoteStopTransactionRequest,
@@ -38,11 +42,22 @@ import {
 import { Client, FTPResponse } from 'basic-ftp';
 import {
   OCPP16AuthorizationStatus,
+  OCPP16AuthorizeRequest,
   OCPP16AuthorizeResponse,
+  OCPP16StartTransactionRequest,
   OCPP16StartTransactionResponse,
   OCPP16StopTransactionReason,
+  OCPP16StopTransactionRequest,
   OCPP16StopTransactionResponse,
 } from '../../../types/ocpp/1.6/Transaction';
+import {
+  OCPP16MeterValuesRequest,
+  OCPP16MeterValuesResponse,
+} from '../../../types/ocpp/1.6/MeterValues';
+import {
+  OCPP16StandardParametersKey,
+  OCPP16SupportedFeatureProfiles,
+} from '../../../types/ocpp/1.6/Configuration';
 
 import type ChargingStation from '../../ChargingStation';
 import Constants from '../../../utils/Constants';
@@ -53,9 +68,7 @@ import { JsonType } from '../../../types/JsonType';
 import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
 import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
-import { OCPP16MeterValuesResponse } from '../../../types/ocpp/1.6/MeterValues';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
-import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
 import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
 import OCPPError from '../../../exception/OCPPError';
 import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
@@ -113,12 +126,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     ]);
   }
 
-  public async handleRequest(
+  public async incomingRequestHandler(
     messageId: string,
     commandName: OCPP16IncomingRequestCommand,
     commandPayload: JsonType
   ): Promise<void> {
-    let result: JsonType;
+    let response: JsonType;
     if (
       this.chargingStation.getOcppStrictCompliance() &&
       this.chargingStation.isInPendingState() &&
@@ -141,8 +154,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     ) {
       if (this.incomingRequestHandlers.has(commandName)) {
         try {
-          // Call the method to build the result
-          result = await this.incomingRequestHandlers.get(commandName)(commandPayload);
+          // Call the method to build the response
+          response = await this.incomingRequestHandlers.get(commandName)(commandPayload);
         } catch (error) {
           // Log
           logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error);
@@ -171,19 +184,17 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         commandName
       );
     }
-    // Send the built result
-    await this.chargingStation.ocppRequestService.sendResult(messageId, result, commandName);
+    // Send the built response
+    await this.chargingStation.ocppRequestService.sendResponse(messageId, response, commandName);
   }
 
   // Simulate charging station restart
   private handleRequestReset(commandPayload: ResetRequest): DefaultResponse {
     // eslint-disable-next-line @typescript-eslint/no-misused-promises
     setImmediate(async (): Promise<void> => {
-      await this.chargingStation.stop(
+      await this.chargingStation.reset(
         (commandPayload.type + 'Reset') as OCPP16StopTransactionReason
       );
-      await Utils.sleep(this.chargingStation.stationInfo.resetTime);
-      this.chargingStation.start();
     });
     logger.info(
       `${this.chargingStation.logPrefix()} ${
@@ -222,39 +233,37 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           connectorId,
           this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
         );
-        await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
-          OCPP16RequestCommand.METER_VALUES,
-          {
-            connectorId,
-            transactionId,
-            meterValue: transactionEndMeterValue,
-          }
-        );
+        await this.chargingStation.ocppRequestService.requestHandler<
+          OCPP16MeterValuesRequest,
+          OCPP16MeterValuesResponse
+        >(OCPP16RequestCommand.METER_VALUES, {
+          connectorId,
+          transactionId,
+          meterValue: transactionEndMeterValue,
+        });
       }
-      const stopResponse =
-        await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StopTransactionResponse>(
-          OCPP16RequestCommand.STOP_TRANSACTION,
-          {
-            transactionId,
-            meterStop:
-              this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
-            idTag: this.chargingStation.getTransactionIdTag(transactionId),
-            reason: OCPP16StopTransactionReason.UNLOCK_COMMAND,
-          }
-        );
+      const stopResponse = await this.chargingStation.ocppRequestService.requestHandler<
+        OCPP16StopTransactionRequest,
+        OCPP16StopTransactionResponse
+      >(OCPP16RequestCommand.STOP_TRANSACTION, {
+        transactionId,
+        meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+        idTag: this.chargingStation.getTransactionIdTag(transactionId),
+        reason: OCPP16StopTransactionReason.UNLOCK_COMMAND,
+      });
       if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
         return Constants.OCPP_RESPONSE_UNLOCKED;
       }
       return Constants.OCPP_RESPONSE_UNLOCK_FAILED;
     }
-    await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
-      OCPP16RequestCommand.STATUS_NOTIFICATION,
-      {
-        connectorId,
-        status: OCPP16ChargePointStatus.AVAILABLE,
-        errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
-      }
-    );
+    await this.chargingStation.ocppRequestService.requestHandler<
+      OCPP16StatusNotificationRequest,
+      OCPP16StatusNotificationResponse
+    >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+      connectorId,
+      status: OCPP16ChargePointStatus.AVAILABLE,
+      errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+    });
     this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
     return Constants.OCPP_RESPONSE_UNLOCKED;
   }
@@ -265,7 +274,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     const configurationKey: OCPPConfigurationKey[] = [];
     const unknownKey: string[] = [];
     if (Utils.isEmptyArray(commandPayload.key)) {
-      for (const configuration of this.chargingStation.configuration.configurationKey) {
+      for (const configuration of this.chargingStation.ocppConfiguration.configurationKey) {
         if (Utils.isUndefined(configuration.visible)) {
           configuration.visible = true;
         }
@@ -370,6 +379,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private handleRequestSetChargingProfile(
     commandPayload: SetChargingProfileRequest
   ): SetChargingProfileResponse {
+    if (
+      !OCPP16ServiceUtils.checkFeatureProfile(
+        this.chargingStation,
+        OCPP16SupportedFeatureProfiles.SmartCharging,
+        OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE
+      )
+    ) {
+      return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED;
+    }
     if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) {
       logger.error(
         `${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
@@ -398,7 +416,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       commandPayload.csChargingProfiles
     );
     logger.debug(
-      `${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`,
+      `${this.chargingStation.logPrefix()} Charging profile(s) set on connector id ${
+        commandPayload.connectorId
+      }, dump their stack: %j`,
       this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles
     );
     return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
@@ -407,6 +427,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private handleRequestClearChargingProfile(
     commandPayload: ClearChargingProfileRequest
   ): ClearChargingProfileResponse {
+    if (
+      !OCPP16ServiceUtils.checkFeatureProfile(
+        this.chargingStation,
+        OCPP16SupportedFeatureProfiles.SmartCharging,
+        OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE
+      )
+    ) {
+      return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
+    }
     const connectorStatus = this.chargingStation.getConnectorStatus(commandPayload.connectorId);
     if (!connectorStatus) {
       logger.error(
@@ -419,7 +448,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     if (commandPayload.connectorId && !Utils.isEmptyArray(connectorStatus.chargingProfiles)) {
       connectorStatus.chargingProfiles = [];
       logger.debug(
-        `${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`,
+        `${this.chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${
+          commandPayload.connectorId
+        }, dump their stack: %j`,
         connectorStatus.chargingProfiles
       );
       return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
@@ -458,7 +489,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               if (clearCurrentCP) {
                 connectorStatus.chargingProfiles[index] = {} as OCPP16ChargingProfile;
                 logger.debug(
-                  `${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`,
+                  `${this.chargingStation.logPrefix()} Matching charging profile(s) cleared on connector id ${
+                    commandPayload.connectorId
+                  }, dump their stack: %j`,
                   connectorStatus.chargingProfiles
                 );
                 clearedCP = true;
@@ -495,14 +528,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         }
         this.chargingStation.getConnectorStatus(id).availability = commandPayload.type;
         if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
-          await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
-            OCPP16RequestCommand.STATUS_NOTIFICATION,
-            {
-              connectorId: id,
-              status: chargePointStatus,
-              errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
-            }
-          );
+          await this.chargingStation.ocppRequestService.requestHandler<
+            OCPP16StatusNotificationRequest,
+            OCPP16StatusNotificationResponse
+          >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+            connectorId: id,
+            status: chargePointStatus,
+            errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+          });
           this.chargingStation.getConnectorStatus(id).status = chargePointStatus;
         }
       }
@@ -520,10 +553,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
       }
       this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
-      await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
-        OCPP16RequestCommand.STATUS_NOTIFICATION,
-        { connectorId, status: chargePointStatus, errorCode: OCPP16ChargePointErrorCode.NO_ERROR }
-      );
+      await this.chargingStation.ocppRequestService.requestHandler<
+        OCPP16StatusNotificationRequest,
+        OCPP16StatusNotificationResponse
+      >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+        connectorId,
+        status: chargePointStatus,
+        errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+      });
       this.chargingStation.getConnectorStatus(connectorId).status = chargePointStatus;
       return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
     }
@@ -536,14 +573,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     const transactionConnectorId = commandPayload.connectorId;
     const connectorStatus = this.chargingStation.getConnectorStatus(transactionConnectorId);
     if (transactionConnectorId) {
-      await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
-        OCPP16RequestCommand.STATUS_NOTIFICATION,
-        {
-          connectorId: transactionConnectorId,
-          status: OCPP16ChargePointStatus.PREPARING,
-          errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
-        }
-      );
+      await this.chargingStation.ocppRequestService.requestHandler<
+        OCPP16StatusNotificationRequest,
+        OCPP16StatusNotificationResponse
+      >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+        connectorId: transactionConnectorId,
+        status: OCPP16ChargePointStatus.PREPARING,
+        errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+      });
       connectorStatus.status = OCPP16ChargePointStatus.PREPARING;
       if (this.chargingStation.isChargingStationAvailable() && connectorStatus) {
         // Check if authorized
@@ -560,12 +597,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           } else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
             connectorStatus.authorizeIdTag = commandPayload.idTag;
             const authorizeResponse: OCPP16AuthorizeResponse =
-              await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16AuthorizeResponse>(
-                OCPP16RequestCommand.AUTHORIZE,
-                {
-                  idTag: commandPayload.idTag,
-                }
-              );
+              await this.chargingStation.ocppRequestService.requestHandler<
+                OCPP16AuthorizeRequest,
+                OCPP16AuthorizeResponse
+              >(OCPP16RequestCommand.AUTHORIZE, {
+                idTag: commandPayload.idTag,
+              });
             if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
               authorized = true;
             }
@@ -585,13 +622,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               connectorStatus.transactionRemoteStarted = true;
               if (
                 (
-                  await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StartTransactionResponse>(
-                    OCPP16RequestCommand.START_TRANSACTION,
-                    {
-                      connectorId: transactionConnectorId,
-                      idTag: commandPayload.idTag,
-                    }
-                  )
+                  await this.chargingStation.ocppRequestService.requestHandler<
+                    OCPP16StartTransactionRequest,
+                    OCPP16StartTransactionResponse
+                  >(OCPP16RequestCommand.START_TRANSACTION, {
+                    connectorId: transactionConnectorId,
+                    idTag: commandPayload.idTag,
+                  })
                 ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
               ) {
                 logger.debug(
@@ -630,13 +667,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           connectorStatus.transactionRemoteStarted = true;
           if (
             (
-              await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StartTransactionResponse>(
-                OCPP16RequestCommand.START_TRANSACTION,
-                {
-                  connectorId: transactionConnectorId,
-                  idTag: commandPayload.idTag,
-                }
-              )
+              await this.chargingStation.ocppRequestService.requestHandler<
+                OCPP16StartTransactionRequest,
+                OCPP16StartTransactionResponse
+              >(OCPP16RequestCommand.START_TRANSACTION, {
+                connectorId: transactionConnectorId,
+                idTag: commandPayload.idTag,
+              })
             ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
           ) {
             logger.debug(
@@ -676,14 +713,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       this.chargingStation.getConnectorStatus(connectorId).status !==
       OCPP16ChargePointStatus.AVAILABLE
     ) {
-      await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
-        OCPP16RequestCommand.STATUS_NOTIFICATION,
-        {
-          connectorId,
-          status: OCPP16ChargePointStatus.AVAILABLE,
-          errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
-        }
-      );
+      await this.chargingStation.ocppRequestService.requestHandler<
+        OCPP16StatusNotificationRequest,
+        OCPP16StatusNotificationResponse
+      >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+        connectorId,
+        status: OCPP16ChargePointStatus.AVAILABLE,
+        errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+      });
       this.chargingStation.getConnectorStatus(connectorId).status =
         OCPP16ChargePointStatus.AVAILABLE;
     }
@@ -708,7 +745,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
       this.chargingStation.setChargingProfile(connectorId, cp);
       logger.debug(
-        `${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction, dump their stack: %j`,
+        `${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}, dump their stack: %j`,
         this.chargingStation.getConnectorStatus(connectorId).chargingProfiles
       );
       return true;
@@ -733,14 +770,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         connectorId > 0 &&
         this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
       ) {
-        await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
-          OCPP16RequestCommand.STATUS_NOTIFICATION,
-          {
-            connectorId,
-            status: OCPP16ChargePointStatus.FINISHING,
-            errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
-          }
-        );
+        await this.chargingStation.ocppRequestService.requestHandler<
+          OCPP16StatusNotificationRequest,
+          OCPP16StatusNotificationResponse
+        >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+          connectorId,
+          status: OCPP16ChargePointStatus.FINISHING,
+          errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+        });
         this.chargingStation.getConnectorStatus(connectorId).status =
           OCPP16ChargePointStatus.FINISHING;
         if (
@@ -754,24 +791,24 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
             connectorId,
             this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
           );
-          await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
-            OCPP16RequestCommand.METER_VALUES,
-            {
-              connectorId,
-              transactionId,
-              meterValue: transactionEndMeterValue,
-            }
-          );
-        }
-        await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StopTransactionResponse>(
-          OCPP16RequestCommand.STOP_TRANSACTION,
-          {
+          await this.chargingStation.ocppRequestService.requestHandler<
+            OCPP16MeterValuesRequest,
+            OCPP16MeterValuesResponse
+          >(OCPP16RequestCommand.METER_VALUES, {
+            connectorId,
             transactionId,
-            meterStop:
-              this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
-            idTag: this.chargingStation.getTransactionIdTag(transactionId),
-          }
-        );
+            meterValue: transactionEndMeterValue,
+          });
+        }
+        await this.chargingStation.ocppRequestService.requestHandler<
+          OCPP16StopTransactionRequest,
+          OCPP16StopTransactionResponse
+        >(OCPP16RequestCommand.STOP_TRANSACTION, {
+          transactionId,
+          meterStop:
+            this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+          idTag: this.chargingStation.getTransactionIdTag(transactionId),
+        });
         return Constants.OCPP_RESPONSE_ACCEPTED;
       }
     }
@@ -786,6 +823,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private async handleRequestGetDiagnostics(
     commandPayload: GetDiagnosticsRequest
   ): Promise<GetDiagnosticsResponse> {
+    if (
+      !OCPP16ServiceUtils.checkFeatureProfile(
+        this.chargingStation,
+        OCPP16SupportedFeatureProfiles.FirmwareManagement,
+        OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
+      )
+    ) {
+      return Constants.OCPP_RESPONSE_EMPTY;
+    }
     logger.debug(
       this.chargingStation.logPrefix() +
         ' ' +
@@ -820,24 +866,24 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
                 info.bytes / 1024
               } bytes transferred from diagnostics archive ${info.name}`
             );
-            await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
-              OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
-              {
-                status: OCPP16DiagnosticsStatus.Uploading,
-              }
-            );
+            await this.chargingStation.ocppRequestService.requestHandler<
+              DiagnosticsStatusNotificationRequest,
+              DiagnosticsStatusNotificationResponse
+            >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+              status: OCPP16DiagnosticsStatus.Uploading,
+            });
           });
           uploadResponse = await ftpClient.uploadFrom(
             path.join(path.resolve(__dirname, '../../../../'), diagnosticsArchive),
             uri.pathname + diagnosticsArchive
           );
           if (uploadResponse.code === 226) {
-            await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
-              OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
-              {
-                status: OCPP16DiagnosticsStatus.Uploaded,
-              }
-            );
+            await this.chargingStation.ocppRequestService.requestHandler<
+              DiagnosticsStatusNotificationRequest,
+              DiagnosticsStatusNotificationResponse
+            >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+              status: OCPP16DiagnosticsStatus.Uploaded,
+            });
             if (ftpClient) {
               ftpClient.close();
             }
@@ -859,12 +905,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
         );
       } catch (error) {
-        await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
-          OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
-          {
-            status: OCPP16DiagnosticsStatus.UploadFailed,
-          }
-        );
+        await this.chargingStation.ocppRequestService.requestHandler<
+          DiagnosticsStatusNotificationRequest,
+          DiagnosticsStatusNotificationResponse
+        >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+          status: OCPP16DiagnosticsStatus.UploadFailed,
+        });
         if (ftpClient) {
           ftpClient.close();
         }
@@ -880,12 +926,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           uri.protocol
         } to transfer the diagnostic logs archive`
       );
-      await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
-        OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
-        {
-          status: OCPP16DiagnosticsStatus.UploadFailed,
-        }
-      );
+      await this.chargingStation.ocppRequestService.requestHandler<
+        DiagnosticsStatusNotificationRequest,
+        DiagnosticsStatusNotificationResponse
+      >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+        status: OCPP16DiagnosticsStatus.UploadFailed,
+      });
       return Constants.OCPP_RESPONSE_EMPTY;
     }
   }
@@ -893,12 +939,30 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private handleRequestTriggerMessage(
     commandPayload: OCPP16TriggerMessageRequest
   ): OCPP16TriggerMessageResponse {
+    if (
+      !OCPP16ServiceUtils.checkFeatureProfile(
+        this.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(
+        `${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:
           setTimeout(() => {
             this.chargingStation.ocppRequestService
-              .sendMessageHandler<OCPP16BootNotificationResponse>(
+              .requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
                 OCPP16RequestCommand.BOOT_NOTIFICATION,
                 {
                   chargePointModel:
@@ -919,6 +983,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
                 },
                 { skipBufferingOnError: true, triggerMessage: true }
               )
+              .then((value) => {
+                this.chargingStation.bootNotificationResponse = value;
+              })
               .catch(() => {
                 /* This is intentional */
               });
@@ -927,14 +994,61 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         case MessageTrigger.Heartbeat:
           setTimeout(() => {
             this.chargingStation.ocppRequestService
-              .sendMessageHandler<OCPP16HeartbeatResponse>(OCPP16RequestCommand.HEARTBEAT, null, {
-                triggerMessage: true,
-              })
+              .requestHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
+                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) {
+              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;
       }