messageId: string,
messagePayload: JsonType | OCPPError,
messageType: MessageType,
- commandName?: RequestCommand | IncomingRequestCommand,
+ commandName: RequestCommand | IncomingRequestCommand,
params: RequestParams = {
skipBufferingOnError: false,
triggerMessage: false,
// Send a message through wsConnection
return Utils.promiseWithTimeout(
new Promise((resolve, reject) => {
+ if (chargingStation.getEnableStatistics() === true) {
+ chargingStation.performanceStatistics?.addRequestStatistic(commandName, messageType);
+ }
const messageToSend = this.buildMessageToSend(
chargingStation,
messageId,
responseCallback,
errorCallback
);
- if (chargingStation.getEnableStatistics() === true) {
- chargingStation.performanceStatistics.addRequestStatistic(commandName, messageType);
- }
let sendError = false;
// Check if wsConnection opened
- if (chargingStation.isWebSocketConnectionOpened() === true) {
- const beginId = PerformanceStatistics.beginMeasure(commandName as string);
+ const wsOpened = chargingStation.isWebSocketConnectionOpened() === true;
+ if (wsOpened) {
+ const beginId = PerformanceStatistics.beginMeasure(commandName);
try {
- chargingStation.wsConnection.send(messageToSend);
+ chargingStation.wsConnection?.send(messageToSend);
logger.debug(
`${chargingStation.logPrefix()} >> Command '${commandName}' sent ${OCPPServiceUtils.getMessageTypeString(
messageType
);
sendError = true;
}
- PerformanceStatistics.endMeasure(commandName as string, beginId);
+ PerformanceStatistics.endMeasure(commandName, beginId);
}
- const wsClosedOrErrored =
- chargingStation.isWebSocketConnectionOpened() === false || sendError === true;
+ const wsClosedOrErrored = !wsOpened || sendError === true;
if (wsClosedOrErrored && params.skipBufferingOnError === false) {
// Buffer
chargingStation.bufferMessage(messageToSend);
*/
function responseCallback(payload: JsonType, requestPayload: JsonType): void {
if (chargingStation.getEnableStatistics() === true) {
- chargingStation.performanceStatistics.addRequestStatistic(
+ chargingStation.performanceStatistics?.addRequestStatistic(
commandName,
MessageType.CALL_RESULT_MESSAGE
);
*/
function errorCallback(error: OCPPError, requestStatistic = true): void {
if (requestStatistic === true && chargingStation.getEnableStatistics() === true) {
- chargingStation.performanceStatistics.addRequestStatistic(
+ chargingStation.performanceStatistics?.addRequestStatistic(
commandName,
MessageType.CALL_ERROR_MESSAGE
);
messageId: string,
messagePayload: JsonType | OCPPError,
messageType: MessageType,
- commandName?: RequestCommand | IncomingRequestCommand,
- responseCallback?: ResponseCallback,
- errorCallback?: ErrorCallback
+ commandName: RequestCommand | IncomingRequestCommand,
+ responseCallback: ResponseCallback,
+ errorCallback: ErrorCallback
): string {
let messageToSend: string;
// Type of message