Performance improvements & watchdog prep

This commit is contained in:
Edward Firmo
2024-03-31 21:26:48 +02:00
parent 0e089b292b
commit 2393834ae8
2 changed files with 186 additions and 34 deletions

View File

@@ -1047,12 +1047,6 @@ globals:
restore_value: true
initial_value: '65535'
##### Versioning #####
- id: version_blueprint
type: char[10]
restore_value: false
initial_value: ''
##### Is uploading TFT #####
- id: is_uploading_tft
type: bool
@@ -1850,6 +1844,17 @@ text_sensor:
}
##### Versioning #####
- id: version_blueprint
name: Version Blueprint
platform: template
entity_category: diagnostic
icon: mdi:tag-text-outline
internal: false
update_interval: never
on_value:
- lambda: |-
check_versions->execute();
- id: version_tft
name: Version TFT
platform: nextion
@@ -1905,7 +1910,7 @@ script:
- wait_until:
condition:
- lambda: |-
return (compare_versions("${version}", version_tft->state.c_str()) and compare_versions("${version}", id(version_blueprint)));
return (compare_versions("${version}", version_tft->state.c_str()) and compare_versions("${version}", version_blueprint->state.c_str()));
timeout: 60s
- lambda: |-
if (!id(is_uploading_tft)) {
@@ -1914,8 +1919,8 @@ script:
ESP_LOGD("script.check_versions", " TFT: %s", version_tft->state.c_str());
if (not compare_versions("${version}", version_tft->state.c_str()))
ESP_LOGE("script.check_versions", "TFT version mismatch!");
ESP_LOGD("script.check_versions", " Blueprint: %s", id(version_blueprint));
if (not compare_versions("${version}", id(version_blueprint)))
ESP_LOGD("script.check_versions", " Blueprint: %s", version_blueprint->state.c_str());
if (not compare_versions("${version}", version_blueprint->state.c_str()))
ESP_LOGE("script.check_versions", "Blueprint version mismatch!");
esphome::api::CustomAPIDevice ha_event;
@@ -1925,7 +1930,7 @@ script:
{"type", "version"},
{"tft", version_tft->state.c_str()},
{"esphome", "${version}"},
{"blueprint", id(version_blueprint)}
{"blueprint", version_blueprint->state.c_str()}
});
}
@@ -1997,7 +2002,7 @@ script:
if (id(is_uploading_tft)) global_settings->stop();
if (blueprint_status->state <= 99) goto_page->execute("boot");
// Blueprint version
copyStringToCharArray(id(version_blueprint), blueprint_version);
version_blueprint->publish_state(blueprint_version.c_str());
disp1->set_component_text("boot.bluep_version", blueprint_version.c_str());
check_versions->execute();
@@ -2826,6 +2831,7 @@ script:
update_alarm_icon->stop();
update_climate_icon->stop();
update_tft_info->stop();
watchdog->stop();
###### Timers ######
- id: timer_reset_all # Global timer reset - Triggered with a touch on the screen
@@ -3040,4 +3046,116 @@ script:
condition:
- lambda: return (!isnan(display_charset->state) and !isnan(display_mode->state) and !(version_tft->state.empty()));
timeout: 10s
- id: watchdog
mode: restart
then:
- lambda: |-
static const char *const TAG = "script.watchdog";
ESP_LOGV(TAG, "Starting");
if (id(is_uploading_tft)) {
ESP_LOGW(TAG, "TFT upload in progress");
} else {
// report Wi-Fi status
bool wifi_connected = wifi_component->is_connected();
if (wifi_connected) {
float rssi = wifi_rssi->state;
const char *rssi_status = "Unknown"; // Use const char* to avoid dynamic memory allocation
if (rssi > -50) rssi_status = "Excellent";
else if (rssi > -60) rssi_status = "Good";
else if (rssi > -70) rssi_status = "Fair";
else if (rssi > -80) rssi_status = "Weak";
else rssi_status = "Poor";
if (rssi > -70) ESP_LOGI(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status, rssi);
else if (rssi > -80) ESP_LOGW(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status, rssi);
else ESP_LOGE(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status, rssi);
}
else {
ESP_LOGW(TAG, "Wi-Fi: DISCONNECTED");
ESP_LOGI(TAG, "Retrying Wi-Fi connection");
wifi_component->retry_connect();
}
// report API status
bool api_connected = api_server->is_connected();
if (api_connected) {
ESP_LOGI(TAG, "API: Connected");
} else {
ESP_LOGW(TAG, "API: DISCONNECTED");
blueprint_status->publish_state(0);
if (current_page->state != "blank" and
current_page->state != "boot" and
current_page->state != "home" and
current_page->state != "screensaver" and
current_page->state != "settings" and
current_page->state != "qrcode") {
ESP_LOGI(TAG, "Fallback to page Home");
disp1->goto_page("home");
}
}
if (!wifi_connected or !api_connected) blueprint_status->publish_state(0);
// Report blueprint version
ESP_LOGI(TAG, "Blueprint:");
if (blueprint_status->state > 99) {
ESP_LOGI(TAG, " Version: %s", version_blueprint->state.c_str());
ESP_LOGI(TAG, " Init steps: %i (%0.1f%%)", int(blueprint_status->raw_state), blueprint_status->state);
} else {
ESP_LOGW(TAG, " Init steps: %i (%0.1f%%)", int(blueprint_status->raw_state), blueprint_status->state);
ESP_LOGW(TAG, " State: %s", (wifi_connected and api_connected) ? "Pending" : "DISCONNECTED");
ESP_LOGI(TAG, "Requesting blueprint settings");
esphome::api::CustomAPIDevice ha_event;
ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"device_name", device_name->state.c_str()},
{"type", "boot"},
{"step", "timeout"}
});
}
// Report ESPHome
ESP_LOGI(TAG, "ESPHome:");
ESP_LOGI(TAG, " Version: ${version}");
// Report framework
#ifdef ARDUINO
ESP_LOGI(TAG, " Framework: Arduino");
size_t total_heap_size = ESP.getHeapSize();
size_t free_heap_size = ESP.getFreeHeap();
#elif defined(USE_ESP_IDF)
ESP_LOGI(TAG, " Framework: ESP-IDF");
size_t total_heap_size = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
size_t free_heap_size = esp_get_free_heap_size();
#endif
if (total_heap_size != 0)
ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size,
int(round(((float)free_heap_size / total_heap_size) * 100.0f)));
// Report UART
ESP_LOGI(TAG, "UART:");
ESP_LOGI(TAG, " Baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate());
ESP_LOGI(TAG, " Queue size: %d", tf_uart->available());
// Report Nextion status
nextion_init->publish_state(nextion_init->state and disp1->is_setup());
ESP_LOGI(TAG, "Nextion:");
ESP_LOGI(TAG, " Queue size: %d", disp1->queue_size());
if (disp1->is_setup())
ESP_LOGI(TAG, " Is setup: True");
else {
ESP_LOGW(TAG, " Is setup: False");
ESP_LOGW(TAG, " Is detected: %s", YESNO(disp1->is_detected()));
//exit_reparse->execute();
}
if (nextion_init->state) {
ESP_LOGI(TAG, " Init: True");
} else
ESP_LOGW(TAG, " Init: False");
if (version_tft->state.empty())
ESP_LOGW(TAG, " TFT: UNKNOWN");
else
ESP_LOGI(TAG, " TFT: %s", version_tft->state.c_str());
}
refresh_wifi_icon->execute();
ESP_LOGV(TAG, "Finished");
...