Standardizing logs calls
This commit is contained in:
@@ -53,13 +53,14 @@ esphome:
|
||||
- lambda: !lambda return id(disp1).is_setup();
|
||||
timeout: 20s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "on_boot";
|
||||
if (not id(tf_uart).available() or not id(disp1).is_setup())
|
||||
{
|
||||
ESP_LOGE("on_boot", "No response from Nextion display");
|
||||
ESP_LOGD("on_boot", "Turn off Nextion");
|
||||
ESP_LOGE(TAG, "No response from Nextion display");
|
||||
ESP_LOGD(TAG, "Turn off Nextion");
|
||||
id(screen_power).turn_off();
|
||||
delay(1500);
|
||||
ESP_LOGD("script.power_cycle_display", "Turn on Nextion");
|
||||
ESP_LOGD(TAG, "Turn on Nextion");
|
||||
id(screen_power).turn_on();
|
||||
}
|
||||
|
||||
@@ -1108,6 +1109,8 @@ text_sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "text_sensor.current_page";
|
||||
|
||||
// Reset globals
|
||||
if (x != "climate" and x != "cover" and x != "fan" and x != "light" and x != "media_player" and x != "confirm" and x != "keyb_num") id(entity_id) = "";
|
||||
if (x != "media_player")
|
||||
@@ -1118,14 +1121,14 @@ text_sensor:
|
||||
}
|
||||
|
||||
// Report new page to logs
|
||||
ESP_LOGD("text_sensor.current_page", "New page: %s", x.c_str());
|
||||
if (!id(entity_id).empty()) ESP_LOGD("text_sensor.current_page", "Entity shown: %s", id(entity_id).c_str());
|
||||
ESP_LOGD(TAG, "New page: %s", x.c_str());
|
||||
if (!id(entity_id).empty()) ESP_LOGD(TAG, "Entity shown: %s", id(entity_id).c_str());
|
||||
|
||||
// Reset timers
|
||||
id(timer_reset_all).execute(x.c_str());
|
||||
|
||||
// Report new page to Home Assistant
|
||||
ESP_LOGV("text_sensor.localevent", "Trigger HA event");
|
||||
ESP_LOGV(TAG, "Trigger HA event");
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
@@ -1135,24 +1138,24 @@ text_sensor:
|
||||
});
|
||||
|
||||
// Report new page to add-ons
|
||||
ESP_LOGV("text_sensor.localevent", "Call add-ons scripts for new page");
|
||||
ESP_LOGV(TAG, "Call add-ons scripts for new page");
|
||||
id(addon_climate_set_climate).execute(x == "climate" and id(entity_id) == "embedded_climate");
|
||||
|
||||
// Construct new page
|
||||
ESP_LOGV("text_sensor.localevent", "Construct new page");
|
||||
ESP_LOGV(TAG, "Construct new page");
|
||||
if (x == "home")
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct home page");
|
||||
ESP_LOGV(TAG, "Construct home page");
|
||||
id(update_page_home).execute();
|
||||
}
|
||||
else if (x == "screensaver")
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct screensaver page");
|
||||
ESP_LOGV(TAG, "Construct screensaver page");
|
||||
id(update_page_screensaver).execute();
|
||||
}
|
||||
else if (x == "climate")
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct climate page");
|
||||
ESP_LOGV(TAG, "Construct climate page");
|
||||
id(disp1).set_component_text_printf("climate.button01_icon", "%s", "\uEE8D"); //mdi:calendar-sync
|
||||
id(disp1).set_component_text_printf("climate.button02_icon", "%s", "\uE069"); //mdi:autorenew
|
||||
id(disp1).set_component_text_printf("climate.button03_icon", "%s", "\uE237"); //mdi:fire
|
||||
@@ -1164,7 +1167,7 @@ text_sensor:
|
||||
}
|
||||
else if (x == "cover") // To do: Should be moved to Blueprint
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct cover page");
|
||||
ESP_LOGV(TAG, "Construct cover page");
|
||||
id(disp1).set_component_text_printf("cover.cover_stop", "%s", "\uE666"); //mdi:stop-circle-outline
|
||||
// In the future this will be dynamically contructed based on the device_class
|
||||
id(disp1).set_component_text_printf("cover.cover_open", "%s", "\uF11D"); //mdi:window-shutter-open
|
||||
@@ -1172,7 +1175,7 @@ text_sensor:
|
||||
}
|
||||
else if (x == "fan") // To do: Should be moved to Blueprint
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct fan page");
|
||||
ESP_LOGV(TAG, "Construct fan page");
|
||||
id(disp1).set_component_text_printf("fan.button_on", "%s", "\uE20F"); //mdi:fan
|
||||
id(disp1).set_component_text_printf("fan.button_off", "%s", "\uE81C"); //mdi:fan-off
|
||||
id(disp1).set_component_text_printf("fan.button_up", "%s", "\uF46D"); //mdi:fan-chevron-up
|
||||
@@ -1180,7 +1183,7 @@ text_sensor:
|
||||
}
|
||||
else if (x == "keyb_num")
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct keyb_num page");
|
||||
ESP_LOGV(TAG, "Construct keyb_num page");
|
||||
id(disp1).set_component_text_printf("keyb_num.bview", "%s", "\uE207"); //mdi:eye
|
||||
id(disp1).set_component_text_printf("keyb_num.bclose", "%s", "\uE158"); //mdi:close-circle
|
||||
id(disp1).set_component_text_printf("keyb_num.bclear", "%s", "\uE641"); //mdi:eraser-variant
|
||||
@@ -1208,7 +1211,7 @@ text_sensor:
|
||||
}
|
||||
else if (x == "media_player") // To do: Should be moved to Blueprint
|
||||
{
|
||||
ESP_LOGV("text_sensor.nspanelevent", "Construct media_player page");
|
||||
ESP_LOGV(TAG, "Construct media_player page");
|
||||
id(disp1).set_component_text_printf("bt_on_off", "%s", "\uE424"); //mdi:power
|
||||
id(disp1).set_component_text_printf("bt_prev", "%s", "\uE4AD"); //mdi:skip-previous
|
||||
id(disp1).set_component_text_printf("bt_next", "%s", "\uE4AC"); //mdi:skip-next
|
||||
@@ -1242,7 +1245,8 @@ text_sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGE("text_sensor.nspanelevent", "Starting");
|
||||
static const char *const TAG = "text_sensor.disp1_nspanel_event";
|
||||
ESP_LOGE(TAG, "Starting");
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, x);
|
||||
std::string page = doc["page"];
|
||||
@@ -1250,10 +1254,10 @@ text_sensor:
|
||||
if (not (component == "currentpage" and (page == "screensaver" or page == "home"))) id(timer_reset_all).execute(page.c_str());
|
||||
std::string value = doc["value"];
|
||||
std::string entity = id(entity_id); //doc["entity"];
|
||||
ESP_LOGE("text_sensor.nspanelevent", "page: %s", page.c_str());
|
||||
ESP_LOGE("text_sensor.nspanelevent", "component: %s", component.c_str());
|
||||
ESP_LOGE("text_sensor.nspanelevent", "value: %s", value.c_str());
|
||||
ESP_LOGE("text_sensor.nspanelevent", "entity: %s", entity.c_str());
|
||||
ESP_LOGE(TAG, "page: %s", page.c_str());
|
||||
ESP_LOGE(TAG, "component: %s", component.c_str());
|
||||
ESP_LOGE(TAG, "value: %s", value.c_str());
|
||||
ESP_LOGE(TAG, "entity: %s", entity.c_str());
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
@@ -1279,6 +1283,7 @@ text_sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "text_sensor.localevent";
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, x);
|
||||
std::string page = doc["page"];
|
||||
@@ -1338,7 +1343,7 @@ text_sensor:
|
||||
if (doc.containsKey("display_mode"))
|
||||
{
|
||||
std::string display_mode_str = doc["display_mode"];
|
||||
ESP_LOGV("text_sensor.localevent", "display_mode: %s", display_mode_str.c_str());
|
||||
ESP_LOGV(TAG, "display_mode: %s", display_mode_str.c_str());
|
||||
float display_mode_float = stof(display_mode_str);
|
||||
if (display_mode_float > 0) id(display_mode) = int(display_mode_float);
|
||||
}
|
||||
@@ -2203,6 +2208,7 @@ script:
|
||||
#- lambda: !lambda 'return (id(version_blueprint) == "${version}");'
|
||||
timeout: 60s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.check_versions";
|
||||
auto compareVersions = [](const char* version1, const char* version2) -> bool
|
||||
{
|
||||
int major1 = 0, minor1 = 0;
|
||||
@@ -2213,11 +2219,11 @@ script:
|
||||
|
||||
return (major1 == major2) && (minor1 == minor2);
|
||||
};
|
||||
ESP_LOGD("script.check_versions", "ESPHome version: ${version}");
|
||||
ESP_LOGD("script.check_versions", "TFT version: %s", id(version_tft).c_str());
|
||||
if (not compareVersions("${version}", id(version_tft).c_str())) ESP_LOGE("script.check_versions", "TFT version mismatch!");
|
||||
ESP_LOGD("script.check_versions", "Blueprint version: %s", id(version_blueprint).c_str());
|
||||
if (not compareVersions("${version}", id(version_blueprint).c_str())) ESP_LOGE("script.check_versions", "Blueprint version mismatch!");
|
||||
ESP_LOGD(TAG, "ESPHome version: ${version}");
|
||||
ESP_LOGD(TAG, "TFT version: %s", id(version_tft).c_str());
|
||||
if (not compareVersions("${version}", id(version_tft).c_str())) ESP_LOGE(TAG, "TFT version mismatch!");
|
||||
ESP_LOGD(TAG, "Blueprint version: %s", id(version_blueprint).c_str());
|
||||
if (not compareVersions("${version}", id(version_blueprint).c_str())) ESP_LOGE(TAG, "Blueprint version mismatch!");
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
@@ -2461,21 +2467,22 @@ script:
|
||||
|
||||
auto upload_tft_arduino = [&](const std::string &url, unsigned int update_baud_rate_) -> bool
|
||||
{
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Nextion TFT upload requested");
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "url: %s", url.c_str());
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "baud_rate: %i", update_baud_rate_);
|
||||
static const char *const TAG = "script.upload_tft.upload_tft_arduino";
|
||||
ESP_LOGD(TAG, "Nextion TFT upload requested");
|
||||
ESP_LOGD(TAG, "url: %s", url.c_str());
|
||||
ESP_LOGD(TAG, "baud_rate: %i", update_baud_rate_);
|
||||
|
||||
if (is_updating_) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Currently updating");
|
||||
ESP_LOGD(TAG, "Currently updating");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
if (!network::is_connected()) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Network is not connected");
|
||||
ESP_LOGD(TAG, "Network is not connected");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Setting Nextion protocol reparse mode to passive");
|
||||
ESP_LOGD(TAG, "Setting Nextion protocol reparse mode to passive");
|
||||
id(disp1).set_protocol_reparse_mode(false);
|
||||
|
||||
is_updating_ = true;
|
||||
@@ -2486,18 +2493,18 @@ script:
|
||||
bool begin_status = http.begin(url.c_str());
|
||||
if (!begin_status) {
|
||||
is_updating_ = false;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Connection failed");
|
||||
ESP_LOGD(TAG, "Connection failed");
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
allocator.deallocate(transfer_buffer_, transfer_buffer_size_);
|
||||
return upload_end_(true);
|
||||
} else {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Connected");
|
||||
ESP_LOGD(TAG, "Connected");
|
||||
}
|
||||
|
||||
http.addHeader("Range", "bytes=0-255");
|
||||
const char *header_names[] = {"Content-Range"};
|
||||
http.collectHeaders(header_names, 1);
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Requesting URL: %s", url.c_str());
|
||||
ESP_LOGD(TAG, "Requesting URL: %s", url.c_str());
|
||||
|
||||
http.setReuse(true);
|
||||
// try up to 5 times. DNS sometimes needs a second try or so
|
||||
@@ -2506,7 +2513,7 @@ script:
|
||||
delay(100);
|
||||
|
||||
while (code != 200 && code != 206 && tries <= 5) {
|
||||
ESP_LOGW("script.upload_tft.upload_tft", "HTTP Request failed; URL: %s; Error: %s, retrying (%d/5)", url.c_str(),
|
||||
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s, retrying (%d/5)", url.c_str(),
|
||||
HTTPClient::errorToString(code).c_str(), tries);
|
||||
|
||||
delay(250);
|
||||
@@ -2525,11 +2532,11 @@ script:
|
||||
http.end();
|
||||
|
||||
if (content_length_ < 4096) {
|
||||
ESP_LOGE("script.upload_tft.upload_tft", "Failed to get file size");
|
||||
ESP_LOGE(TAG, "Failed to get file size");
|
||||
return upload_end_(true);
|
||||
}
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Updating Nextion");
|
||||
ESP_LOGD(TAG, "Updating Nextion");
|
||||
// The Nextion will ignore the update command if it is sleeping
|
||||
|
||||
char command[128];
|
||||
@@ -2553,17 +2560,17 @@ script:
|
||||
}
|
||||
|
||||
std::string response;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Waiting for upgrade response");
|
||||
ESP_LOGD(TAG, "Waiting for upgrade response");
|
||||
recv_ret_string_(response, 2000, true); // This can take some time to return
|
||||
|
||||
// The Nextion display will, if it's ready to accept data, send a 0x05 byte.
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Upgrade response is [%s]",
|
||||
ESP_LOGD(TAG, "Upgrade response is [%s]",
|
||||
format_hex_pretty(reinterpret_cast<const uint8_t *>(response.data()), response.size()).c_str());
|
||||
|
||||
if (response.find(0x05) != std::string::npos) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Preparation for tft update done");
|
||||
ESP_LOGD(TAG, "Preparation for tft update done");
|
||||
} else {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Preparation for tft update failed %d \"%s\"", response[0], response.c_str());
|
||||
ESP_LOGD(TAG, "Preparation for tft update failed %d \"%s\"", response[0], response.c_str());
|
||||
return upload_end_(true);
|
||||
}
|
||||
|
||||
@@ -2579,12 +2586,12 @@ script:
|
||||
|
||||
if (transfer_buffer_ == nullptr) {
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Allocating buffer size %d, Heap size is %u", chunk_size, ESP.getFreeHeap());
|
||||
ESP_LOGD(TAG, "Allocating buffer size %d, Heap size is %u", chunk_size, ESP.getFreeHeap());
|
||||
transfer_buffer_ = allocator.allocate(chunk_size);
|
||||
if (transfer_buffer_ == nullptr) { // Try a smaller size
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Could not allocate buffer size: %d trying 4096 instead", chunk_size);
|
||||
ESP_LOGD(TAG, "Could not allocate buffer size: %d trying 4096 instead", chunk_size);
|
||||
chunk_size = 4096;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Allocating %d buffer", chunk_size);
|
||||
ESP_LOGD(TAG, "Allocating %d buffer", chunk_size);
|
||||
transfer_buffer_ = allocator.allocate(chunk_size);
|
||||
|
||||
if (!transfer_buffer_)
|
||||
@@ -2596,21 +2603,21 @@ script:
|
||||
transfer_buffer_size_ = chunk_size;
|
||||
}
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d",
|
||||
ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d",
|
||||
url.c_str(), content_length_, transfer_buffer_size_, ESP.getFreeHeap());
|
||||
|
||||
int result = 0;
|
||||
while (content_length_ > 0) {
|
||||
result = upload_by_chunks_arduino(&http, url, result);
|
||||
if (result < 0) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Error updating Nextion!");
|
||||
ESP_LOGD(TAG, "Error updating Nextion!");
|
||||
return upload_end_(true);
|
||||
}
|
||||
App.feed_wdt();
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Heap Size %d, Bytes left %d", ESP.getFreeHeap(), content_length_);
|
||||
ESP_LOGD(TAG, "Heap Size %d, Bytes left %d", ESP.getFreeHeap(), content_length_);
|
||||
}
|
||||
is_updating_ = false;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Successfully updated Nextion!");
|
||||
ESP_LOGD(TAG, "Successfully updated Nextion!");
|
||||
|
||||
return upload_end_(false);
|
||||
};
|
||||
@@ -2740,21 +2747,21 @@ script:
|
||||
|
||||
auto upload_tft_esp_idf = [&](const std::string &url, unsigned int update_baud_rate_) -> bool
|
||||
{
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Nextion TFT upload requested");
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "url: %s", url.c_str());
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "baud_rate: %i", update_baud_rate_);
|
||||
ESP_LOGD(TAG, "Nextion TFT upload requested");
|
||||
ESP_LOGD(TAG, "url: %s", url.c_str());
|
||||
ESP_LOGD(TAG, "baud_rate: %i", update_baud_rate_);
|
||||
|
||||
if (is_updating_) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Currently updating");
|
||||
ESP_LOGD(TAG, "Currently updating");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
if (!network::is_connected()) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Network is not connected");
|
||||
ESP_LOGD(TAG, "Network is not connected");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Setting Nextion protocol reparse mode to passive");
|
||||
ESP_LOGD(TAG, "Setting Nextion protocol reparse mode to passive");
|
||||
id(disp1).set_protocol_reparse_mode(false);
|
||||
|
||||
is_updating_ = true;
|
||||
@@ -2770,7 +2777,7 @@ script:
|
||||
int status = esp_http_client_perform(http);
|
||||
delay(100);
|
||||
while ((status != ESP_OK || (esp_http_client_get_status_code(http) != 200 && esp_http_client_get_status_code(http) != 206)) && tries <= 5) {
|
||||
ESP_LOGW("script.upload_tft.upload_tft", "HTTP Request failed; URL: %s; Error: %d, retrying (%d/5)", url.c_str(), status, tries);
|
||||
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %d, retrying (%d/5)", url.c_str(), status, tries);
|
||||
delay(250);
|
||||
status = esp_http_client_perform(http);
|
||||
tries++;
|
||||
@@ -2782,44 +2789,44 @@ script:
|
||||
}
|
||||
|
||||
int http_status = esp_http_client_get_status_code(http);
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "HTTP Status Code: %d", http_status);
|
||||
ESP_LOGD(TAG, "HTTP Status Code: %d", http_status);
|
||||
|
||||
char *content_range_cstr = nullptr;
|
||||
char *content_length_cstr = nullptr;
|
||||
|
||||
esp_err_t range_err = esp_http_client_get_header(http, "Content-Range", &content_range_cstr);
|
||||
if (range_err == ESP_OK && content_range_cstr != nullptr) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Fetched Content-Range header: %s", content_range_cstr);
|
||||
ESP_LOGD(TAG, "Fetched Content-Range header: %s", content_range_cstr);
|
||||
std::string content_range_string = content_range_cstr;
|
||||
content_range_string = content_range_string.substr(content_range_string.find("/") + 1);
|
||||
content_length_ = atoi(content_range_string.c_str());
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Using Content-Range header: %s", content_range_cstr);
|
||||
ESP_LOGD(TAG, "Using Content-Range header: %s", content_range_cstr);
|
||||
free(content_range_cstr);
|
||||
} else {
|
||||
ESP_LOGW("script.upload_tft.upload_tft", "Failed to fetch Content-Range header. Error: %d", range_err);
|
||||
ESP_LOGW(TAG, "Failed to fetch Content-Range header. Error: %d", range_err);
|
||||
}
|
||||
|
||||
esp_err_t length_err = esp_http_client_get_header(http, "Content-Length", &content_length_cstr);
|
||||
if (length_err == ESP_OK && content_length_cstr != nullptr) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Fetched Content-Length header: %s", content_length_cstr);
|
||||
ESP_LOGD(TAG, "Fetched Content-Length header: %s", content_length_cstr);
|
||||
content_length_ = atoi(content_length_cstr); // Convert to integer
|
||||
free(content_length_cstr);
|
||||
} else {
|
||||
ESP_LOGW("script.upload_tft.upload_tft", "Failed to fetch Content-Length header. Error: %d", length_err);
|
||||
ESP_LOGW(TAG, "Failed to fetch Content-Length header. Error: %d", length_err);
|
||||
}
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Parsed content length: %d", content_length_);
|
||||
ESP_LOGD(TAG, "Parsed content length: %d", content_length_);
|
||||
|
||||
if (content_length_ < 4096) {
|
||||
ESP_LOGE("script.upload_tft.upload_tft", "File size check failed. Size: %d", content_length_);
|
||||
ESP_LOGE(TAG, "File size check failed. Size: %d", content_length_);
|
||||
return upload_end_(true);
|
||||
} else {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "File size check passed. Proceeding...");
|
||||
ESP_LOGD(TAG, "File size check passed. Proceeding...");
|
||||
}
|
||||
|
||||
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Updating Nextion");
|
||||
ESP_LOGD(TAG, "Updating Nextion");
|
||||
// The Nextion will ignore the update command if it is sleeping
|
||||
|
||||
char command[128];
|
||||
@@ -2843,17 +2850,17 @@ script:
|
||||
}
|
||||
|
||||
std::string response;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Waiting for upgrade response");
|
||||
ESP_LOGD(TAG, "Waiting for upgrade response");
|
||||
recv_ret_string_(response, 2000, true); // This can take some time to return
|
||||
|
||||
// The Nextion display will, if it's ready to accept data, send a 0x05 byte.
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Upgrade response is [%s]",
|
||||
ESP_LOGD(TAG, "Upgrade response is [%s]",
|
||||
format_hex_pretty(reinterpret_cast<const uint8_t *>(response.data()), response.size()).c_str());
|
||||
|
||||
if (response.find(0x05) != std::string::npos) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Preparation for tft update done");
|
||||
ESP_LOGD(TAG, "Preparation for tft update done");
|
||||
} else {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Preparation for tft update failed %d \"%s\"", response[0], response.c_str());
|
||||
ESP_LOGD(TAG, "Preparation for tft update failed %d \"%s\"", response[0], response.c_str());
|
||||
return upload_end_(true);
|
||||
}
|
||||
|
||||
@@ -2869,12 +2876,12 @@ script:
|
||||
|
||||
if (transfer_buffer_ == nullptr) {
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Allocating buffer size %d, Heap size is %u", chunk_size, esp_get_free_heap_size());
|
||||
ESP_LOGD(TAG, "Allocating buffer size %d, Heap size is %u", chunk_size, esp_get_free_heap_size());
|
||||
transfer_buffer_ = allocator.allocate(chunk_size);
|
||||
if (transfer_buffer_ == nullptr) { // Try a smaller size
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Could not allocate buffer size: %d trying 4096 instead", chunk_size);
|
||||
ESP_LOGD(TAG, "Could not allocate buffer size: %d trying 4096 instead", chunk_size);
|
||||
chunk_size = 4096;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Allocating %d buffer", chunk_size);
|
||||
ESP_LOGD(TAG, "Allocating %d buffer", chunk_size);
|
||||
transfer_buffer_ = allocator.allocate(chunk_size);
|
||||
|
||||
if (!transfer_buffer_)
|
||||
@@ -2886,21 +2893,21 @@ script:
|
||||
transfer_buffer_size_ = chunk_size;
|
||||
}
|
||||
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d",
|
||||
ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d",
|
||||
url.c_str(), content_length_, transfer_buffer_size_, esp_get_free_heap_size());
|
||||
|
||||
int result = 0;
|
||||
while (content_length_ > 0) {
|
||||
result = upload_by_chunks_esp_idf(url, result);
|
||||
if (result < 0) {
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Error updating Nextion!");
|
||||
ESP_LOGD(TAG, "Error updating Nextion!");
|
||||
return upload_end_(true);
|
||||
}
|
||||
App.feed_wdt();
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Heap Size %d, Bytes left %d", esp_get_free_heap_size(), content_length_);
|
||||
ESP_LOGD(TAG, "Heap Size %d, Bytes left %d", esp_get_free_heap_size(), content_length_);
|
||||
}
|
||||
is_updating_ = false;
|
||||
ESP_LOGD("script.upload_tft.upload_tft", "Successfully updated Nextion!");
|
||||
ESP_LOGD(TAG, "Successfully updated Nextion!");
|
||||
|
||||
return upload_end_(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user