mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-22 09:17:02 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a70bd7511 | ||
|
|
c583c2b44a | ||
|
|
4c28d512a1 | ||
|
|
1775d0abce | ||
|
|
8e65f1fe14 | ||
|
|
c1d1bf6bb5 |
@@ -17,6 +17,7 @@ class AmsMqttHandler {
|
|||||||
public:
|
public:
|
||||||
AmsMqttHandler(MqttConfig& mqttConfig, RemoteDebug* debugger, char* buf) {
|
AmsMqttHandler(MqttConfig& mqttConfig, RemoteDebug* debugger, char* buf) {
|
||||||
this->mqttConfig = mqttConfig;
|
this->mqttConfig = mqttConfig;
|
||||||
|
this->mqttConfigChanged = true;
|
||||||
this->debugger = debugger;
|
this->debugger = debugger;
|
||||||
this->json = buf;
|
this->json = buf;
|
||||||
mqtt.dropOverflow(true);
|
mqtt.dropOverflow(true);
|
||||||
@@ -50,6 +51,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
RemoteDebug* debugger;
|
RemoteDebug* debugger;
|
||||||
MqttConfig mqttConfig;
|
MqttConfig mqttConfig;
|
||||||
|
bool mqttConfigChanged = true;
|
||||||
MQTTClient mqtt = MQTTClient(256);
|
MQTTClient mqtt = MQTTClient(256);
|
||||||
unsigned long lastMqttRetry = -10000;
|
unsigned long lastMqttRetry = -10000;
|
||||||
bool caVerification = true;
|
bool caVerification = true;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ void AmsMqttHandler::setCaVerification(bool caVerification) {
|
|||||||
|
|
||||||
void AmsMqttHandler::setConfig(MqttConfig& mqttConfig) {
|
void AmsMqttHandler::setConfig(MqttConfig& mqttConfig) {
|
||||||
this->mqttConfig = mqttConfig;
|
this->mqttConfig = mqttConfig;
|
||||||
|
this->mqttConfigChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AmsMqttHandler::connect() {
|
bool AmsMqttHandler::connect() {
|
||||||
@@ -19,6 +20,8 @@ bool AmsMqttHandler::connect() {
|
|||||||
lastMqttRetry = millis();
|
lastMqttRetry = millis();
|
||||||
|
|
||||||
time_t epoch = time(nullptr);
|
time_t epoch = time(nullptr);
|
||||||
|
|
||||||
|
WiFiClient *actualClient = NULL;
|
||||||
|
|
||||||
if(mqttConfig.ssl) {
|
if(mqttConfig.ssl) {
|
||||||
if(epoch < FirmwareVersion::BuildEpoch) {
|
if(epoch < FirmwareVersion::BuildEpoch) {
|
||||||
@@ -33,7 +36,9 @@ bool AmsMqttHandler::connect() {
|
|||||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("ESP8266 firmware does not have enough memory...\n"));
|
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("ESP8266 firmware does not have enough memory...\n"));
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mqttConfigChanged) {
|
||||||
if(caVerification && LittleFS.begin()) {
|
if(caVerification && LittleFS.begin()) {
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
@@ -48,8 +53,6 @@ bool AmsMqttHandler::connect() {
|
|||||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("CA accepted\n"));
|
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("CA accepted\n"));
|
||||||
} else {
|
} else {
|
||||||
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf_P(PSTR("CA was rejected\n"));
|
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf_P(PSTR("CA was rejected\n"));
|
||||||
delete mqttSecureClient;
|
|
||||||
mqttSecureClient = NULL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -97,29 +100,21 @@ bool AmsMqttHandler::connect() {
|
|||||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("CA verification disabled\n"));
|
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("CA verification disabled\n"));
|
||||||
mqttSecureClient->setInsecure();
|
mqttSecureClient->setInsecure();
|
||||||
}
|
}
|
||||||
if(mqttClient != NULL) {
|
|
||||||
mqttClient->stop();
|
|
||||||
delete mqttClient;
|
|
||||||
}
|
|
||||||
mqttClient = mqttSecureClient;
|
|
||||||
|
|
||||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("MQTT SSL setup complete (%dkb free heap)\n"), ESP.getFreeHeap());
|
|
||||||
}
|
}
|
||||||
} else if(mqttSecureClient != NULL) {
|
actualClient = mqttSecureClient;
|
||||||
mqttSecureClient->stop();
|
|
||||||
delete mqttSecureClient;
|
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("MQTT SSL setup complete (%dkb free heap)\n"), ESP.getFreeHeap());
|
||||||
mqttSecureClient = NULL;
|
} else {
|
||||||
mqttClient = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mqttClient == NULL) {
|
|
||||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("No SSL, using client without SSL support\n"));
|
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("No SSL, using client without SSL support\n"));
|
||||||
mqttClient = new WiFiClient();
|
if(mqttClient == NULL) {
|
||||||
|
mqttClient = new WiFiClient();
|
||||||
|
}
|
||||||
|
actualClient = mqttClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mqttConfigChanged = false;
|
||||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Connecting to MQTT %s:%d\n"), mqttConfig.host, mqttConfig.port);
|
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Connecting to MQTT %s:%d\n"), mqttConfig.host, mqttConfig.port);
|
||||||
|
mqtt.begin(mqttConfig.host, mqttConfig.port, *actualClient);
|
||||||
mqtt.begin(mqttConfig.host, mqttConfig.port, *mqttClient);
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
if(mqttSecureClient) {
|
if(mqttSecureClient) {
|
||||||
@@ -160,15 +155,6 @@ void AmsMqttHandler::disconnect() {
|
|||||||
mqtt.loop();
|
mqtt.loop();
|
||||||
delay(10);
|
delay(10);
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
if(mqttClient != NULL) {
|
|
||||||
mqttClient->stop();
|
|
||||||
delete mqttClient;
|
|
||||||
mqttClient = NULL;
|
|
||||||
if(mqttSecureClient != NULL) {
|
|
||||||
mqttSecureClient = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lwmqtt_err_t AmsMqttHandler::lastError() {
|
lwmqtt_err_t AmsMqttHandler::lastError() {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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, "");
|
||||||
|
|
||||||
|
|||||||
2
lib/SvelteUi/app/dist/index.js
vendored
2
lib/SvelteUi/app/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -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="true" 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={data.i2e} 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)}
|
||||||
|
|||||||
Reference in New Issue
Block a user