From 625b0fd5a433f3f9a65a03633ca9ebbd01c5e875 Mon Sep 17 00:00:00 2001 From: Calin Crecea Date: Wed, 13 Apr 2022 18:18:29 +0200 Subject: [PATCH] log raw socket messages --- src/charging-station/ChargingStation.ts | 3 +++ src/charging-station/ocpp/OCPPRequestService.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 1d18e5b6..d1a94e75 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -69,6 +69,7 @@ import { SampledValueTemplate } from '../types/MeasurandPerPhaseSampledValueTemp import { SupervisionUrlDistribution } from '../types/ConfigurationData'; import { URL } from 'url'; import Utils from '../utils/Utils'; +import chalk from 'chalk'; import crypto from 'crypto'; import fs from 'fs'; import logger from '../utils/Logger'; @@ -1468,6 +1469,8 @@ export default class ChargingStation { let errMsg: string; try { const request = JSON.parse(data.toString()) as IncomingRequest; + const requestAsString = JSON.stringify(request); + console.log(chalk`{yellow << Received message = ${requestAsString}}`); if (Utils.isIterable(request)) { // Parse the message [messageType, messageId, commandName, commandPayload, errorDetails] = request; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 89766371..9dd0e7bf 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -16,6 +16,7 @@ import OCPPError from '../../exception/OCPPError'; import type OCPPResponseService from './OCPPResponseService'; import PerformanceStatistics from '../../performance/PerformanceStatistics'; import Utils from '../../utils/Utils'; +import chalk from 'chalk'; import logger from '../../utils/Logger'; export default abstract class OCPPRequestService { @@ -151,6 +152,7 @@ export default abstract class OCPPRequestService { if (this.chargingStation.isWebSocketConnectionOpened()) { // Yes: Send Message const beginId = PerformanceStatistics.beginMeasure(commandName); + console.log(chalk`{blue >> Sending message = ${messageToSend}}`); // FIXME: Handle sending error this.chargingStation.wsConnection.send(messageToSend); PerformanceStatistics.endMeasure(commandName, beginId); -- 2.34.1