Skip to content

Commit 89581f0

Browse files
author
Serhiy-Krasovskyy
committed
Small correction of mqtt data publication. Improved input data processing.
1 parent 643a852 commit 89581f0

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class Constants {
2121
public static ApmDefaultEnvironment = 'development';
2222
public static ProductionEnvironment = 'production';
2323
public static MaxVoltage = 400;
24+
public static MaxAmperage = 40;
2425
public static SerialDataTimeout = 20000; // 20 seconds
2526
public static CacheOneDay = Intervals.OneDay;
2627
}

src/modules/collect-data/collect-data.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ export class CollectDataService {
341341
);
342342
return;
343343
}
344+
if (sensorData.amperage > Constants.MaxAmperage) {
345+
this.logger.error(
346+
`[${CollectDataService.name}].${this.processSensorData.name} => ` +
347+
`Amperage is too high: ${sensorData.amperage}A`,
348+
);
349+
return;
350+
}
344351
this.sensorsDataSubject.next(sensorData);
345352
await this.dataService.processVoltageAmperageData(sensorData);
346353
// await this.dataService.processVoltageData(sensorData);

src/modules/mqtt/mqtt-client.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ export class MqttClientService {
6060
Current: Math.round(sensorsData.amperage * 10) / 10,
6161
Voltage: Math.round(sensorsData.voltage),
6262
Power:
63-
Math.round(((sensorsData.voltage * sensorsData.amperage) / 1000) * 100) / 100,
63+
Math.round(
64+
((sensorsData.voltage *
65+
sensorsData.amperage *
66+
this.config.powerCoefficient) /
67+
1000) *
68+
100,
69+
) / 100,
6470
};
6571
this.mqttConnectionService.publish('tele/tasmota/STATE', JSON.stringify(data), options);
6672
}

0 commit comments

Comments
 (0)