class AutomaticTransactionGenerator {
constructor(chargingStation) {
this._chargingStation = chargingStation;
- this._timeToStop = false;
+ this._timeToStop = true;
this._performanceObserver = new PerformanceObserver((list) => {
const entry = list.getEntries()[0];
this._chargingStation._statistics.logPerformance(entry, 'AutomaticTransactionGenerator');
});
}
+ get timeToStop() {
+ return this._timeToStop;
+ }
+
_basicFormatLog(connectorId = null) {
if (connectorId) {
- return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG on connector #' + connectorId);
+ return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG on connector #' + connectorId + ':');
}
return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG:');
}
async start() {
this._timeToStop = false;
- if (this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours &&
- this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours > 0) {
- logger.info(this._basicFormatLog() + ' ATG will stop in ' + Utils.secondstoHHMMSS(this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours * 3600));
+ if (this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours &&
+ this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours > 0) {
+ logger.info(this._basicFormatLog() + ' ATG will stop in ' + Utils.secondstoHHMMSS(this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600));
setTimeout(() => {
this.stop();
- }, this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours * 3600 * 1000);
+ }, this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600 * 1000);
}
for (const connector in this._chargingStation._connectors) {
if (connector > 0) {
async startConnector(connectorId) {
do {
- const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransaction, this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDelayBetweenTwoTransaction) * 1000;
+ const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransaction,
+ this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDelayBetweenTwoTransaction) * 1000;
logger.info(this._basicFormatLog(connectorId) + ' wait for ' + Utils.secondstoHHMMSS(wait / 1000));
await Utils.sleep(wait);
if (this._timeToStop) break;
await Utils.sleep(2000);
} else {
// Wait until end of transaction
- const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration, this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
+ const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration,
+ this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
logger.info(this._basicFormatLog(connectorId) + ' transaction ' + this._chargingStation._connectors[connectorId].transactionId + ' will stop in ' + Utils.secondstoHHMMSS(wait / 1000));
await Utils.sleep(wait);
// Stop transaction
this._messageQueue = [];
this._isSocketRestart = false;
+
+ this._authorizedTags = this._getAuthorizedTags();
}
_initialize() {
this._bootNotificationMessage = {
chargePointModel: this._stationInfo.chargePointModel,
chargePointVendor: this._stationInfo.chargePointVendor,
+ // chargePointSerialNumber: this._stationInfo.chargePointSerialNumber,
+ firmwareVersion: this._stationInfo.firmwareVersion ? this._stationInfo.firmwareVersion : '',
};
this._configuration = this._getConfiguration();
- this._authorizedTags = this._getAuthorizedTags();
this._supervisionUrl = this._getSupervisionURL();
this._statistics = new Statistics(this._stationInfo.name);
this._performanceObserver = new PerformanceObserver((list) => {
}
async start() {
+ this._url = this._supervisionUrl + '/' + this._stationInfo.name;
+ this._wsConnection = new WebSocket(this._url, 'ocpp1.6');
logger.info(this._basicFormatLog() + ' Will communicate with ' + this._supervisionUrl);
// Monitor authorization file
this._startAuthorizationFileMonitoring();
// Monitor station template file
this._startStationTemplateFileMonitoring();
- this._url = this._supervisionUrl + '/' + this._stationInfo.name;
- this._wsConnection = new WebSocket(this._url, 'ocpp1.6');
// Handle Socket incoming messages
this._wsConnection.on('message', this.onMessage.bind(this));
// Handle Socket error
clearInterval(this._heartbeatSetInterval);
this._heartbeatSetInterval = null;
}
- // Stop the ATG
- if (this._stationInfo.AutomaticTransactionGenerator.enable && this._automaticTransactionGeneration &&
- !this._automaticTransactionGeneration._timeToStop) {
+ // Stop the ATG if needed
+ if (Utils.convertToBoolean(this._stationInfo.AutomaticTransactionGenerator.enable) &&
+ Utils.convertToBoolean(this._stationInfo.AutomaticTransactionGenerator.stopOnConnectionFailure) &&
+ this._automaticTransactionGeneration &&
+ !this._automaticTransactionGeneration.timeToStop) {
this._automaticTransactionGeneration.stop();
}
if (this._autoReconnectTimeout !== 0 &&
let lastConnector;
for (lastConnector in connectorsConfig) {
// add connector 0, OCPP specification violation that for example KEBA have
- if (Utils.convertToInt(lastConnector) === 0 && this._stationInfo.useConnectorId0) {
+ if (Utils.convertToInt(lastConnector) === 0 && Utils.convertToBoolean(this._stationInfo.useConnectorId0)) {
this._connectors[lastConnector] = connectorsConfig[lastConnector];
}
}
}
// generate all connectors
for (let index = 1; index <= maxConnectors; index++) {
- const randConnectorID = this._stationInfo.randomConnectors ? Utils.getRandomInt(maxConnectors, 1) : index;
+ const randConnectorID = Utils.convertToBoolean(this._stationInfo.randomConnectors) ? Utils.getRandomInt(lastConnector, 1) : index;
this._connectors[index] = connectorsConfig[randConnectorID];
}
}
}
}
- if (this._stationInfo.AutomaticTransactionGenerator.enable) {
+ if (Utils.convertToBoolean(this._stationInfo.AutomaticTransactionGenerator.enable)) {
if (!this._automaticTransactionGeneration) {
this._automaticTransactionGeneration = new AutomaticTransactionGenerator(this);
}
- this._automaticTransactionGeneration.start();
+ if (this._automaticTransactionGeneration.timeToStop) {
+ this._automaticTransactionGeneration.start();
+ }
}
this._statistics.start();
}
}
handleResponseStartTransaction(payload, requestPayload) {
- // Reset connector transaction related attributes
+ // Set connector transaction related attributes
this._connectors[requestPayload.connectorId].transactionStarted = false;
this._connectors[requestPayload.connectorId].idTag = requestPayload.idTag;
}
}
+ handleResponseStopTransaction(payload, requestPayload) {
+ if (payload.idTagInfo && payload.idTagInfo.status) {
+ logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: ' + payload.idTagInfo.status );
+ } else {
+ logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: Unknown');
+ }
+ }
+
handleResponseStatusNotification(payload) {
logger.debug(this._basicFormatLog() + ' Status notification response received: %j', payload);
}
await this.sendMessage(messageId, result, Constants.OCPP_JSON_CALL_RESULT_MESSAGE);
}
- async handleGetConfiguration() {
+ async handleGetConfiguration(commandPayload) {
return this._configuration;
}
if (sampledValueLcl.sampledValue[index].measurand && sampledValueLcl.sampledValue[index].measurand === 'SoC') {
sampledValueLcl.sampledValue[index].value = Math.floor(Math.random() * 100) + 1;
if (sampledValueLcl.sampledValue[index].value > 100) {
- logger.info(self._basicFormatLog() + ' Meter type: ' +
+ logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
(sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'default') +
', value: ' + sampledValueLcl.sampledValue[index].value);
}
connector.lastConsumptionValue = 0;
}
consumption = Math.round(connector.lastConsumptionValue * 3600 / interval);
- logger.info(self._basicFormatLog() + ' ConnectorID ' + connectorID + ' transaction ' + connector.transactionId + ' value ' + connector.lastConsumptionValue);
+ logger.info(self._basicFormatLog() + ' MeterValues: 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() + ' Meter type: ' +
+ logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
(sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'default') +
', value: ' + sampledValueLcl.sampledValue[index].value + '/' + (self._stationInfo.maxPower * 3600 / interval));
}
};
await self.sendMessage(Utils.generateUUID(), payload, Constants.OCPP_JSON_CALL_MESSAGE, 'MeterValues');
} catch (error) {
- logger.error(self._basicFormatLog() + ' Send meter values error: ' + error);
+ logger.error(self._basicFormatLog() + ' Send MeterValues error: ' + error);
}
}
async startMeterValues(connectorID, interval, self) {
if (!this._connectors[connectorID].transactionStarted) {
- logger.debug(`${self._basicFormatLog()} Trying to start meter values on connector ID ${connectorID} with no transaction started`);
+ logger.debug(`${self._basicFormatLog()} Trying to start MeterValues on connector ID ${connectorID} with no transaction started`);
} else if (this._connectors[connectorID].transactionStarted && !this._connectors[connectorID].transactionId) {
- logger.debug(`${self._basicFormatLog()} Trying to start meter values on connector ID ${connectorID} with no transaction id`);
+ logger.debug(`${self._basicFormatLog()} Trying to start MeterValues on connector ID ${connectorID} with no transaction id`);
}
this._connectors[connectorID].transactionInterval = setInterval(async () => {
const sendMeterValues = performance.timerify(this.sendMeterValues);