mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-12 21:44:21 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc09ab5cc9 | ||
|
|
6e3a6f71e2 |
@@ -240,6 +240,9 @@ bool AmsConfiguration::getMeterConfig(MeterConfig& config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AmsConfiguration::setMeterConfig(MeterConfig& config) {
|
bool AmsConfiguration::setMeterConfig(MeterConfig& config) {
|
||||||
|
if(config.bufferSize < 1) config.bufferSize = 1;
|
||||||
|
if(config.bufferSize > 64) config.bufferSize = 64;
|
||||||
|
|
||||||
MeterConfig existing;
|
MeterConfig existing;
|
||||||
if(getMeterConfig(existing)) {
|
if(getMeterConfig(existing)) {
|
||||||
meterChanged |= config.baud != existing.baud;
|
meterChanged |= config.baud != existing.baud;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
statusTopic = F("homeassistant/status");
|
statusTopic = F("homeassistant/status");
|
||||||
discoveryTopic = F("homeassistant/sensor/");
|
discoveryTopic = F("homeassistant/sensor/");
|
||||||
}
|
}
|
||||||
strcpy(this->mqttConfig.subscribeTopic, statusTopic.c_str());
|
// strcpy(this->mqttConfig.subscribeTopic, statusTopic.c_str());
|
||||||
};
|
};
|
||||||
|
|
||||||
bool publish(AmsData* data, AmsData* previousState, EnergyAccounting* ea, EntsoeApi* eapi);
|
bool publish(AmsData* data, AmsData* previousState, EnergyAccounting* ea, EntsoeApi* eapi);
|
||||||
@@ -94,7 +94,7 @@ private:
|
|||||||
bool publishList4(AmsData* data, EnergyAccounting* ea);
|
bool publishList4(AmsData* data, EnergyAccounting* ea);
|
||||||
String getMeterModel(AmsData* data);
|
String getMeterModel(AmsData* data);
|
||||||
bool publishRealtime(AmsData* data, EnergyAccounting* ea, EntsoeApi* eapi);
|
bool publishRealtime(AmsData* data, EnergyAccounting* ea, EntsoeApi* eapi);
|
||||||
void publishSensor(const HomeAssistantSensor& sensor);
|
void publishSensor(const HomeAssistantSensor sensor);
|
||||||
void publishList1Sensors();
|
void publishList1Sensors();
|
||||||
void publishList1ExportSensors();
|
void publishList1ExportSensors();
|
||||||
void publishList2Sensors();
|
void publishList2Sensors();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ struct HomeAssistantSensor {
|
|||||||
const char* name;
|
const char* name;
|
||||||
const char* topic;
|
const char* topic;
|
||||||
const char* path;
|
const char* path;
|
||||||
const uint16_t ttl;
|
uint16_t ttl;
|
||||||
const char* uom;
|
const char* uom;
|
||||||
const char* devcl;
|
const char* devcl;
|
||||||
const char* stacl;
|
const char* stacl;
|
||||||
|
|||||||
@@ -23,24 +23,24 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState, En
|
|||||||
if(time(nullptr) < FirmwareVersion::BuildEpoch)
|
if(time(nullptr) < FirmwareVersion::BuildEpoch)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(data->getListType() >= 3) { // publish energy counts
|
// if(data->getListType() >= 3) { // publish energy counts
|
||||||
publishList3(data, ea);
|
// publishList3(data, ea);
|
||||||
loop();
|
// loop();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(data->getListType() == 1) { // publish power counts
|
// if(data->getListType() == 1) { // publish power counts
|
||||||
publishList1(data, ea);
|
// publishList1(data, ea);
|
||||||
} else if(data->getListType() <= 3) { // publish power counts and volts/amps
|
// } else if(data->getListType() <= 3) { // publish power counts and volts/amps
|
||||||
publishList2(data, ea);
|
// publishList2(data, ea);
|
||||||
} else if(data->getListType() == 4) { // publish power counts and volts/amps/phase power and PF
|
// } else if(data->getListType() == 4) { // publish power counts and volts/amps/phase power and PF
|
||||||
publishList4(data, ea);
|
// publishList4(data, ea);
|
||||||
}
|
// }
|
||||||
loop();
|
loop();
|
||||||
|
|
||||||
if(ea->isInitialized()) {
|
// if(ea->isInitialized()) {
|
||||||
publishRealtime(data, ea, eapi);
|
// publishRealtime(data, ea, eapi);
|
||||||
loop();
|
// loop();
|
||||||
}
|
// }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +319,7 @@ bool HomeAssistantMqttHandler::publishPrices(EntsoeApi* eapi) {
|
|||||||
bool HomeAssistantMqttHandler::publishSystem(HwTools* hw, EntsoeApi* eapi, EnergyAccounting* ea) {
|
bool HomeAssistantMqttHandler::publishSystem(HwTools* hw, EntsoeApi* eapi, EnergyAccounting* ea) {
|
||||||
if(topic.isEmpty() || !mqtt.connected())
|
if(topic.isEmpty() || !mqtt.connected())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
publishSystemSensors();
|
publishSystemSensors();
|
||||||
if(hw->getTemperature() > -50) publishTemperatureSensor(0, "");
|
if(hw->getTemperature() > -50) publishTemperatureSensor(0, "");
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw, EntsoeApi* eapi, Energ
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomeAssistantMqttHandler::publishSensor(const HomeAssistantSensor& sensor) {
|
void HomeAssistantMqttHandler::publishSensor(const HomeAssistantSensor sensor) {
|
||||||
String uid = String(sensor.path);
|
String uid = String(sensor.path);
|
||||||
uid.replace(".", "");
|
uid.replace(".", "");
|
||||||
uid.replace("[", "");
|
uid.replace("[", "");
|
||||||
|
|||||||
20
lib/SvelteUi/app/dist/index.js
vendored
20
lib/SvelteUi/app/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -33,10 +33,10 @@
|
|||||||
if(i2e) {
|
if(i2e) {
|
||||||
xTicks.push({ label: 'L2' });
|
xTicks.push({ label: 'L2' });
|
||||||
points.push({
|
points.push({
|
||||||
label: 'N/A',
|
label: 'Not available',
|
||||||
labelAngle: 90,
|
labelAngle: -90,
|
||||||
title: 'The value is not reported by your meter',
|
title: 'L2 current is not reported by your meter',
|
||||||
value: 0,
|
value: 0,
|
||||||
color: '#7c3aedcc'
|
color: '#7c3aedcc'
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -82,9 +82,9 @@
|
|||||||
<text
|
<text
|
||||||
width="{barWidth - 4}"
|
width="{barWidth - 4}"
|
||||||
dominant-baseline="middle"
|
dominant-baseline="middle"
|
||||||
text-anchor="{barWidth < vertSwitch ? 'left' : 'middle'}"
|
text-anchor="{barWidth < vertSwitch || point.labelAngle ? 'left' : 'middle'}"
|
||||||
fill="{yScale(point.value) > yScale(0)-labelOffset ? point.color : 'white'}"
|
fill="{yScale(point.value) > yScale(0)-labelOffset ? point.color : 'white'}"
|
||||||
transform="translate({xScale(i) + barWidth/2} {yScale(point.value) > yScale(0) - labelOffset ? yScale(point.value) - labelOffset : yScale(point.value) + 10}) rotate({barWidth < vertSwitch ? 90 : 0})"
|
transform="translate({xScale(i) + barWidth/2} {yScale(point.value) > yScale(0) - labelOffset ? yScale(point.value) - labelOffset : yScale(point.value) + 10}) rotate({point.labelAngle ? point.labelAngle : barWidth < vertSwitch ? 90 : 0})"
|
||||||
|
|
||||||
>{point.label}</text>
|
>{point.label}</text>
|
||||||
{#if point.title}
|
{#if point.title}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if uiVisibility(sysinfo.ui.a, data.i1 > 0.01 || data.i2 > 0.01 || data.i3 > 0.01)}
|
{#if uiVisibility(sysinfo.ui.a, data.i1 > 0.01 || data.i2 > 0.01 || data.i3 > 0.01)}
|
||||||
<div class="cnt">
|
<div class="cnt">
|
||||||
<AmpPlot u1={data.u1} u2={data.u2} u3={data.u3} i1={data.i1} i2={data.i2} i2e={data.i2e} i3={data.i3} max={data.mf ? data.mf : 32}/>
|
<AmpPlot u1={data.u1} u2={data.u2} u3={data.u3} i1={data.i1} i2={data.i2} i2e="true" i3={data.i3} max={data.mf ? data.mf : 32}/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if uiVisibility(sysinfo.ui.r, data.ri > 0 || data.re > 0 || data.ric > 0 || data.rec > 0)}
|
{#if uiVisibility(sysinfo.ui.r, data.ri > 0 || data.re > 0 || data.ric > 0 || data.rec > 0)}
|
||||||
|
|||||||
@@ -788,8 +788,8 @@ void handleSystem(unsigned long now) {
|
|||||||
|
|
||||||
// After one hour, adjust buffer size to match the largest payload
|
// After one hour, adjust buffer size to match the largest payload
|
||||||
if(!maxDetectPayloadDetectDone && now > 3600000) {
|
if(!maxDetectPayloadDetectDone && now > 3600000) {
|
||||||
if(maxDetectedPayloadSize * 1.5 > meterConfig.bufferSize * 64) {
|
if(maxDetectedPayloadSize * 1.25 > meterConfig.bufferSize * 64) {
|
||||||
int bufferSize = min((double) 64, ceil((maxDetectedPayloadSize * 1.5) / 64));
|
int bufferSize = min((double) 64, ceil((maxDetectedPayloadSize * 1.25) / 64));
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
if(gpioConfig.hanPin != 3 && gpioConfig.hanPin != 113) {
|
if(gpioConfig.hanPin != 3 && gpioConfig.hanPin != 113) {
|
||||||
bufferSize = min(bufferSize, 2);
|
bufferSize = min(bufferSize, 2);
|
||||||
@@ -1010,6 +1010,7 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(meterConfig.bufferSize < 1) meterConfig.bufferSize = 1;
|
if(meterConfig.bufferSize < 1) meterConfig.bufferSize = 1;
|
||||||
|
if(meterConfig.bufferSize > 64) meterConfig.bufferSize = 64;
|
||||||
|
|
||||||
if(hwSerial != NULL) {
|
if(hwSerial != NULL) {
|
||||||
debugD_P(PSTR("Hardware serial"));
|
debugD_P(PSTR("Hardware serial"));
|
||||||
@@ -1035,6 +1036,7 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
|||||||
}
|
}
|
||||||
if(meterConfig.bufferSize < 4) meterConfig.bufferSize = 4; // 64 bytes (1) is default for software serial, 256 bytes (4) for hardware
|
if(meterConfig.bufferSize < 4) meterConfig.bufferSize = 4; // 64 bytes (1) is default for software serial, 256 bytes (4) for hardware
|
||||||
|
|
||||||
|
debugD_P(PSTR("Using serial buffer size %d"), 64 * meterConfig.bufferSize);
|
||||||
hwSerial->setRxBufferSize(64 * meterConfig.bufferSize);
|
hwSerial->setRxBufferSize(64 * meterConfig.bufferSize);
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
hwSerial->begin(baud, serialConfig, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, invert);
|
hwSerial->begin(baud, serialConfig, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, invert);
|
||||||
@@ -1107,10 +1109,12 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bufferSize = meterConfig.bufferSize;
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
if(meterConfig.bufferSize > 2) meterConfig.bufferSize = 2;
|
if(bufferSize > 2) bufferSize = 2;
|
||||||
#endif
|
#endif
|
||||||
swSerial->begin(baud, serialConfig, pin, -1, invert, meterConfig.bufferSize * 64);
|
debugD_P(PSTR("Using serial buffer size %d"), 64 * bufferSize);
|
||||||
|
swSerial->begin(baud, serialConfig, pin, -1, invert, bufferSize * 64);
|
||||||
hanSerial = swSerial;
|
hanSerial = swSerial;
|
||||||
|
|
||||||
Serial.end();
|
Serial.end();
|
||||||
@@ -1121,7 +1125,7 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
|||||||
if(hanBuffer != NULL) {
|
if(hanBuffer != NULL) {
|
||||||
free(hanBuffer);
|
free(hanBuffer);
|
||||||
}
|
}
|
||||||
hanBufferSize = 64 * meterConfig.bufferSize * 2;
|
hanBufferSize = max(64 * meterConfig.bufferSize * 2, 1280);
|
||||||
hanBuffer = (uint8_t*) malloc(hanBufferSize);
|
hanBuffer = (uint8_t*) malloc(hanBufferSize);
|
||||||
|
|
||||||
// The library automatically sets the pullup in Serial.begin()
|
// The library automatically sets the pullup in Serial.begin()
|
||||||
@@ -1258,6 +1262,10 @@ bool readHanPort() {
|
|||||||
hanSerial->readBytes(hanBuffer, hanBufferSize);
|
hanSerial->readBytes(hanBuffer, hanBufferSize);
|
||||||
len = 0;
|
len = 0;
|
||||||
debugI_P(PSTR("Buffer overflow, resetting"));
|
debugI_P(PSTR("Buffer overflow, resetting"));
|
||||||
|
#if defined(ESP32)
|
||||||
|
meterConfig.bufferSize += 4;
|
||||||
|
config.setMeterConfig(meterConfig);
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
hanBuffer[len++] = hanSerial->read();
|
hanBuffer[len++] = hanSerial->read();
|
||||||
@@ -1848,7 +1856,7 @@ int16_t unwrapData(uint8_t *buf, DataParserContext &context) {
|
|||||||
return DATA_PARSE_UNKNOWN_DATA;
|
return DATA_PARSE_UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long lastMqttRetry = -10000;
|
unsigned long lastMqttRetry = -20000;
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
if(millis() - lastMqttRetry < (config.isMqttChanged() ? 5000 : 30000)) {
|
if(millis() - lastMqttRetry < (config.isMqttChanged() ? 5000 : 30000)) {
|
||||||
yield();
|
yield();
|
||||||
|
|||||||
Reference in New Issue
Block a user