Improve debug logging.
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 19 Oct 2020 09:38:08 +0000 (11:38 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 19 Oct 2020 09:38:08 +0000 (11:38 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/assets/station-templates/abb.station-template.json
src/assets/station-templates/evlink.station-template.json
src/assets/station-templates/keba.station-template.json
src/assets/station-templates/schneider-imredd.station-template.json
src/assets/station-templates/schneider.station-template.json
src/assets/station-templates/siemens.mougins69.station-template.json
src/assets/station-templates/virtual-simple-atg.station-template.json
src/assets/station-templates/virtual-simple.station-template.json
src/assets/station-templates/virtual.station-template.json
src/charging-station/ChargingStation.js

index 6faab07844774f38a1cc56cc30bf53f78a7ab41c..a24f514958d5ca521a585c062b57ffcfa6550f3f 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "VendorKey",
index 89cbc5cb78e22608dddc0e8b8c25d805cbd4d3f3..1efb99f6879e91c45d00ffb246d2bff3f3d49cad 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index 3422aec220517add7d6b9347abba43832a7711da..4cadd5c6894cf9a632cbe7e9a98903f47b763230 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index 6851275664bf23a249c573002fb5460b9eaae149..1660e4a4cdf4b5584f90881d2c90af8db834418c 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index 4ec5e790eb78c1f330d8446a4170768a6c0cf1de..54a71498728075fc14985ba439d4adf0aea9be5a 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index a9d7de494c2265ea74bd4dd82a155f3126f8d246..206526adc84eb5f5dd994a1484d5c92a3d1349c5 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index fdeeefc524a96c3208f3f69c9a42ad12221afd43..a17f6dd51ae57f608f7a401e9d6aefec689d49c1 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index d197d127f9eecda862a4144d312a2dcabcfb3a9c..3e2898bd256298ed03cd070f1efcbd203045fc56 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index c7cbf74d638720fb8125c62d9f65245177128544..62bf86c7037eafedb363291e4b3927edf8132564 100644 (file)
       {
         "key": "LocalAuthListEnabled",
         "readonly": false,
-        "value": false
+        "value": "false"
       },
       {
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
-        "value": false
+        "value": "false"
       }
     ]
   },
index d4eb7f6d5a4787d4bcc1e1f0f34b0e3e287e7e01..30330463a774397bfc16fdd1dda6d360659b147a 100644 (file)
@@ -376,7 +376,7 @@ class ChargingStation {
         // Error Message
         case Constants.OCPP_JSON_CALL_ERROR_MESSAGE:
           // Build Message
-          this._statistics.addMessage(`Error ${command.code ? command.code : Constants.OCPP_ERROR_GENERIC_ERROR} on ${commandName}`);
+          this._statistics.addMessage(`Error ${command.code ? command.code : Constants.OCPP_ERROR_GENERIC_ERROR} on ${commandName || ''}`);
           messageToSend = JSON.stringify([messageType, messageId, command.code ? command.code : Constants.OCPP_ERROR_GENERIC_ERROR, command.message ? command.message : '', command.details ? command.details : {}]);
           break;
       }
@@ -413,7 +413,7 @@ class ChargingStation {
 
       // Function that will receive the request's rejection
       function rejectCallback(reason) {
-        self._statistics.addMessage(`Error ${command.code ? command.code : Constants.OCPP_ERROR_GENERIC_ERROR} on ${commandName}`, true);
+        self._statistics.addMessage(`Error ${command.code ? command.code : Constants.OCPP_ERROR_GENERIC_ERROR} on ${commandName || ''}`, true);
         // Build Exception
         // eslint-disable-next-line no-empty-function
         self._requests[messageId] = [() => { }, () => { }, '']; // Properly format the request
@@ -505,29 +505,31 @@ class ChargingStation {
       logger.debug(this._basicFormatLog() + ' Try to start a transaction on an already used connector ' + requestPayload.connectorId + ' by transaction ' + this._connectors[requestPayload.connectorId].transactionId);
     }
 
-    if (payload.idTagInfo && payload.idTagInfo.status === 'Accepted') {
-      for (const connector in this._connectors) {
-        if (Utils.convertToInt(connector) === Utils.convertToInt(requestPayload.connectorId)) {
-          this._connectors[connector].transactionStarted = true;
-          this._connectors[connector].transactionId = payload.transactionId;
-          this._connectors[connector].idTag = requestPayload.idTag;
-          this._connectors[connector].lastConsumptionValue = 0;
-          this._connectors[connector].lastSoC = 0;
-          this.sendStatusNotification(requestPayload.connectorId, 'Charging');
-          logger.info(this._basicFormatLog() + ' Transaction ' + this._connectors[connector].transactionId + ' STARTED on ' + this._stationInfo.name + '#' + requestPayload.connectorId + ' for idTag ' + requestPayload.idTag);
-          const configuredMeterValueSampleInterval = this._getConfigurationKey('MeterValueSampleInterval');
-          this.startMeterValues(requestPayload.connectorId,
-            configuredMeterValueSampleInterval ? configuredMeterValueSampleInterval.value * 1000 : 60000,
-            this);
-        }
+    let transactionConnectorId;
+    for (const connector in this._connectors) {
+      if (Utils.convertToInt(connector) === Utils.convertToInt(requestPayload.connectorId)) {
+        transactionConnectorId = connector;
+        break;
       }
+    }
+    if (!transactionConnectorId) {
+      logger.error(this._basicFormatLog() + ' Try to start a transaction on a non existing connector Id ' + requestPayload.connectorId);
+      return;
+    }
+    if (payload.idTagInfo && payload.idTagInfo.status === 'Accepted') {
+      this._connectors[transactionConnectorId].transactionStarted = true;
+      this._connectors[transactionConnectorId].transactionId = payload.transactionId;
+      this._connectors[transactionConnectorId].idTag = requestPayload.idTag;
+      this._connectors[transactionConnectorId].lastConsumptionValue = 0;
+      this._connectors[transactionConnectorId].lastSoC = 0;
+      this.sendStatusNotification(requestPayload.connectorId, 'Charging');
+      logger.info(this._basicFormatLog() + ' Transaction ' + this._connectors[transactionConnectorId].transactionId + ' STARTED on ' + this._stationInfo.name + '#' + requestPayload.connectorId + ' for idTag ' + requestPayload.idTag);
+      const configuredMeterValueSampleInterval = this._getConfigurationKey('MeterValueSampleInterval');
+      this.startMeterValues(requestPayload.connectorId,
+        configuredMeterValueSampleInterval ? configuredMeterValueSampleInterval.value * 1000 : 60000);
     } else {
       logger.error(this._basicFormatLog() + ' Starting transaction id ' + payload.transactionId + ' REJECTED with status ' + payload.idTagInfo.status + ', idTag ' + requestPayload.idTag);
-      for (const connector in this._connectors) {
-        if (Utils.convertToInt(connector) === Utils.convertToInt(requestPayload.connectorId)) {
-          this._resetTransactionOnConnector(connector);
-        }
-      }
+      this._resetTransactionOnConnector(transactionConnectorId);
       this.sendStatusNotification(requestPayload.connectorId, 'Available');
     }
   }
@@ -541,7 +543,8 @@ class ChargingStation {
       }
     }
     if (!transactionConnectorId) {
-      logger.debug(this._basicFormatLog() + ' Try to stop a non existing transaction ' + requestPayload.transactionId);
+      logger.error(this._basicFormatLog() + ' Try to stop a non existing transaction ' + requestPayload.transactionId);
+      return;
     }
     if (payload.idTagInfo && payload.idTagInfo.status === 'Accepted') {
       this.sendStatusNotification(transactionConnectorId, 'Available');
@@ -757,7 +760,7 @@ class ChargingStation {
   }
 
   // eslint-disable-next-line class-methods-use-this
-  async sendMeterValues(connectorID, interval, self) {
+  async sendMeterValues(connectorID, interval, self, debug = false) {
     try {
       const sampledValueLcl = {
         timestamp: new Date().toISOString(),
@@ -769,30 +772,25 @@ class ChargingStation {
         sampledValueLcl.sampledValue = [meterValuesClone];
       }
       for (let index = 0; index < sampledValueLcl.sampledValue.length; index++) {
+        const connector = self._connectors[connectorID];
         if (sampledValueLcl.sampledValue[index].measurand && sampledValueLcl.sampledValue[index].measurand === 'SoC') {
           sampledValueLcl.sampledValue[index].value = Utils.getRandomInt(100);
-          if (sampledValueLcl.sampledValue[index].value > 100) {
-            logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
-              sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register' +
-              ', value: ' + sampledValueLcl.sampledValue[index].value);
+          if (sampledValueLcl.sampledValue[index].value > 100 || debug) {
+            logger.error(`${self._basicFormatLog()} MeterValues measurand ${sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register'}: connectorID ${connectorID}, transaction ${connector.transactionId}, value: ${sampledValueLcl.sampledValue[index].value}`);
           }
         } else {
           // Persist previous value in connector
-          const connector = self._connectors[connectorID];
-          let consumption;
-          consumption = Utils.getRandomInt(self._stationInfo.maxPower / 3600000 * interval);
+          const consumption = Utils.getRandomInt(self._stationInfo.maxPower / 3600000 * interval);
           if (connector && connector.lastConsumptionValue >= 0) {
             connector.lastConsumptionValue += consumption;
           } else {
             connector.lastConsumptionValue = 0;
           }
-          consumption = Math.round(connector.lastConsumptionValue * 3600 / interval);
-          logger.info(self._basicFormatLog() + ' MeterValues: connectorID ' + connectorID + ', transaction ' + connector.transactionId + ', value ' + connector.lastConsumptionValue);
+          const maxConsumption = self._stationInfo.maxPower * 3600 / interval;
+          logger.info(`${self._basicFormatLog()} MeterValues measurand ${sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register'}: connectorID ${connectorID}, transaction ${connector.transactionId}, value ${connector.lastConsumptionValue}`);
           sampledValueLcl.sampledValue[index].value = connector.lastConsumptionValue;
-          if (sampledValueLcl.sampledValue[index].value > (self._stationInfo.maxPower * 3600 / interval) || sampledValueLcl.sampledValue[index].value < 500) {
-            logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
-              sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register' +
-              ', value: ' + sampledValueLcl.sampledValue[index].value + '/' + (self._stationInfo.maxPower * 3600 / interval));
+          if (sampledValueLcl.sampledValue[index].value > maxConsumption || debug) {
+            logger.error(`${self._basicFormatLog()} MeterValues measurand ${sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register'}: connectorID ${connectorID}, transaction ${connector.transactionId}, value: ${sampledValueLcl.sampledValue[index].value}/${maxConsumption}`);
           }
         }
       }
@@ -808,18 +806,20 @@ class ChargingStation {
     }
   }
 
-  async startMeterValues(connectorID, interval, self) {
+  async startMeterValues(connectorID, interval) {
     if (!this._connectors[connectorID].transactionStarted) {
-      logger.debug(`${self._basicFormatLog()} Trying to start MeterValues on connector ID ${connectorID} with no transaction started`);
+      logger.error(`${this._basicFormatLog()} Trying to start MeterValues on connector ID ${connectorID} with no transaction started`);
+      return;
     } else if (this._connectors[connectorID].transactionStarted && !this._connectors[connectorID].transactionId) {
-      logger.debug(`${self._basicFormatLog()} Trying to start MeterValues on connector ID ${connectorID} with no transaction id`);
+      logger.error(`${this._basicFormatLog()} Trying to start MeterValues on connector ID ${connectorID} with no transaction id`);
+      return;
     }
     this._connectors[connectorID].transactionSetInterval = setInterval(async () => {
       const sendMeterValues = performance.timerify(this.sendMeterValues);
       this._performanceObserver.observe({
         entryTypes: ['function'],
       });
-      await sendMeterValues(connectorID, interval, self);
+      await sendMeterValues(connectorID, interval, this);
     }, interval);
   }