mirror of
https://github.com/arendst/Tasmota.git
synced 2026-07-27 20:05:46 +00:00
Refactor displaymode 4 and up
- Fix MQTT timeout when using DisplayMode 4 and up
This commit is contained in:
@@ -1708,7 +1708,7 @@ const char kSensorUnit[] PROGMEM =
|
||||
D_UNIT_PARTS_PER_MILLION "|" // ppm
|
||||
D_UNIT_HERTZ; // Hz
|
||||
|
||||
void DisplayJsonValue(const char* topic, const char* device, const char* mkey, const char* value) {
|
||||
void DisplayJsonValue(const char* topic, const char* mkey, const char* value) {
|
||||
SHOW_FREE_MEM(PSTR("DisplayJsonValue"));
|
||||
|
||||
char temp[TOPSZ];
|
||||
@@ -1747,12 +1747,26 @@ void DisplayJsonValue(const char* topic, const char* device, const char* mkey, c
|
||||
snprintf_P(source, sizeof(source), PSTR("%s%s%s%s"), (size)?topic:"", (size)?"/":"", mkey, buffer); // pow1/Voltage or Voltage if topic is empty (local sensor or header)
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("%s %s"), source, svalue);
|
||||
|
||||
// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "topic [%s], device [%s], mkey [%s], source [%s], value [%s], quantity_code %d, log_buffer [%s]"),
|
||||
// topic, device, mkey, source, value, quantity_code, buffer);
|
||||
// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "topic [%s], mkey [%s], source [%s], value [%s], quantity_code %d, log_buffer [%s]"),
|
||||
// topic, mkey, source, value, quantity_code, buffer);
|
||||
|
||||
DisplayLogBufferAdd(buffer);
|
||||
}
|
||||
|
||||
void DisplayAnalyzeJsonObject(const char *topic, JsonParserObject Object) {
|
||||
for (auto key : Object) {
|
||||
JsonParserToken value = key.getValue();
|
||||
if (value.isObject()) {
|
||||
DisplayAnalyzeJsonObject(topic, value.getObject());
|
||||
} else {
|
||||
const char* values = value.getStr(nullptr);
|
||||
if (values != nullptr) {
|
||||
DisplayJsonValue(topic, key.getStr(), values); // Sensor 56%
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayAnalyzeJson(char *topic, const char *json) {
|
||||
// //tele/pow2/STATE {"Time":"2017-09-20T11:53:03", "Uptime":10, "Vcc":3.123, "POWER":"ON", "Wifi":{"AP":2, "SSId":"indebuurt2", "RSSI":68, "APMac":"00:22:6B:FE:8E:20"}}
|
||||
// //tele/pow2/ENERGY {"Time":"2017-09-20T11:53:03", "Total":6.522, "Yesterday":0.150, "Today":0.073, "Period":0.5, "Power":12.1, "Factor":0.56, "Voltage":210.1, "Current":0.102}
|
||||
@@ -1777,34 +1791,8 @@ void DisplayAnalyzeJson(char *topic, const char *json) {
|
||||
if (unit) {
|
||||
snprintf_P(disp_pres, sizeof(disp_pres), PSTR("%s"), unit); // hPa or mmHg
|
||||
}
|
||||
for (auto key1 : root) {
|
||||
JsonParserToken value1 = key1.getValue();
|
||||
if (value1.isObject()) {
|
||||
JsonParserObject Object2 = value1.getObject();
|
||||
for (auto key2 : Object2) {
|
||||
JsonParserToken value2 = key2.getValue();
|
||||
if (value2.isObject()) {
|
||||
JsonParserObject Object3 = value2.getObject();
|
||||
for (auto key3 : Object3) {
|
||||
const char* value3 = key3.getValue().getStr(nullptr);
|
||||
if (value3 != nullptr) { // "DHT11":{"Temperature":null,"Humidity":null} - ignore null as it will raise exception 28
|
||||
DisplayJsonValue(topic, key1.getStr(), key3.getStr(), value3); // Sensor 56%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const char* value = value2.getStr(nullptr);
|
||||
if (value != nullptr) {
|
||||
DisplayJsonValue(topic, key1.getStr(), key2.getStr(), value); // Sensor 56%
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const char* value = value1.getStr(nullptr);
|
||||
if (value != nullptr) {
|
||||
DisplayJsonValue(topic, key1.getStr(), key1.getStr(), value); // Topic 56%
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DisplayAnalyzeJsonObject(topic, root);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -297,6 +297,7 @@ void EPD47_PrintLog(void) {
|
||||
for (byte i = 0; i < last_row; i++) {
|
||||
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
|
||||
renderer->println(disp_screen_buffer[i]);
|
||||
delay(0); // Fix MQTT timeout
|
||||
}
|
||||
strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols);
|
||||
DisplayFillScreen(last_row);
|
||||
|
||||
@@ -560,6 +560,7 @@ void UDISP_PrintLog(void) {
|
||||
for (byte i = 0; i < last_row; i++) {
|
||||
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
|
||||
renderer->println(disp_screen_buffer[i]);
|
||||
delay(0); // Fix MQTT timeout
|
||||
}
|
||||
strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols);
|
||||
DisplayFillScreen(last_row);
|
||||
|
||||
Reference in New Issue
Block a user