mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-27 20:48:36 +00:00
Merge branch 'gskjold:master' into extend_power_info
This commit is contained in:
@@ -517,6 +517,7 @@ bool AmsConfiguration::getEnergyAccountingConfig(EnergyAccountingConfig& config)
|
||||
}
|
||||
|
||||
bool AmsConfiguration::setEnergyAccountingConfig(EnergyAccountingConfig& config) {
|
||||
if(config.hours > 5) config.hours = 5;
|
||||
EnergyAccountingConfig existing;
|
||||
if(getEnergyAccountingConfig(existing)) {
|
||||
for(int i = 0; i < 9; i++) {
|
||||
|
||||
@@ -1051,7 +1051,7 @@ void WiFi_connect() {
|
||||
}
|
||||
#endif
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setSleep(WIFI_PS_MIN_MODEM);
|
||||
WiFi.setSleep(WIFI_PS_MAX_MODEM);
|
||||
#if defined(ESP32)
|
||||
if(wifi.power >= 195)
|
||||
WiFi.setTxPower(WIFI_POWER_19_5dBm);
|
||||
|
||||
@@ -237,11 +237,12 @@ float EnergyAccounting::getMonthMax() {
|
||||
uint32_t maxHour = 0.0;
|
||||
bool included[5] = { false, false, false, false, false };
|
||||
|
||||
while(count < config->hours) {
|
||||
while(count < config->hours && count <= 5) {
|
||||
uint8_t maxIdx = 0;
|
||||
uint16_t maxVal = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(included[i]) continue;
|
||||
if(data.peaks[i].day == 0) continue;
|
||||
if(data.peaks[i].value > maxVal) {
|
||||
maxVal = data.peaks[i].value;
|
||||
maxIdx = i;
|
||||
@@ -253,9 +254,7 @@ float EnergyAccounting::getMonthMax() {
|
||||
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(!included[i]) continue;
|
||||
if(data.peaks[i].day > 0) {
|
||||
maxHour += data.peaks[i].value;
|
||||
}
|
||||
maxHour += data.peaks[i].value;
|
||||
}
|
||||
return maxHour > 0 ? maxHour / count / 100.0 : 0.0;
|
||||
}
|
||||
@@ -266,7 +265,7 @@ float EnergyAccounting::getPeak(uint8_t num) {
|
||||
uint8_t count = 0;
|
||||
bool included[5] = { false, false, false, false, false };
|
||||
|
||||
while(count < config->hours) {
|
||||
while(count < config->hours && count <= 5) {
|
||||
uint8_t maxIdx = 0;
|
||||
uint16_t maxVal = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
@@ -341,7 +340,7 @@ bool EnergyAccounting::load() {
|
||||
this->data.peaks[b].day = b;
|
||||
memcpy(&this->data.peaks[b].value, buf+i, 2);
|
||||
b++;
|
||||
if(b >= config->hours) break;
|
||||
if(b >= config->hours || b >= 5) break;
|
||||
}
|
||||
ret = true;
|
||||
} else if(buf[0] == 1) {
|
||||
|
||||
@@ -64,9 +64,11 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState, En
|
||||
}
|
||||
|
||||
String peaks = "";
|
||||
for(uint8_t i = 1; i <= ea->getConfig()->hours; i++) {
|
||||
uint8_t peakCount = ea->getConfig()->hours;
|
||||
if(peakCount > 5) peakCount = 5;
|
||||
for(uint8_t i = 1; i <= peakCount; i++) {
|
||||
if(!peaks.isEmpty()) peaks += ",";
|
||||
peaks += String(ea->getPeak(i));
|
||||
peaks += String(ea->getPeak(i), 2);
|
||||
}
|
||||
snprintf_P(json, BufferSize, REALTIME_JSON,
|
||||
ea->getMonthMax(),
|
||||
@@ -246,6 +248,8 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw, EntsoeApi* eapi, Energ
|
||||
#endif
|
||||
String haUrl = "http://" + haUID + ".local/";
|
||||
// Could this be necessary? haUID.replace("-", "_");
|
||||
uint8_t peakCount = ea->getConfig()->hours;
|
||||
if(peakCount > 5) peakCount = 5;
|
||||
|
||||
uint8_t peaks = 0;
|
||||
for(int i=0;i<HA_SENSOR_COUNT;i++) {
|
||||
@@ -261,7 +265,7 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw, EntsoeApi* eapi, Energ
|
||||
uom = String(eapi->getCurrency());
|
||||
}
|
||||
if(strncmp(sensor.path, "peaks[", 6) == 0) {
|
||||
if(peaks >= ea->getConfig()->hours) continue;
|
||||
if(peaks >= peakCount) continue;
|
||||
peaks++;
|
||||
}
|
||||
snprintf_P(json, BufferSize, HADISCOVER_JSON,
|
||||
|
||||
Reference in New Issue
Block a user