Compare commits
6 Commits
b94461b39f
...
64ab3fa4b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64ab3fa4b9 | ||
|
|
7629fa086b | ||
|
|
6b03d7c44f | ||
|
|
9cae2b3d9f | ||
|
|
e73cfb731d | ||
|
|
52e3dd174c |
@@ -82,7 +82,7 @@ script:
|
||||
- id: !extend change_climate_state
|
||||
then:
|
||||
- lambda: |-
|
||||
if (embedded) {
|
||||
if (embedded and !id(is_uploading_tft)) {
|
||||
static const char *const TAG = "addon_climate_base.script.change_climate_state";
|
||||
auto FahrenheitToCelsius = [](float fahrenheit) -> float {
|
||||
return (fahrenheit - 32.0) * 5.0 / 9.0;
|
||||
@@ -114,7 +114,7 @@ script:
|
||||
call.set_mode(value);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid call:");
|
||||
ESP_LOGE(TAG, " Embedded: %s", embedded ? "True" : "False");
|
||||
ESP_LOGE(TAG, " Embedded: %s", YESNO(embedded));
|
||||
ESP_LOGE(TAG, " Key: %s", key.c_str());
|
||||
ESP_LOGE(TAG, " Value: %s", value.c_str());
|
||||
}
|
||||
@@ -136,7 +136,7 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
id(is_addon_climate_visible) = (current_page->state == "climate" and detailed_entity->state == "embedded_climate");
|
||||
if (id(is_addon_climate_visible)) {
|
||||
if (id(is_addon_climate_visible) and !id(is_uploading_tft)) {
|
||||
static const char *const TAG = "addon_climate_base.script.page_climate";
|
||||
auto CelsiusToFahrenheit = [](float celsius) -> float {
|
||||
return (celsius * 9 / 5) + 32;
|
||||
@@ -207,57 +207,59 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
// Update chips
|
||||
if (id(is_embedded_thermostat))
|
||||
if (id(is_embedded_thermostat) and !id(is_uploading_tft))
|
||||
update_climate_icon->execute("home.icon_top_03", int(thermostat_embedded->action), int(thermostat_embedded->mode));
|
||||
|
||||
- id: !extend set_climate
|
||||
then:
|
||||
- lambda: |-
|
||||
if (current_page->state == "climate")
|
||||
if (current_page->state == "climate" and !id(is_uploading_tft))
|
||||
id(is_addon_climate_visible) = embedded_climate;
|
||||
|
||||
- id: !extend watchdog
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_climate_base.script.watchdog";
|
||||
bool addon_climate_cool = ${addon_climate_cool};
|
||||
bool addon_climate_heat = ${addon_climate_heat};
|
||||
bool addon_climate_dual = ${addon_climate_dual};
|
||||
uint cooler_relay = ${cooler_relay};
|
||||
uint heater_relay = ${heater_relay};
|
||||
ESP_LOGI(TAG, "Add-on climate:");
|
||||
if (addon_climate_cool) {
|
||||
ESP_LOGI(TAG, " Cool: %s", addon_climate_cool ? "Enabled" : "Disabled");
|
||||
if (cooler_relay == 1 or cooler_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay: %u", cooler_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay: %u", cooler_relay);
|
||||
}
|
||||
if (addon_climate_heat) {
|
||||
ESP_LOGI(TAG, " Heat: %s", addon_climate_heat ? "Enabled" : "Disabled");
|
||||
if (heater_relay == 1 or heater_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay: %u", heater_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay: %u", heater_relay);
|
||||
}
|
||||
if (addon_climate_dual) {
|
||||
ESP_LOGI(TAG, " Dual: %s", addon_climate_dual ? "Enabled" : "Disabled");
|
||||
if (cooler_relay == 1 or cooler_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay (cooler): %u", cooler_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay (cooler): %u", cooler_relay);
|
||||
if (heater_relay == 1 or heater_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay (heater): %u", heater_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay (heater): %u", heater_relay);
|
||||
if (cooler_relay == heater_relay)
|
||||
ESP_LOGE(TAG, " Double relay assignment");
|
||||
}
|
||||
if (!id(is_uploading_tft)) {
|
||||
static const char *const TAG = "addon_climate_base.script.watchdog";
|
||||
bool addon_climate_cool = ${addon_climate_cool};
|
||||
bool addon_climate_heat = ${addon_climate_heat};
|
||||
bool addon_climate_dual = ${addon_climate_dual};
|
||||
uint cooler_relay = ${cooler_relay};
|
||||
uint heater_relay = ${heater_relay};
|
||||
ESP_LOGI(TAG, "Add-on climate:");
|
||||
if (addon_climate_cool) {
|
||||
ESP_LOGI(TAG, " Cool: %s", addon_climate_cool ? "Enabled" : "Disabled");
|
||||
if (cooler_relay == 1 or cooler_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay: %u", cooler_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay: %u", cooler_relay);
|
||||
}
|
||||
if (addon_climate_heat) {
|
||||
ESP_LOGI(TAG, " Heat: %s", addon_climate_heat ? "Enabled" : "Disabled");
|
||||
if (heater_relay == 1 or heater_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay: %u", heater_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay: %u", heater_relay);
|
||||
}
|
||||
if (addon_climate_dual) {
|
||||
ESP_LOGI(TAG, " Dual: %s", addon_climate_dual ? "Enabled" : "Disabled");
|
||||
if (cooler_relay == 1 or cooler_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay (cooler): %u", cooler_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay (cooler): %u", cooler_relay);
|
||||
if (heater_relay == 1 or heater_relay == 2)
|
||||
ESP_LOGI(TAG, " Relay (heater): %u", heater_relay);
|
||||
else
|
||||
ESP_LOGE(TAG, " Relay (heater): %u", heater_relay);
|
||||
if (cooler_relay == heater_relay)
|
||||
ESP_LOGE(TAG, " Double relay assignment");
|
||||
}
|
||||
|
||||
if ((addon_climate_cool && addon_climate_heat) ||
|
||||
(addon_climate_cool && addon_climate_dual) ||
|
||||
(addon_climate_heat && addon_climate_dual) ||
|
||||
(!addon_climate_cool && !addon_climate_heat && !addon_climate_dual)) {
|
||||
ESP_LOGE(TAG, "Invalid settings for add-on Climate");
|
||||
if ((addon_climate_cool && addon_climate_heat) ||
|
||||
(addon_climate_cool && addon_climate_dual) ||
|
||||
(addon_climate_heat && addon_climate_dual) ||
|
||||
(!addon_climate_cool && !addon_climate_heat && !addon_climate_dual)) {
|
||||
ESP_LOGE(TAG, "Invalid settings for add-on Climate");
|
||||
}
|
||||
}
|
||||
...
|
||||
|
||||
@@ -72,10 +72,8 @@ esphome:
|
||||
- lambda: |-
|
||||
// Hide TFT file selectors when using arduino
|
||||
#ifdef ARDUINO
|
||||
tft_file_branch->set_internal(true);
|
||||
tft_file_model->set_internal(true);
|
||||
#elif defined(ESP_PLATFORM)
|
||||
tft_file_branch->set_internal(false);
|
||||
tft_file_model->set_internal(false);
|
||||
#endif
|
||||
|
||||
@@ -90,21 +88,11 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: ${upload_tft_baud_rate}
|
||||
|
||||
#- id: tft_branch
|
||||
# type: uint
|
||||
# restore_value: true
|
||||
# initial_value: '0'
|
||||
|
||||
- id: tft_is_valid
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
|
||||
#- id: tft_model
|
||||
# type: uint
|
||||
# restore_value: true
|
||||
# initial_value: '0'
|
||||
|
||||
- id: tft_upload_attempt
|
||||
type: uint
|
||||
restore_value: false
|
||||
@@ -115,18 +103,12 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: '"${nextion_update_url}"'
|
||||
|
||||
script:
|
||||
- id: exit_reparse_v414
|
||||
mode: restart
|
||||
then:
|
||||
- logger.log: "Exit reparse"
|
||||
- uart.write:
|
||||
id: tf_uart
|
||||
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
|
||||
- uart.write:
|
||||
id: tf_uart
|
||||
data: [0xFF, 0xFF, 0xFF]
|
||||
- id: tft_upload_result
|
||||
type: esphome::nextion::Nextion::TFTUploadResult
|
||||
restore_value: false
|
||||
initial_value: 'esphome::nextion::Nextion::TFTUploadResult::Unknown'
|
||||
|
||||
script:
|
||||
- id: nextion_uart_command
|
||||
mode: queued
|
||||
parameters:
|
||||
@@ -160,7 +142,8 @@ script:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.script.nextion_upload";
|
||||
ESP_LOGD(TAG, "Starting TFT upload...");
|
||||
if (disp1->upload_tft()) App.safe_reboot();
|
||||
id(tft_upload_result) = disp1->upload_tft();
|
||||
ESP_LOGD(TAG, "TFT upload: %s", esphome::nextion::Nextion::TFTUploadResultToString(id(tft_upload_result)));
|
||||
|
||||
- id: open_upload_dialog
|
||||
mode: restart
|
||||
@@ -210,22 +193,6 @@ script:
|
||||
App.feed_wdt();
|
||||
}
|
||||
|
||||
- id: !extend restore_settings
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.script.restore_settings";
|
||||
|
||||
// ESP_LOGD(TAG, "Restoring TFT file branch selector to index %u", id(tft_branch));
|
||||
// auto tft_file_branch_call = id(tft_file_branch).make_call();
|
||||
// tft_file_branch_call.set_index(id(tft_branch));
|
||||
// tft_file_branch_call.perform();
|
||||
|
||||
// ESP_LOGD(TAG, "Restoring TFT file model selector to index %u", id(tft_model));
|
||||
// auto tft_file_model_call = id(tft_file_model).make_call();
|
||||
// tft_file_model_call.set_index(id(tft_model));
|
||||
// tft_file_model_call.perform();
|
||||
|
||||
- id: set_tft_file
|
||||
mode: restart
|
||||
then:
|
||||
@@ -236,15 +203,13 @@ script:
|
||||
#elif defined(ESP_PLATFORM)
|
||||
static const char *const TAG = "addon_upload_tft.script.set_tft_file.esp_idf";
|
||||
#endif
|
||||
std::string branch = tft_file_branch->state;
|
||||
std::string branch = "v${version}";
|
||||
if (branch.find("beta") != std::string::npos) branch = "beta";
|
||||
else if (branch.find("dev") != std::string::npos) branch = "dev";
|
||||
std::string model = tft_file_model->state;
|
||||
ESP_LOGD(TAG, "TFT URL set:");
|
||||
ESP_LOGD(TAG, " Branch: %s", branch.c_str());
|
||||
ESP_LOGD(TAG, " Model: %s", model.c_str());
|
||||
// if (id(is_restored_settings) and tft_file_branch->active_index().has_value())
|
||||
// id(tft_branch) = tft_file_branch->active_index().value();
|
||||
// if (id(is_restored_settings) and tft_file_model->active_index().has_value())
|
||||
// id(tft_model) = tft_file_model->active_index().value();
|
||||
|
||||
if (id(is_uploading_tft))
|
||||
ESP_LOGW(TAG, " TFT Upload in progress.");
|
||||
@@ -327,7 +292,7 @@ script:
|
||||
|
||||
ESP_LOGD(TAG, " Target upload baud rate: %d bps", id(baud_rate_target));
|
||||
ESP_LOGD(TAG, " Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate());
|
||||
ESP_LOGD(TAG, " Valid TFT: %s", id(tft_is_valid) ? "True" : "False");
|
||||
ESP_LOGD(TAG, " Valid TFT: %s", YESNO(id(tft_is_valid)));
|
||||
|
||||
// Upload URL
|
||||
ESP_LOGD(TAG, " Upload URL: %s", url.c_str());
|
||||
@@ -411,13 +376,6 @@ script:
|
||||
baud_rate: 115200
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Attempt twice with upload engine from v4.1.4 (115200bps)
|
||||
- script.execute:
|
||||
id: upload_tft_sequence_attempt_v414
|
||||
url: !lambda return url.c_str();
|
||||
baud_rate: 115200
|
||||
- script.wait: upload_tft_sequence_attempt_v414
|
||||
|
||||
### Restart Nextion and attempt twice again at default baud rate (115200bps)
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
@@ -492,692 +450,6 @@ script:
|
||||
- script.wait: upload_tft_attempt
|
||||
- delay: 5s
|
||||
|
||||
- id: upload_tft_sequence_attempt_v414
|
||||
mode: single
|
||||
parameters:
|
||||
url: string
|
||||
baud_rate: uint
|
||||
then:
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Setting baud rate"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute:
|
||||
id: set_baud_rate
|
||||
baud_rate: !lambda return baud_rate;
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Attempt #7
|
||||
- script.execute:
|
||||
id: upload_tft_v414
|
||||
url: !lambda return url.c_str();
|
||||
- script.wait: upload_tft_v414
|
||||
- delay: 5s
|
||||
# Attempt #8
|
||||
- script.execute:
|
||||
id: upload_tft_v414
|
||||
url: !lambda return url.c_str();
|
||||
- script.wait: upload_tft_v414
|
||||
- delay: 5s
|
||||
|
||||
- id: upload_tft_v414
|
||||
mode: single
|
||||
parameters:
|
||||
url: string
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.script.upload_tft_v414";
|
||||
ESP_LOGD(TAG, "Attempting to upload TFT");
|
||||
id(tft_upload_attempt)++;
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps", id(tft_upload_attempt), tf_uart->get_baud_rate());
|
||||
report_upload_progress->execute(update_msg);
|
||||
- script.wait: report_upload_progress
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
timeout: 1s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.script.upload_tft_v414";
|
||||
ESP_LOGD(TAG, "Starting...");
|
||||
std::vector<uint8_t> buffer_;
|
||||
|
||||
bool is_updating_ = false;
|
||||
|
||||
bool upload_first_chunk_sent_ = false;
|
||||
|
||||
int content_length_ = 0;
|
||||
int tft_size_ = 0;
|
||||
|
||||
auto delay_seconds_ = [](int seconds) {
|
||||
ESP_LOGD(TAG, "Wait %i seconds", seconds);
|
||||
for (int i = 0; i < (seconds*4); i++) {
|
||||
#ifdef ARDUINO
|
||||
delay(250);
|
||||
#elif defined(USE_ESP_IDF)
|
||||
vTaskDelay(pdMS_TO_TICKS(250));
|
||||
#endif
|
||||
App.feed_wdt();
|
||||
}
|
||||
};
|
||||
|
||||
auto set_baud_rate_ = [](int baud_rate) {
|
||||
#ifdef USE_ARDUINO
|
||||
auto *uart = reinterpret_cast<uart::ESP32ArduinoUARTComponent *>(tf_uart);
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
auto *uart = reinterpret_cast<uart::IDFUARTComponent *>(tf_uart);
|
||||
#endif
|
||||
uart->set_baud_rate(baud_rate);
|
||||
uart->setup();
|
||||
};
|
||||
|
||||
auto send_nextion_command = [](const std::string &command) -> bool
|
||||
{
|
||||
static const char *const TAG = "addon_upload_tft.script.upload_tft.send_nextion_command";
|
||||
ESP_LOGD(TAG, "Sending: %s", command.c_str());
|
||||
id(tf_uart).write_str(command.c_str());
|
||||
const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF};
|
||||
id(tf_uart).write_array(to_send, sizeof(to_send));
|
||||
return true;
|
||||
};
|
||||
|
||||
auto recv_ret_string_ = [](std::string &response, uint32_t timeout, bool recv_flag) -> uint16_t
|
||||
{
|
||||
static const char *const TAG = "script.upload_tft.recv_ret_string_";
|
||||
uint16_t ret;
|
||||
uint8_t c = 0;
|
||||
uint8_t nr_of_ff_bytes = 0;
|
||||
uint64_t start;
|
||||
bool exit_flag = false;
|
||||
bool ff_flag = false;
|
||||
|
||||
start = millis();
|
||||
|
||||
while ((timeout == 0 && id(tf_uart).available()) || millis() - start <= timeout)
|
||||
{
|
||||
if (!id(tf_uart).available())
|
||||
{
|
||||
App.feed_wdt();
|
||||
continue;
|
||||
}
|
||||
|
||||
id(tf_uart).read_byte(&c);
|
||||
if (c == 0xFF)
|
||||
{
|
||||
nr_of_ff_bytes++;
|
||||
}
|
||||
else
|
||||
{
|
||||
nr_of_ff_bytes = 0;
|
||||
ff_flag = false;
|
||||
}
|
||||
|
||||
if (nr_of_ff_bytes >= 3)
|
||||
ff_flag = true;
|
||||
|
||||
response += (char) c;
|
||||
if (recv_flag)
|
||||
{
|
||||
if (response.find(0x05) != std::string::npos)
|
||||
{
|
||||
exit_flag = true;
|
||||
}
|
||||
}
|
||||
App.feed_wdt();
|
||||
delay(2);
|
||||
|
||||
if (exit_flag || ff_flag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ff_flag)
|
||||
response = response.substr(0, response.length() - 3); // Remove last 3 0xFF
|
||||
|
||||
ret = response.length();
|
||||
return ret;
|
||||
};
|
||||
|
||||
auto upload_end_ = [&](bool completed) -> bool
|
||||
{
|
||||
static const char *const TAG = "script.upload_tft.upload_end_";
|
||||
ESP_LOGD(TAG, "Completed: %s", completed ? "True" : "False");
|
||||
//ESP_LOGD(TAG, "Restarting Nextion");
|
||||
//send_nextion_command("rest");
|
||||
#ifdef ARDUINO
|
||||
delay(1500);
|
||||
#elif defined(ESP_PLATFORM)
|
||||
//vTaskDelay(pdMS_TO_TICKS(1500));
|
||||
#endif
|
||||
|
||||
is_updating_ = false;
|
||||
if (!completed) ESP_LOGD(TAG, "Nextion TFT upload will attempt again");
|
||||
return completed;
|
||||
};
|
||||
|
||||
#ifdef ARDUINO // arduino # To do: Move to Nextion component on ESPHome
|
||||
size_t transfer_buffer_size_ = 0;
|
||||
uint8_t *transfer_buffer_{nullptr};
|
||||
auto upload_by_chunks_arduino = [&](HTTPClient *http, const std::string &url, int range_start) -> int
|
||||
{
|
||||
static const char *const TAG = "script.upload_tft.upload_by_chunks_arduino";
|
||||
int range_end;
|
||||
|
||||
if (range_start == 0 && transfer_buffer_size_ > 16384) { // Start small at the first run in case of a big skip
|
||||
range_end = 16384 - 1;
|
||||
} else {
|
||||
range_end = range_start + transfer_buffer_size_ - 1;
|
||||
}
|
||||
|
||||
if (range_end > tft_size_)
|
||||
range_end = tft_size_;
|
||||
|
||||
char range_header[64];
|
||||
sprintf(range_header, "bytes=%d-%d", range_start, range_end);
|
||||
|
||||
ESP_LOGD(TAG, "Requesting range: %s", range_header);
|
||||
|
||||
int tries = 1;
|
||||
int code;
|
||||
bool begin_status;
|
||||
while (tries <= 10) {
|
||||
begin_status = http->begin(url.c_str());
|
||||
|
||||
++tries;
|
||||
if (!begin_status) {
|
||||
ESP_LOGD(TAG, "Connection failed");
|
||||
delay(1000);
|
||||
continue;
|
||||
};
|
||||
|
||||
http->addHeader("Range", range_header);
|
||||
|
||||
code = http->GET();
|
||||
if (code == 200 || code == 206) {
|
||||
break;
|
||||
}
|
||||
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s, retries(%d/10)", url.c_str(),
|
||||
HTTPClient::errorToString(code).c_str(), tries);
|
||||
http->end();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
if (tries > 10) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string recv_string;
|
||||
size_t size;
|
||||
int fetched = 0;
|
||||
int range = range_end - range_start;
|
||||
int write_len;
|
||||
|
||||
// fetch next segment from HTTP stream
|
||||
while (fetched < range) {
|
||||
size = http->getStreamPtr()->available();
|
||||
if (!size) {
|
||||
App.feed_wdt();
|
||||
delay(2);
|
||||
continue;
|
||||
}
|
||||
int c = http->getStreamPtr()->readBytes(
|
||||
&transfer_buffer_[fetched], ((size > transfer_buffer_size_) ? transfer_buffer_size_ : size));
|
||||
fetched += c;
|
||||
}
|
||||
http->end();
|
||||
ESP_LOGD(TAG, "Fetched %d bytes", fetched);
|
||||
|
||||
// upload fetched segments to the display in 4KB chunks
|
||||
for (int i = 0; i < range; i += 4096) {
|
||||
App.feed_wdt();
|
||||
write_len = content_length_ < 4096 ? content_length_ : 4096;
|
||||
id(tf_uart).write_array(&transfer_buffer_[i], write_len);
|
||||
content_length_ -= write_len;
|
||||
ESP_LOGD(TAG, "Uploaded %0.1f %%, remaining %d bytes",
|
||||
100.0 * (tft_size_ - content_length_) / tft_size_,
|
||||
content_length_);
|
||||
|
||||
if (!upload_first_chunk_sent_) {
|
||||
upload_first_chunk_sent_ = true;
|
||||
delay(500);
|
||||
}
|
||||
|
||||
recv_ret_string_(recv_string, 5000, true);
|
||||
if (recv_string[0] != 0x05) { // 0x05 == "ok"
|
||||
ESP_LOGD(TAG, "recv_string [%s]",
|
||||
format_hex_pretty(reinterpret_cast<const uint8_t *>(recv_string.data()), recv_string.size()).c_str());
|
||||
}
|
||||
|
||||
// handle partial upload request
|
||||
if (recv_string[0] == 0x08 && recv_string.size() == 5) {
|
||||
uint32_t result = 0;
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
result += static_cast<uint8_t>(recv_string[j + 1]) << (8 * j);
|
||||
}
|
||||
if (result > 0) {
|
||||
ESP_LOGD(TAG, "Nextion reported new range %d", result);
|
||||
content_length_ = tft_size_ - result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
recv_string.clear();
|
||||
}
|
||||
return range_end + 1;
|
||||
};
|
||||
auto upload_tft_ = [&](const std::string &url, uint32_t update_baud_rate_) -> bool
|
||||
{
|
||||
static const char *const TAG = "addon_upload_tft.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: %" PRIu32, update_baud_rate_);
|
||||
|
||||
if (is_updating_) {
|
||||
ESP_LOGD(TAG, "Currently updating");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
if (!network::is_connected()) {
|
||||
ESP_LOGD(TAG, "Network is not connected");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
if (!disp1->is_setup()) {
|
||||
ESP_LOGD(TAG, "Setting Nextion protocol reparse mode to passive");
|
||||
exit_reparse_v414->execute();
|
||||
delay_seconds_(5);
|
||||
}
|
||||
|
||||
is_updating_ = true;
|
||||
|
||||
HTTPClient http;
|
||||
http.setTimeout(15000); // Yes 15 seconds.... Helps 8266s along
|
||||
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
bool begin_status = http.begin(url.c_str());
|
||||
if (!begin_status) {
|
||||
is_updating_ = false;
|
||||
ESP_LOGD(TAG, "Connection failed");
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
allocator.deallocate(transfer_buffer_, transfer_buffer_size_);
|
||||
return upload_end_(false);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Connected");
|
||||
}
|
||||
|
||||
http.addHeader("Range", "bytes=0-255");
|
||||
const char *header_names[] = {"Content-Range"};
|
||||
http.collectHeaders(header_names, 1);
|
||||
ESP_LOGD(TAG, "Requesting URL: %s", url.c_str());
|
||||
|
||||
http.setReuse(true);
|
||||
// attempt up to 5 times. DNS sometimes needs a second attempt or so
|
||||
int tries = 1;
|
||||
int code = http.GET();
|
||||
delay(100);
|
||||
|
||||
while (code != 200 && code != 206 && tries <= 5) {
|
||||
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s, reattempting (%d/5)", url.c_str(),
|
||||
HTTPClient::errorToString(code).c_str(), tries);
|
||||
|
||||
delay(250);
|
||||
code = http.GET();
|
||||
++tries;
|
||||
}
|
||||
|
||||
if ((code != 200 && code != 206) || tries > 5) {
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
String content_range_string = http.header("Content-Range");
|
||||
content_range_string.remove(0, 12);
|
||||
content_length_ = content_range_string.toInt();
|
||||
tft_size_ = content_length_;
|
||||
http.end();
|
||||
|
||||
if (content_length_ < 4096) {
|
||||
ESP_LOGE(TAG, "Failed to get file size");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Updating Nextion");
|
||||
// The Nextion will ignore the update command if it is sleeping
|
||||
|
||||
char command[128];
|
||||
// Tells the Nextion the content length of the tft file and baud rate it will be sent at
|
||||
// Once the Nextion accepts the command it will wait until the file is successfully uploaded
|
||||
// If it fails for any reason a power cycle of the display will be needed
|
||||
sprintf(command, "whmi-wris %d,%d,1", content_length_, update_baud_rate_);
|
||||
|
||||
ESP_LOGD(TAG, "Clear serial receive buffer: %d", id(tf_uart).available());
|
||||
// Clear serial receive buffer
|
||||
uint8_t d;
|
||||
while (id(tf_uart).available()) {
|
||||
id(tf_uart).read_byte(&d);
|
||||
};
|
||||
|
||||
send_nextion_command(command);
|
||||
|
||||
if (update_baud_rate_ != id(tf_uart).get_baud_rate()) {
|
||||
set_baud_rate_(update_baud_rate_);
|
||||
//id(tf_uart).set_baud_rate(update_baud_rate_);
|
||||
//id(tf_uart).setup();
|
||||
//delay_seconds_(2);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Waiting for upgrade response");
|
||||
std::string response;
|
||||
recv_ret_string_(response, 5000, 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(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(TAG, "Preparation for tft update done");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Preparation for tft update failed %d \"%s\"", response[0], response.c_str());
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
// Nextion wants 4096 bytes at a time. Make chunk_size a multiple of 4096
|
||||
uint32_t chunk_size = 8192;
|
||||
if (ESP.getFreeHeap() > 81920) { // Ensure some FreeHeap to other things and limit chunk size
|
||||
chunk_size = ESP.getFreeHeap() - 65536;
|
||||
chunk_size = int(chunk_size / 4096) * 4096;
|
||||
chunk_size = chunk_size > ${upload_tft_chunk_size_max} ? ${upload_tft_chunk_size_max} : chunk_size;
|
||||
} else if (ESP.getFreeHeap() < 32768) {
|
||||
chunk_size = 4096;
|
||||
}
|
||||
|
||||
if (transfer_buffer_ == nullptr) {
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
ESP_LOGD(TAG, "Allocating buffer size %d, Heap size is %" PRIu32, chunk_size, ESP.getFreeHeap());
|
||||
transfer_buffer_ = allocator.allocate(chunk_size);
|
||||
if (transfer_buffer_ == nullptr) { // Attempt a smaller size
|
||||
ESP_LOGD(TAG, "Could not allocate buffer size: %d attempting 4096 instead", chunk_size);
|
||||
chunk_size = 4096;
|
||||
ESP_LOGD(TAG, "Allocating %d buffer", chunk_size);
|
||||
transfer_buffer_ = allocator.allocate(chunk_size);
|
||||
|
||||
if (!transfer_buffer_)
|
||||
{
|
||||
return upload_end_(false);
|
||||
}
|
||||
}
|
||||
|
||||
transfer_buffer_size_ = chunk_size;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %" PRIu32,
|
||||
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(TAG, "Error updating Nextion!");
|
||||
return upload_end_(false);
|
||||
}
|
||||
App.feed_wdt();
|
||||
ESP_LOGD(TAG, "Heap Size %" PRIu32 ", Bytes left %d", ESP.getFreeHeap(), content_length_);
|
||||
}
|
||||
is_updating_ = false;
|
||||
ESP_LOGD(TAG, "Successfully updated Nextion!");
|
||||
|
||||
return upload_end_(true);
|
||||
};
|
||||
#elif defined(ESP_PLATFORM) // esp-idf # To do: Move to Nextion component on ESPHome
|
||||
auto upload_range_esp_idf_ = [&](const std::string &url, int range_start) -> int {
|
||||
static const char *const TAG = "addon_upload_tft.script.upload_tft.upload_range_esp_idf_";
|
||||
ESP_LOGVV(TAG, "url: %s", url.c_str());
|
||||
uint32_t range_size_ = tft_size_ - range_start;
|
||||
ESP_LOGVV(TAG, "tft_size_: %i", tft_size_);
|
||||
ESP_LOGV(TAG, "Available heap: %" PRIu32, esp_get_free_heap_size());
|
||||
int range_end = (range_start == 0) ? std::min(tft_size_, 16383) : tft_size_;
|
||||
if (range_size_ <= 0 or range_end <= range_start) {
|
||||
ESP_LOGE(TAG, "Invalid range");
|
||||
ESP_LOGD(TAG, "Range start: %i", range_start);
|
||||
ESP_LOGD(TAG, "Range end: %i", range_end);
|
||||
ESP_LOGD(TAG, "Range size: %" PRIu32, range_size_);
|
||||
return -1;
|
||||
}
|
||||
|
||||
esp_http_client_config_t config = {
|
||||
.url = url.c_str(),
|
||||
.cert_pem = nullptr,
|
||||
};
|
||||
esp_http_client_handle_t client = esp_http_client_init(&config);
|
||||
|
||||
char range_header[64];
|
||||
sprintf(range_header, "bytes=%d-%d", range_start, range_end);
|
||||
ESP_LOGV(TAG, "Requesting range: %s", range_header);
|
||||
esp_http_client_set_header(client, "Range", range_header);
|
||||
ESP_LOGVV(TAG, "Available heap: %u", esp_get_free_heap_size());
|
||||
ESP_LOGV(TAG, "Opening http connetion");
|
||||
esp_err_t err;
|
||||
if ((err = esp_http_client_open(client, 0)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
|
||||
esp_http_client_cleanup(client);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Fetch content length");
|
||||
int content_length = esp_http_client_fetch_headers(client);
|
||||
ESP_LOGV(TAG, "content_length = %d", content_length);
|
||||
if (content_length <= 0) {
|
||||
ESP_LOGE(TAG, "Failed to get content length: %d", content_length);
|
||||
esp_http_client_cleanup(client);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int total_read_len = 0, read_len;
|
||||
|
||||
ESP_LOGV(TAG, "Allocate buffer");
|
||||
uint8_t* buffer = new uint8_t[4096];
|
||||
std::string recv_string;
|
||||
if (buffer == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for buffer");
|
||||
ESP_LOGV(TAG, "Available heap: %" PRIu32, esp_get_free_heap_size());
|
||||
} else {
|
||||
ESP_LOGV(TAG, "Memory for buffer allocated successfully");
|
||||
|
||||
while (true) {
|
||||
App.feed_wdt();
|
||||
ESP_LOGVV(TAG, "Available heap: %u", esp_get_free_heap_size());
|
||||
int read_len = esp_http_client_read(client, reinterpret_cast<char*>(buffer), 4096);
|
||||
ESP_LOGVV(TAG, "Read %d bytes from HTTP client, writing to UART", read_len);
|
||||
if (read_len > 0) {
|
||||
tf_uart->write_array(buffer, read_len);
|
||||
ESP_LOGVV(TAG, "Write to UART successful");
|
||||
recv_ret_string_(recv_string, 5000, true);
|
||||
content_length_ -= read_len;
|
||||
ESP_LOGD(TAG, "Uploaded %0.2f %%, remaining %d bytes",
|
||||
100.0 * (tft_size_ - content_length_) / tft_size_,
|
||||
content_length_);
|
||||
if (recv_string[0] != 0x05) { // 0x05 == "ok"
|
||||
ESP_LOGD(TAG, "recv_string [%s]",
|
||||
format_hex_pretty(reinterpret_cast<const uint8_t *>(recv_string.data()), recv_string.size()).c_str());
|
||||
}
|
||||
// handle partial upload request
|
||||
if (recv_string[0] == 0x08 && recv_string.size() == 5) {
|
||||
uint32_t result = 0;
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
result += static_cast<uint8_t>(recv_string[j + 1]) << (8 * j);
|
||||
}
|
||||
if (result > 0) {
|
||||
ESP_LOGI(TAG, "Nextion reported new range %" PRIu32, result);
|
||||
content_length_ = tft_size_ - result;
|
||||
// Deallocate the buffer when done
|
||||
delete[] buffer;
|
||||
ESP_LOGVV(TAG, "Memory for buffer deallocated");
|
||||
esp_http_client_cleanup(client);
|
||||
esp_http_client_close(client);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
recv_string.clear();
|
||||
} else if (read_len == 0) {
|
||||
ESP_LOGV(TAG, "End of HTTP response reached");
|
||||
break; // Exit the loop if there is no more data to read
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to read from HTTP client, error code: %d", read_len);
|
||||
break; // Exit the loop on error
|
||||
}
|
||||
}
|
||||
|
||||
// Deallocate the buffer when done
|
||||
delete[] buffer;
|
||||
ESP_LOGVV(TAG, "Memory for buffer deallocated");
|
||||
}
|
||||
esp_http_client_cleanup(client);
|
||||
esp_http_client_close(client);
|
||||
return range_end + 1;
|
||||
};
|
||||
auto upload_tft_ = [&](const std::string &url, unsigned int update_baud_rate_) -> bool {
|
||||
static const char *const TAG = "addon_upload_tft.script.upload_tft.upload_tft_esp_idf";
|
||||
ESP_LOGD(TAG, "Nextion TFT upload requested");
|
||||
ESP_LOGD(TAG, " url: %s", url.c_str());
|
||||
ESP_LOGD(TAG, " baud_rate: %u", update_baud_rate_);
|
||||
|
||||
if (is_updating_) {
|
||||
ESP_LOGW(TAG, "Currently updating");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
if (!network::is_connected()) {
|
||||
ESP_LOGE(TAG, "Network is not connected");
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
if (!disp1->is_setup()) {
|
||||
ESP_LOGD(TAG, "Setting Nextion protocol reparse mode to passive");
|
||||
exit_reparse_v414->execute();
|
||||
delay_seconds_(5);
|
||||
}
|
||||
|
||||
is_updating_ = true;
|
||||
|
||||
// Define the configuration for the HTTP client
|
||||
ESP_LOGV(TAG, "Establishing connection to HTTP server");
|
||||
ESP_LOGVV(TAG, "Available heap: %u", esp_get_free_heap_size());
|
||||
esp_http_client_config_t config = {
|
||||
.url = url.c_str(),
|
||||
.cert_pem = nullptr,
|
||||
.method = HTTP_METHOD_HEAD,
|
||||
.timeout_ms = 15000,
|
||||
};
|
||||
|
||||
// Initialize the HTTP client with the configuration
|
||||
ESP_LOGV(TAG, "Initializing HTTP client");
|
||||
ESP_LOGV(TAG, "Available heap: %" PRIu32, esp_get_free_heap_size());
|
||||
esp_http_client_handle_t http = esp_http_client_init(&config);
|
||||
if (!http) {
|
||||
ESP_LOGE(TAG, "Failed to initialize HTTP client.");
|
||||
return upload_end_(false); // return -1 to indicate an error
|
||||
}
|
||||
|
||||
// Perform the HTTP request
|
||||
ESP_LOGV(TAG, "Check if the client could connect");
|
||||
ESP_LOGV(TAG, "Available heap: %" PRIu32, esp_get_free_heap_size());
|
||||
esp_err_t err = esp_http_client_perform(http);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "HTTP request failed: %s", esp_err_to_name(err));
|
||||
esp_http_client_cleanup(http);
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
// Check the HTTP Status Code
|
||||
int status_code = esp_http_client_get_status_code(http);
|
||||
ESP_LOGV(TAG, "HTTP Status Code: %d", status_code);
|
||||
size_t tft_file_size = esp_http_client_get_content_length(http);
|
||||
ESP_LOGD(TAG, "TFT file size: %zu", tft_file_size);
|
||||
|
||||
if (tft_file_size < 4096) {
|
||||
ESP_LOGE(TAG, "File size check failed. Size: %zu", tft_file_size);
|
||||
esp_http_client_cleanup(http);
|
||||
return upload_end_(false);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "File size check passed. Proceeding...");
|
||||
}
|
||||
content_length_ = tft_file_size;
|
||||
tft_size_ = tft_file_size;
|
||||
|
||||
ESP_LOGD(TAG, "Updating Nextion");
|
||||
// The Nextion will ignore the update command if it is sleeping
|
||||
|
||||
char command[128];
|
||||
// Tells the Nextion the content length of the tft file and baud rate it will be sent at
|
||||
// Once the Nextion accepts the command it will wait until the file is successfully uploaded
|
||||
// If it fails for any reason a power cycle of the display will be needed
|
||||
sprintf(command, "whmi-wris %d,%d,1", content_length_, update_baud_rate_);
|
||||
|
||||
// Clear serial receive buffer
|
||||
uint8_t d;
|
||||
while (id(tf_uart).available()) {
|
||||
id(tf_uart).read_byte(&d);
|
||||
};
|
||||
|
||||
send_nextion_command(command);
|
||||
|
||||
if (update_baud_rate_ != id(tf_uart).get_baud_rate()) {
|
||||
set_baud_rate_(update_baud_rate_);
|
||||
//id(tf_uart).set_baud_rate(update_baud_rate_);
|
||||
//id(tf_uart).setup();
|
||||
}
|
||||
|
||||
std::string 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(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_LOGV(TAG, "Preparation for tft update done");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Preparation for tft update failed %d \"%s\"", response[0], response.c_str());
|
||||
esp_http_client_cleanup(http);
|
||||
return upload_end_(false);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d, Heap Size %" PRIu32,
|
||||
url.c_str(), content_length_, esp_get_free_heap_size());
|
||||
|
||||
ESP_LOGV(TAG, "Starting transfer by chunks loop");
|
||||
int result = 0;
|
||||
while (content_length_ > 0) {
|
||||
result = upload_range_esp_idf_(url.c_str(), result);
|
||||
if (result < 0) {
|
||||
ESP_LOGE(TAG, "Error updating Nextion!");
|
||||
esp_http_client_cleanup(http);
|
||||
return upload_end_(false);
|
||||
}
|
||||
App.feed_wdt();
|
||||
ESP_LOGV(TAG, "Heap Size %" PRIu32 ", Bytes left %d", esp_get_free_heap_size(), content_length_);
|
||||
}
|
||||
|
||||
is_updating_ = false;
|
||||
ESP_LOGD(TAG, "Successfully updated Nextion!");
|
||||
|
||||
ESP_LOGD(TAG, "Close HTTP connection");
|
||||
esp_http_client_close(http);
|
||||
esp_http_client_cleanup(http);
|
||||
return upload_end_(true);
|
||||
};
|
||||
#endif
|
||||
|
||||
if (upload_tft_(url, 115200)) App.safe_reboot();
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps failed!", id(tft_upload_attempt), tf_uart->get_baud_rate());
|
||||
report_upload_progress->execute(update_msg);
|
||||
ESP_LOGD(TAG, "Finished!");
|
||||
- script.wait: report_upload_progress
|
||||
|
||||
- id: upload_tft_attempt
|
||||
mode: single
|
||||
then:
|
||||
@@ -1186,6 +458,7 @@ script:
|
||||
- lambda: |-
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps", id(tft_upload_attempt), tf_uart->get_baud_rate());
|
||||
id(tft_upload_result) = esphome::nextion::Nextion::TFTUploadResult::Unknown;
|
||||
report_upload_progress->execute(update_msg);
|
||||
- script.wait: report_upload_progress
|
||||
- wait_until:
|
||||
@@ -1196,28 +469,33 @@ script:
|
||||
- script.wait: nextion_upload
|
||||
- lambda: |-
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps failed!", id(tft_upload_attempt), tf_uart->get_baud_rate());
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps returned: %s", id(tft_upload_attempt),
|
||||
tf_uart->get_baud_rate(), esphome::nextion::Nextion::TFTUploadResultToString(id(tft_upload_result)));
|
||||
report_upload_progress->execute(update_msg);
|
||||
- script.wait: report_upload_progress
|
||||
- if:
|
||||
condition:
|
||||
not:
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::Unknown;
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::UploadInProgress;
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::NextionError_PreparationFailed;
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::NextionError_InvalidResponse;
|
||||
then:
|
||||
- delay: 5s
|
||||
- lambda: |-
|
||||
App.safe_reboot();
|
||||
|
||||
- id: !extend watchdog
|
||||
then:
|
||||
- lambda: |-
|
||||
if (!id(is_uploading_tft)) {
|
||||
static const char *const TAG = "addon_upload_tft.script.watchdog";
|
||||
ESP_LOGI(TAG, "Add-on Upload TFT:");
|
||||
ESP_LOGI(TAG, " File model: %s", tft_file_model->state.c_str());
|
||||
ESP_LOGD(TAG, " Valid TFT: %s", YESNO(id(tft_is_valid)));
|
||||
}
|
||||
|
||||
select:
|
||||
- id: tft_file_branch
|
||||
name: Update TFT display - Branch
|
||||
platform: template
|
||||
options:
|
||||
- "v${version}"
|
||||
- "beta"
|
||||
- "dev"
|
||||
initial_option: "v${version}"
|
||||
optimistic: true
|
||||
restore_value: false
|
||||
internal: true
|
||||
entity_category: config
|
||||
disabled_by_default: true
|
||||
icon: mdi:file-sync
|
||||
set_action:
|
||||
- script.execute: set_tft_file
|
||||
|
||||
- id: tft_file_model
|
||||
name: Update TFT display - Model
|
||||
platform: template
|
||||
@@ -1237,7 +515,7 @@ select:
|
||||
entity_category: config
|
||||
disabled_by_default: false
|
||||
icon: mdi:file-sync
|
||||
set_action:
|
||||
on_value:
|
||||
- script.execute: set_tft_file
|
||||
|
||||
sensor:
|
||||
|
||||
@@ -23,10 +23,17 @@ substitutions:
|
||||
|
||||
##### External components #####
|
||||
external_components:
|
||||
- source: github://pr#6128 # Remove this and update min ver when that PR is released (Hopefully v2024.2.0)
|
||||
components:
|
||||
- nextion
|
||||
refresh: 300s
|
||||
#- source: github://pr#6128 # Remove this and update min ver when that PR is released (Hopefully v2024.2.0)
|
||||
# components:
|
||||
# - nextion
|
||||
# refresh: 300s
|
||||
- source: # Update this before the release
|
||||
type: git
|
||||
url: https://github.com/edwardtfn/esphome
|
||||
ref: nextion-21
|
||||
components: [ nextion ]
|
||||
refresh: 1s
|
||||
|
||||
|
||||
##### ESPHOME CONFIGURATION #####
|
||||
esphome:
|
||||
@@ -39,12 +46,19 @@ esphome:
|
||||
on_boot:
|
||||
- priority: 600.0 # This is where most sensors are set up.
|
||||
then:
|
||||
- lambda: |-
|
||||
// Update Wi-Fi icon
|
||||
disp1->set_component_text_printf("home.wifi_icon", "\uE708");
|
||||
// Update Wi-Fi icon color
|
||||
disp1->set_component_font_color("home.wifi_icon", 63488);
|
||||
- script.execute: restore_settings
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: return disp1->is_setup();
|
||||
timeout: 60s
|
||||
- if:
|
||||
condition:
|
||||
- lambda: return (not disp1->is_detected());
|
||||
then:
|
||||
- switch.turn_off: screen_power
|
||||
- delay: 2s
|
||||
- switch.turn_on: screen_power
|
||||
- delay: 5s
|
||||
|
||||
on_shutdown:
|
||||
- priority: 0
|
||||
@@ -564,10 +578,10 @@ api:
|
||||
ESP_LOGV(TAG, "notification_icon: %s", notification_icon.c_str());
|
||||
ESP_LOGV(TAG, "notification_icon_color_normal: %i", notification_icon_color_normal.size());
|
||||
ESP_LOGV(TAG, "notification_icon_color_unread: %i", notification_icon_color_unread.size());
|
||||
ESP_LOGV(TAG, "qrcode: %s", qrcode ? "True" : "False");
|
||||
ESP_LOGV(TAG, "qrcode: %s", YESNO(qrcode));
|
||||
ESP_LOGV(TAG, "qrcode_icon: %s", qrcode_icon.c_str());
|
||||
ESP_LOGV(TAG, "qrcode_icon_color: %i", qrcode_icon_color.size());
|
||||
ESP_LOGV(TAG, "entities_pages: %s", entities_pages ? "True" : "False");
|
||||
ESP_LOGV(TAG, "entities_pages: %s", YESNO(entities_pages));
|
||||
ESP_LOGV(TAG, "entities_pages_icon: %s", entities_pages_icon.c_str());
|
||||
ESP_LOGV(TAG, "entities_pages_icon_color: %i", entities_pages_icon_color.size());
|
||||
|
||||
@@ -1283,7 +1297,7 @@ select:
|
||||
entity_category: config
|
||||
disabled_by_default: true
|
||||
icon: mdi:swap-horizontal
|
||||
set_action:
|
||||
on_value:
|
||||
- lambda: set_baud_rate->execute(stoi(x), true);
|
||||
|
||||
- id: wakeup_page_name
|
||||
@@ -1307,7 +1321,7 @@ select:
|
||||
internal: false
|
||||
entity_category: config
|
||||
icon: mdi:page-next-outline
|
||||
set_action:
|
||||
on_value:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "select.wakeup_page_name";
|
||||
ESP_LOGD(TAG, "New wake-up page selected: %s", x.c_str());
|
||||
@@ -1584,28 +1598,6 @@ switch:
|
||||
|
||||
##### START - TEXT SENSOR CONFIGURATION #####
|
||||
text_sensor:
|
||||
|
||||
##### Device name - Used for the Blueprint to identify service names when device is renamed
|
||||
- id: device_name
|
||||
name: Device name
|
||||
internal: false
|
||||
platform: template
|
||||
update_interval: never
|
||||
lambda: |-
|
||||
return {"${name}"};
|
||||
filters:
|
||||
- to_lower:
|
||||
- lambda: |-
|
||||
std::replace(x.begin(), x.end(), ' ', '_');
|
||||
return x;
|
||||
- substitute:
|
||||
- "- -> _"
|
||||
- "___ -> _"
|
||||
- "__ -> _"
|
||||
- "__ -> _"
|
||||
- "__ -> _"
|
||||
- "__ -> _"
|
||||
|
||||
##### Entity Id of the entity displayed on the detailed pages
|
||||
- name: Detailed Entity
|
||||
id: detailed_entity
|
||||
@@ -1869,10 +1861,11 @@ script:
|
||||
|
||||
return (major1 == major2) && (minor1 == minor2);
|
||||
};
|
||||
ESP_LOGD(TAG, "ESPHome version: ${version}");
|
||||
ESP_LOGD(TAG, "TFT version: %s", version_tft->state.c_str());
|
||||
ESP_LOGD(TAG, "Versions:");
|
||||
ESP_LOGD(TAG, " ESPHome: ${version}");
|
||||
ESP_LOGD(TAG, " TFT: %s", version_tft->state.c_str());
|
||||
if (not compareVersions("${version}", version_tft->state.c_str())) ESP_LOGE(TAG, "TFT version mismatch!");
|
||||
ESP_LOGD(TAG, "Blueprint version: %s", version_blueprint->state.c_str());
|
||||
ESP_LOGD(TAG, " Blueprint: %s", version_blueprint->state.c_str());
|
||||
if (not compareVersions("${version}", version_blueprint->state.c_str())) ESP_LOGE(TAG, "Blueprint version mismatch!");
|
||||
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
@@ -2072,8 +2065,8 @@ script:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.nextion_status";
|
||||
ESP_LOGD(TAG, "Nextion status:");
|
||||
ESP_LOGD(TAG, " Is detected: %s", disp1->is_detected() ? "True" : "False");
|
||||
ESP_LOGD(TAG, " Is setup: %s", disp1->is_setup() ? "True" : "False");
|
||||
ESP_LOGD(TAG, " Is detected: %s", YESNO(disp1->is_detected()));
|
||||
ESP_LOGD(TAG, " Is setup: %s", YESNO(disp1->is_setup()));
|
||||
ESP_LOGD(TAG, " Queue size: %d", disp1->queue_size());
|
||||
|
||||
- id: notification_clear
|
||||
@@ -2441,7 +2434,7 @@ script:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.refresh_notification";
|
||||
bool is_notification = ((not notification_text->state.empty()) or (not notification_label->state.empty()));
|
||||
ESP_LOGV(TAG, "Notification: %s", is_notification ? "True" : "False");
|
||||
ESP_LOGV(TAG, "Notification: %s", YESNO(is_notification));
|
||||
disp1->send_command_printf("is_notification=%i", is_notification ? 0 : 1);
|
||||
if (current_page->state == "home") {
|
||||
if (is_notification) {
|
||||
@@ -2523,10 +2516,7 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.restore_settings";
|
||||
ESP_LOGD(TAG, "Restoring settings");
|
||||
|
||||
device_name->update();
|
||||
ESP_LOGD("script.restore_settings", "Restoring settings");
|
||||
|
||||
#ifdef ARDUINO
|
||||
id(framework) = 1;
|
||||
@@ -2534,16 +2524,19 @@ script:
|
||||
id(framework) = 2;
|
||||
#endif
|
||||
|
||||
ESP_LOGV(TAG, "Restoring baud rate");
|
||||
set_baud_rate->execute(stoi(baud_rate->state), true);
|
||||
|
||||
// ESP_LOGV(TAG, "Restoring wake-up page selector");
|
||||
// auto wakeup_page_name_call = id(wakeup_page_name).make_call();
|
||||
// wakeup_page_name_call.set_option(id(page_names)[id(wakeup_page_id)]);
|
||||
// wakeup_page_name_call.perform();
|
||||
|
||||
// id(is_restored_settings) = true;
|
||||
ESP_LOGV(TAG, "Finishing");
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: return (not isnan(stoi(baud_rate->state)));
|
||||
- lambda: |-
|
||||
ESP_LOGV("script.restore_settings", "Restoring baud rate");
|
||||
set_baud_rate->execute(stoi(baud_rate->state), true);
|
||||
ESP_LOGV("script.restore_settings", "Done!");
|
||||
|
||||
- id: service_call_alarm_control_panel
|
||||
mode: restart
|
||||
@@ -2657,7 +2650,7 @@ script:
|
||||
ESP_LOGD(TAG, " total_steps: %d", total_steps);
|
||||
ESP_LOGD(TAG, " temp_offset: %i", temp_offset);
|
||||
ESP_LOGD(TAG, " climate_icon: %s", climate_icon.c_str());
|
||||
ESP_LOGD(TAG, " embedded_climate: %s", embedded_climate ? "True" : "False");
|
||||
ESP_LOGD(TAG, " embedded_climate: %s", YESNO(embedded_climate));
|
||||
if (current_page->state == "climate") {
|
||||
ESP_LOGD(TAG, "Page climate is visible");
|
||||
disp1->send_command_printf("climateslider.maxval=%i", total_steps);
|
||||
@@ -3312,7 +3305,7 @@ script:
|
||||
ESP_LOGI(TAG, " Is setup: True");
|
||||
else {
|
||||
ESP_LOGW(TAG, " Is setup: False");
|
||||
ESP_LOGW(TAG, " Is detected: %s", disp1->is_detected() ? "True" : "False");
|
||||
ESP_LOGW(TAG, " Is detected: %s", YESNO(disp1->is_detected()));
|
||||
//exit_reparse->execute();
|
||||
}
|
||||
if (nextion_init->state) {
|
||||
|
||||
Reference in New Issue
Block a user