Skip to content

Commit

Permalink
Update IDF TFT upload script
Browse files Browse the repository at this point in the history
This improves (but still doesn't fix) the esp crashing during the upload process.
It appears like the esp_http_client_read() function is causing a watchdog reset while waiting for something. Maybe due to not handling unexpected connection close? The connection reliability may be a factor.
```
[D][nspanel_lovelace_upload:142]: Uploaded 42.20%, remaining 4741340 bytes, free heap: 35812 (DRAM) + 0 (PSRAM) bytes
[D][nspanel_lovelace_upload:039]: HTTP_EVENT_ON_DATA, len=96
[D][nspanel_lovelace_upload:039]: HTTP_EVENT_ON_DATA, len=512
[D][nspanel_lovelace_upload:039]: HTTP_EVENT_ON_DATA, len=512
[D][nspanel_lovelace_upload:039]: HTTP_EVENT_ON_DATA, len=416
E (138838) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (138838) task_wdt:  - loopTask (CPU 1)
E (138838) task_wdt: Tasks currently running:
E (138838) task_wdt: CPU 0: IDLE0
E (138838) task_wdt: CPU 1: IDLE1
E (138838) task_wdt: Aborting.

abort() was called at PC 0x40105c20 on core 0

Backtrace: 0x40082b4d:0x3ffb0870 0x4008e4c9:0x3ffb0890 0x400947b5:0x3ffb08b0 0x40105c20:0x3ffb0920 0x400834f5:0x3ffb0940 0x401858fb:0x3ffcbeb0 0x401063bd:0x3ffcbed0 0x4008f954:0x3ffcbef0
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x40082b4d: panic_abort at D:/.platformio/packages/framework-espidf@3.40407.240606/components/esp_system/panic.c:408
WARNING Decoded 0x4008e4c9: esp_system_abort at D:/.platformio/packages/framework-espidf@3.40407.240606/components/esp_system/esp_system.c:137
WARNING Decoded 0x400947b5: abort at D:\.platformio\packages\framework-espidf@3.40407.240606\components\newlib/abort.c:46
WARNING Decoded 0x40105c20: task_wdt_isr at D:/.platformio/packages/framework-espidf@3.40407.240606/components/esp_system/task_wdt.c:176 (discriminator 3)
WARNING Decoded 0x400834f5: _xt_lowint1 at D:\.platformio\packages\framework-espidf@3.40407.240606\components\freertos\port\xtensa/xtensa_vectors.S:1118
WARNING Decoded 0x401858fb: cpu_ll_waiti at D:\.platformio\packages\framework-espidf@3.40407.240606\components\hal\esp32\include/hal/cpu_ll.h:183
 (inlined by) esp_pm_impl_waiti at D:\.platformio\packages\framework-espidf@3.40407.240606\components\esp_pm/pm_impl.c:853
WARNING Decoded 0x401063bd: esp_vApplicationIdleHook at D:/.platformio/packages/framework-espidf@3.40407.240606/components/esp_system/freertos_hooks.c:63
WARNING Decoded 0x4008f954: prvIdleTask at D:\.platformio\packages\framework-espidf@3.40407.240606\components\freertos/tasks.c:4099
```
  • Loading branch information
olicooper committed Aug 1, 2024
1 parent 56c18c8 commit 28c4a4c
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 211 deletions.
22 changes: 12 additions & 10 deletions components/nspanel_lovelace/nspanel_lovelace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,17 +1261,19 @@ uint16_t NSPanelLovelace::recv_ret_string_(std::string &response, uint32_t timeo
#endif
}

void NSPanelLovelace::start_reparse_mode_() {
this->send_nextion_command_("DRAKJHSUYDGBNCJHGJKSHBDN");
this->send_nextion_command_("recmod=0");
this->send_nextion_command_("recmod=0");
this->send_nextion_command_("connect");
reparse_mode_ = true;
}
void NSPanelLovelace::set_reparse_mode_(bool active) {
if (this->reparse_mode_ == active) return;

if (active) {
this->send_nextion_command_("recmod=1");
} else {
this->send_nextion_command_("DRAKJHSUYDGBNCJHGJKSHBDN");
this->send_nextion_command_("recmod=0");
this->send_nextion_command_("recmod=0");
this->send_nextion_command_("connect");
}

void NSPanelLovelace::exit_reparse_mode_() {
this->send_nextion_command_("recmod=1");
reparse_mode_ = false;
this->reparse_mode_ = active;
}
#endif // USE_NSPANEL_TFT_UPLOAD

Expand Down
18 changes: 10 additions & 8 deletions components/nspanel_lovelace/nspanel_lovelace.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#ifdef USE_ESP_IDF
#include "esphome/components/uart/uart_component_esp_idf.h"
#ifdef USE_NSPANEL_TFT_UPLOAD
#include <esp_http_client.h>
#endif
#else
#ifdef USE_NSPANEL_TFT_UPLOAD
#include <HTTPClient.h>
Expand Down Expand Up @@ -148,8 +151,7 @@ class NSPanelLovelace : public Component, public uart::UARTDevice, protected api
void init_display_(int baud_rate);
#ifdef USE_NSPANEL_TFT_UPLOAD
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag);
void start_reparse_mode_();
void exit_reparse_mode_();
void set_reparse_mode_(bool active);
#endif
void send_nextion_command_(const std::string &command);

Expand Down Expand Up @@ -230,7 +232,6 @@ class NSPanelLovelace : public Component, public uart::UARTDevice, protected api

std::queue<std::string> command_queue_;
unsigned long command_last_sent_ = 0;
unsigned int update_baud_rate_ = 921600;

bool button_press_timeout_set_ = false;
std::string button_press_uuid_;
Expand All @@ -254,17 +255,18 @@ class NSPanelLovelace : public Component, public uart::UARTDevice, protected api
std::string command_buffer_;

#ifdef USE_NSPANEL_TFT_UPLOAD
unsigned int update_baud_rate_ = 921600;
bool is_updating_ = false;
bool reparse_mode_ = false;
int content_length_ = 0;
int tft_size_ = 0;
uint32_t content_length_ = 0;
size_t tft_size_ = 0;
bool upload_first_chunk_sent_ = false;
#ifdef USE_ESP_IDF
int upload_range_(const std::string &url, int range_start);
int upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &range_start);
#else // USE_ARDUINO
uint8_t *transfer_buffer_ = nullptr;
size_t transfer_buffer_size_;
bool upload_first_chunk_sent_ = false;
int upload_by_chunks_(HTTPClient *http, const std::string &url, int range_start);
int upload_by_chunks_(HTTPClient *http, const std::string &url, uint32_t &range_start);
#endif
bool upload_end_(bool successful);
#endif // USE_NSPANEL_TFT_UPLOAD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const char *const TAG = "nspanel_lovelace_upload";
// Originally from: https://github.com/sairon/esphome-nspanel-lovelace-ui/blob/dev/components/nspanel_lovelace/nspanel_lovelace_upload.cpp
// Followed guide: https://unofficialnextion.com/t/nextion-upload-protocol-v1-2-the-fast-one/1044/2

int NSPanelLovelace::upload_by_chunks_(HTTPClient *http, const std::string &url, int range_start) {
int NSPanelLovelace::upload_by_chunks_(HTTPClient *http, const std::string &url, uint32_t &range_start) {
int range_end;

if (range_start == 0 && this->transfer_buffer_size_ > 16384) { // Start small at the first run in case of a big skip
Expand Down Expand Up @@ -139,9 +139,7 @@ bool NSPanelLovelace::upload_tft(const std::string &url) {
return false;
}

if (!this->reparse_mode_) {
this->start_reparse_mode_();
}
this->set_reparse_mode_(false);

this->is_updating_ = true;

Expand Down Expand Up @@ -266,7 +264,7 @@ bool NSPanelLovelace::upload_tft(const std::string &url) {
ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d",
url.c_str(), this->content_length_, this->transfer_buffer_size_, ESP.getFreeHeap());

int result = 0;
uint32_t result = 0;
while (this->content_length_ > 0) {
result = this->upload_by_chunks_(&http, url, result);
if (result < 0) {
Expand Down
Loading

0 comments on commit 28c4a4c

Please sign in to comment.