mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-02-11 02:41:04 +00:00
topic contains all fields, null if not used
This commit is contained in:
@@ -315,6 +315,7 @@ bool longPressActive = false;
|
||||
bool wifiConnected = false;
|
||||
|
||||
unsigned long lastTemperatureRead = 0;
|
||||
unsigned long lastSystemMessage = 0;
|
||||
unsigned long lastErrorBlink = 0;
|
||||
int lastError = 0;
|
||||
|
||||
@@ -473,6 +474,12 @@ void loop() {
|
||||
}
|
||||
|
||||
if(readHanPort() || now - meterState.getLastUpdateMillis() > 30000) {
|
||||
if(now - lastSystemMessage > 15000) {
|
||||
if(mqtt != NULL && mqttHandler != NULL && WiFi.getMode() != WIFI_AP && WiFi.status() == WL_CONNECTED && mqtt->connected() && !topic.isEmpty()) {
|
||||
lastSystemMessage = now;
|
||||
mqttHandler->publishSystem(&hw);
|
||||
}
|
||||
}
|
||||
if(now - lastTemperatureRead > 15000) {
|
||||
unsigned long start = millis();
|
||||
hw.updateTemperatures();
|
||||
|
||||
@@ -17,7 +17,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
snprintf_P(json, sizeof(json), JSON1HA_JSON,
|
||||
data->getActiveImportPower()
|
||||
);
|
||||
return mqtt->publish(topic + "/data1", json);
|
||||
return mqtt->publish(topic + "/power", json);
|
||||
} else if(data->getListType() == 2) {
|
||||
char json[384];
|
||||
snprintf_P(json, sizeof(json), JSON2HA_JSON,
|
||||
@@ -35,7 +35,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
data->getL2Voltage(),
|
||||
data->getL3Voltage()
|
||||
);
|
||||
return mqtt->publish(topic + "/data2", json);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
} else if(data->getListType() == 3) {
|
||||
if(data->getPowerFactor() == 0) {
|
||||
char json[512];
|
||||
@@ -59,7 +59,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
data->getReactiveExportCounter(),
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
return mqtt->publish(topic + "/data3", json);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
} else {
|
||||
char json[768];
|
||||
snprintf_P(json, sizeof(json), JSON3HAPF_JSON,
|
||||
@@ -86,7 +86,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
data->getReactiveExportCounter(),
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
return mqtt->publish(topic + "/data3pf", json);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user