2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,4 +12,4 @@ Nextion2Text.*
|
||||
# Ignore dev folder
|
||||
#dev
|
||||
|
||||
nspanel_esphome_prebuilt.bin
|
||||
nspanel_esphome_prebuilt*.bin
|
||||
|
||||
@@ -105,7 +105,7 @@ globals:
|
||||
restore_value: true
|
||||
initial_value: '0'
|
||||
|
||||
- id: tft_upload_try
|
||||
- id: tft_upload_attempt
|
||||
type: uint
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
@@ -327,6 +327,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");
|
||||
|
||||
// Upload URL
|
||||
ESP_LOGD(TAG, " Upload URL: %s", url.c_str());
|
||||
@@ -382,152 +383,58 @@ script:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
timeout: 1s
|
||||
|
||||
### Try twice at the target baud rate
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
### Attempt twice with upload engine from v4.1.4 (115200bps) when TFT isn't detected
|
||||
- if:
|
||||
condition:
|
||||
- lambda: !lambda return (not id(tft_is_valid));
|
||||
then:
|
||||
- script.execute:
|
||||
id: upload_tft_sequence_attempt_v414
|
||||
url: !lambda return url.c_str();
|
||||
baud_rate: 115200
|
||||
- script.wait: upload_tft_sequence_attempt_v414
|
||||
|
||||
### Attempt twice at the target baud rate
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Setting baud rate"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute:
|
||||
id: set_baud_rate
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: !lambda return id(baud_rate_target);
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #1
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
# Try #2
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Try twice at the original baud rate
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
### Attempt twice at the original baud rate
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Setting baud rate"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute:
|
||||
id: set_baud_rate
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: !lambda return id(baud_rate_original);
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #3
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
# Try #4
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Try twice at the Nextion's default baud rate (115200bps)
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
### Attempt twice at the Nextion's default baud rate (115200bps)
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Setting baud rate"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute:
|
||||
id: set_baud_rate
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: 115200
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #5
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
# Try #6
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Try twice with upload engine from v4.1.4 (115200bps)
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
### Attempt twice with upload engine from v4.1.4 (115200bps)
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Setting baud rate"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute:
|
||||
id: set_baud_rate
|
||||
id: upload_tft_sequence_attempt_v414
|
||||
url: !lambda return url.c_str();
|
||||
baud_rate: 115200
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #7
|
||||
- script.execute:
|
||||
id: upload_tft_v414
|
||||
url: !lambda return url.c_str();
|
||||
- script.wait: upload_tft_v414
|
||||
- delay: 5s
|
||||
# Try #8
|
||||
- script.execute:
|
||||
id: upload_tft_v414
|
||||
url: !lambda return url.c_str();
|
||||
- script.wait: upload_tft_v414
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt_v414
|
||||
|
||||
### Exit reparse and try twice again
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
### Exit reparse and attempt twice again
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Exiting reparse mode"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute: exit_reparse
|
||||
- script.wait: exit_reparse
|
||||
- delay: 5s
|
||||
- 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
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: 115200
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #9
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
# Try #10
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Then try twice again at 9600bps
|
||||
- script.execute: nextion_status
|
||||
- script.wait: nextion_status
|
||||
### Then attempt twice again at 9600bps
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Setting baud rate"
|
||||
- script.wait: report_upload_progress
|
||||
- script.execute:
|
||||
id: set_baud_rate
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: 9600
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #11
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
# Try #12
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Restart Nextion and try twice again at default baud rate (115200bps)
|
||||
### Restart Nextion and attempt twice again at default baud rate (115200bps)
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
message: "Restarting Nextion display"
|
||||
@@ -540,26 +447,10 @@ script:
|
||||
- delay: 2s
|
||||
- switch.turn_on: screen_power
|
||||
- delay: 5s
|
||||
- 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
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: 115200
|
||||
definitive: false
|
||||
- script.wait: set_baud_rate
|
||||
- delay: 2s
|
||||
# Try #13
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
# Try #14
|
||||
- script.execute: upload_tft_try
|
||||
- script.wait: upload_tft_try
|
||||
- delay: 5s
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### All tries failed ###
|
||||
- script.execute:
|
||||
@@ -592,6 +483,63 @@ script:
|
||||
screen_power->publish_state(true);
|
||||
ESP_LOGE(TAG, "TFT upload finished unsuccessfully!");
|
||||
|
||||
- id: upload_tft_sequence_attempt
|
||||
mode: single
|
||||
parameters:
|
||||
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
|
||||
# First attempt
|
||||
- script.execute: upload_tft_attempt
|
||||
- script.wait: upload_tft_attempt
|
||||
- delay: 5s
|
||||
# Backup attempt
|
||||
- script.execute: upload_tft_attempt
|
||||
- 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:
|
||||
@@ -599,10 +547,10 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.script.upload_tft_v414";
|
||||
ESP_LOGD(TAG, "Trying to upload TFT");
|
||||
id(tft_upload_try)++;
|
||||
ESP_LOGD(TAG, "Attempting to upload TFT");
|
||||
id(tft_upload_attempt)++;
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Try #%d at %" PRIu32 " bps", id(tft_upload_try), tf_uart->get_baud_rate());
|
||||
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:
|
||||
@@ -725,7 +673,7 @@ script:
|
||||
#endif
|
||||
|
||||
is_updating_ = false;
|
||||
if (!completed) ESP_LOGD(TAG, "Nextion TFT upload will try again");
|
||||
if (!completed) ESP_LOGD(TAG, "Nextion TFT upload will attempt again");
|
||||
return completed;
|
||||
};
|
||||
|
||||
@@ -884,13 +832,13 @@ script:
|
||||
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
|
||||
// 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, retrying (%d/5)", url.c_str(),
|
||||
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s, reattempting (%d/5)", url.c_str(),
|
||||
HTTPClient::errorToString(code).c_str(), tries);
|
||||
|
||||
delay(250);
|
||||
@@ -966,8 +914,8 @@ script:
|
||||
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) { // Try a smaller size
|
||||
ESP_LOGD(TAG, "Could not allocate buffer size: %d trying 4096 instead", 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);
|
||||
@@ -1242,19 +1190,19 @@ script:
|
||||
|
||||
if (upload_tft_(url, 115200)) App.safe_reboot();
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Try #%d at %" PRIu32 " bps failed!", id(tft_upload_try), tf_uart->get_baud_rate());
|
||||
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_try
|
||||
- id: upload_tft_attempt
|
||||
mode: single
|
||||
then:
|
||||
- logger.log: "Trying to upload TFT"
|
||||
- lambda: !lambda id(tft_upload_try)++;
|
||||
- logger.log: "Attempting to upload TFT"
|
||||
- lambda: !lambda id(tft_upload_attempt)++;
|
||||
- lambda: |-
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Try #%d at %" PRIu32 " bps", id(tft_upload_try), tf_uart->get_baud_rate());
|
||||
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:
|
||||
@@ -1265,7 +1213,7 @@ script:
|
||||
- script.wait: nextion_upload
|
||||
- lambda: |-
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Try #%d at %" PRIu32 " bps failed!", id(tft_upload_try), tf_uart->get_baud_rate());
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps failed!", id(tft_upload_attempt), tf_uart->get_baud_rate());
|
||||
report_upload_progress->execute(update_msg);
|
||||
- script.wait: report_upload_progress
|
||||
|
||||
@@ -1314,5 +1262,12 @@ sensor:
|
||||
on_value:
|
||||
then:
|
||||
lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.sensor.display_mode";
|
||||
id(tft_is_valid) = (display_mode->state > 0 and display_mode->state < 4);
|
||||
if (id(tft_is_valid))
|
||||
ESP_LOGD(TAG, "Valid TFT: True");
|
||||
else {
|
||||
ESP_LOGW(TAG, "Display mode: %i", int(display_mode->state));
|
||||
ESP_LOGW(TAG, "Valid TFT: False");
|
||||
}
|
||||
...
|
||||
|
||||
@@ -2803,6 +2803,7 @@ script:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGE(TAG, "A non-compatible TFT is installed");
|
||||
ESP_LOGE(TAG, "Display mode: %f", display_mode->state);
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Nextion setup sequence finished!");
|
||||
|
||||
Reference in New Issue
Block a user