mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-02-27 01:10:31 +00:00
Pulse meter
This commit is contained in:
@@ -57,6 +57,8 @@ public:
|
||||
bool isDayHappy();
|
||||
bool isMonthHappy();
|
||||
|
||||
double getEstimatedImportCounter();
|
||||
|
||||
private:
|
||||
Timezone* tz;
|
||||
DayDataPoints day = {
|
||||
|
||||
@@ -553,3 +553,17 @@ bool AmsDataStorage::isMonthHappy() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
double AmsDataStorage::getEstimatedImportCounter() {
|
||||
if(day.lastMeterReadTime == 0) return 0;
|
||||
|
||||
time_t now = time(nullptr);
|
||||
double hours = (now - day.lastMeterReadTime) / 3600.0;
|
||||
uint64_t total = 0;
|
||||
for(uint8_t i = 0; i < 24; i++) {
|
||||
total += getHourImport(i);
|
||||
}
|
||||
double perHour = total / 24.0;
|
||||
debugger->printf_P(PSTR("now: %lu, hours: %.4f, total: %lu, per hour: %.4f, %.4f\n"), now, hours, total, perHour, perHour * hours);
|
||||
return (day.activeImport + (perHour * hours)) / 1000.0;
|
||||
}
|
||||
@@ -38,7 +38,7 @@
|
||||
"phase" : "Phase power",
|
||||
"pf" : "Power factor",
|
||||
"tariffpeak" : "Tariff peaks",
|
||||
"realtime" : "Real time plot",
|
||||
"realtime" : "Real-time plot",
|
||||
"price" : "Future energy price",
|
||||
"day" : "Energy use last 24 hours",
|
||||
"month" : "Energy use last {0} days",
|
||||
@@ -52,7 +52,7 @@
|
||||
"total_out" : "Total out"
|
||||
},
|
||||
"realtime" : {
|
||||
"title" : "Real time calculations",
|
||||
"title" : "Real-time calculations",
|
||||
"consumption" : "Consumption",
|
||||
"cost" : "Cost",
|
||||
"last_month" : "Last month",
|
||||
@@ -235,9 +235,9 @@
|
||||
"h" : "Per phase",
|
||||
"f" : "Power factor",
|
||||
"r" : "Reactive",
|
||||
"c" : "Realtime",
|
||||
"c" : "Real-time",
|
||||
"t" : "Peaks",
|
||||
"l" : "Realtime plot",
|
||||
"l" : "Real-time plot",
|
||||
"p" : "Price",
|
||||
"d" : "Day plot",
|
||||
"m" : "Month plot",
|
||||
|
||||
@@ -1195,6 +1195,13 @@ bool readHanPort() {
|
||||
if(pulseMc != NULL) {
|
||||
pulseMc->onPulse(pulses);
|
||||
pulses = 0;
|
||||
if(meterState.getListType() < 3) {
|
||||
time_t now = time(nullptr);
|
||||
if(now > FirmwareVersion::BuildEpoch) {
|
||||
ImpulseAmsData init = ImpulseAmsData(ds.getEstimatedImportCounter());
|
||||
meterState.apply(init);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!mc->loop()) {
|
||||
meterState.setLastError(mc->getLastError());
|
||||
|
||||
@@ -14,3 +14,8 @@ ImpulseAmsData::ImpulseAmsData(AmsData& state, uint16_t pulsePerKwh, uint8_t pul
|
||||
lastUpdateMillis = state.getLastUpdateMillis();
|
||||
}
|
||||
}
|
||||
|
||||
ImpulseAmsData::ImpulseAmsData(double activeImportCounter) {
|
||||
this->activeImportCounter = activeImportCounter;
|
||||
this->listType = 3;
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
class ImpulseAmsData : public AmsData {
|
||||
public:
|
||||
ImpulseAmsData(AmsData &state, uint16_t pulsePerKwh, uint8_t pulses);
|
||||
ImpulseAmsData(double activeImportCounter);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -48,10 +48,10 @@ void PulseMeterCommunicator::setupGpio() {
|
||||
if(meterConfig.rxPin != NOT_A_PIN) {
|
||||
pinMode(meterConfig.rxPin, meterConfig.rxPinPullup ? INPUT_PULLUP : INPUT);
|
||||
}
|
||||
if(meterConfig.txPin != NOT_A_PIN) {
|
||||
pinMode(meterConfig.txPin, OUTPUT);
|
||||
digitalWrite(meterConfig.txPin, HIGH);
|
||||
}
|
||||
// Export counter?
|
||||
// if(meterConfig.txPin != NOT_A_PIN) {
|
||||
// pinMode(meterConfig.txPin, meterConfig.rxPinPullup ? INPUT_PULLUP : INPUT);
|
||||
// }
|
||||
}
|
||||
|
||||
void PulseMeterCommunicator::onPulse(uint8_t pulses) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
class PulseMeterCommunicator : public MeterCommunicator {
|
||||
public:
|
||||
PulseMeterCommunicator(RemoteDebug* debugger);
|
||||
void configure(MeterConfig&, Timezone*);
|
||||
void configure(MeterConfig& config, Timezone* tz);
|
||||
bool loop();
|
||||
AmsData* getData(AmsData& meterState);
|
||||
int getLastError();
|
||||
|
||||
Reference in New Issue
Block a user