ESPHome Watchdog
This implements a watchdog script with complementing the scripts `on_setup` and `refresh_wifi_icon` to be checking the components every minute and taking proper actions (when possible). Solves #1464
This commit is contained in:
@@ -71,6 +71,8 @@ script:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.upload_tft_new";
|
||||
ESP_LOGVV(TAG, "Starting...");
|
||||
id(is_uploading_tft) = true;
|
||||
|
||||
nextion_status->execute();
|
||||
|
||||
auto delay_seconds_ = [](int seconds) {
|
||||
@@ -187,6 +189,7 @@ script:
|
||||
delay_seconds_(2);
|
||||
App.safe_reboot();
|
||||
|
||||
id(is_uploading_tft) = false;
|
||||
ESP_LOGD(TAG, "Finished!");
|
||||
|
||||
- id: upload_tft
|
||||
@@ -197,6 +200,8 @@ script:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.upload_tft";
|
||||
ESP_LOGD(TAG, "Starting...");
|
||||
id(is_uploading_tft) = true;
|
||||
|
||||
char update_msg[128];
|
||||
|
||||
auto delay_seconds_ = [](int seconds) {
|
||||
@@ -226,9 +231,9 @@ script:
|
||||
auto send_nextion_command = [](const std::string &command) -> bool {
|
||||
static const char *const TAG = "script.upload_tft.send_nextion_command";
|
||||
ESP_LOGD(TAG, "Sending: %s", command.c_str());
|
||||
id(tf_uart).write_str(command.c_str());
|
||||
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));
|
||||
tf_uart->write_array(to_send, sizeof(to_send));
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -285,15 +290,15 @@ script:
|
||||
|
||||
start = millis();
|
||||
|
||||
while ((timeout == 0 && id(tf_uart).available()) || millis() - start <= timeout)
|
||||
while ((timeout == 0 && tf_uart->available()) || millis() - start <= timeout)
|
||||
{
|
||||
if (!id(tf_uart).available())
|
||||
if (!tf_uart->available())
|
||||
{
|
||||
App.feed_wdt();
|
||||
continue;
|
||||
}
|
||||
|
||||
id(tf_uart).read_byte(&c);
|
||||
tf_uart->read_byte(&c);
|
||||
if (c == 0xFF)
|
||||
{
|
||||
nr_of_ff_bytes++;
|
||||
@@ -424,7 +429,7 @@ script:
|
||||
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);
|
||||
tf_uart->write_array(&transfer_buffer_[i], write_len);
|
||||
content_length_ -= write_len;
|
||||
ESP_LOGD(TAG, "Uploaded %0.1f %%, remaining %d bytes, heap: %d",
|
||||
100.0 * (tft_size_ - content_length_) / tft_size_,
|
||||
@@ -543,19 +548,19 @@ script:
|
||||
// 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());
|
||||
ESP_LOGD(TAG, "Clear serial receive buffer: %d", tf_uart->available());
|
||||
// Clear serial receive buffer
|
||||
uint8_t d;
|
||||
while (id(tf_uart).available()) {
|
||||
id(tf_uart).read_byte(&d);
|
||||
while (tf_uart->available()) {
|
||||
tf_uart->read_byte(&d);
|
||||
};
|
||||
|
||||
send_nextion_command(command);
|
||||
|
||||
if (update_baud_rate_ != id(tf_uart).get_baud_rate()) {
|
||||
if (update_baud_rate_ != tf_uart->get_baud_rate()) {
|
||||
set_baud_rate_(update_baud_rate_);
|
||||
//id(tf_uart).set_baud_rate(update_baud_rate_);
|
||||
//id(tf_uart).setup();
|
||||
//tf_uart->set_baud_rate(update_baud_rate_);
|
||||
//tf_uart->setup();
|
||||
//delay_seconds_(2);
|
||||
}
|
||||
|
||||
@@ -809,16 +814,16 @@ script:
|
||||
|
||||
// Clear serial receive buffer
|
||||
uint8_t d;
|
||||
while (id(tf_uart).available()) {
|
||||
id(tf_uart).read_byte(&d);
|
||||
while (tf_uart->available()) {
|
||||
tf_uart->read_byte(&d);
|
||||
};
|
||||
|
||||
send_nextion_command(command);
|
||||
|
||||
if (update_baud_rate_ != id(tf_uart).get_baud_rate()) {
|
||||
if (update_baud_rate_ != tf_uart->get_baud_rate()) {
|
||||
set_baud_rate_(update_baud_rate_);
|
||||
//id(tf_uart).set_baud_rate(update_baud_rate_);
|
||||
//id(tf_uart).setup();
|
||||
//tf_uart->set_baud_rate(update_baud_rate_);
|
||||
//tf_uart->setup();
|
||||
}
|
||||
|
||||
std::string response;
|
||||
@@ -1019,6 +1024,7 @@ script:
|
||||
delay_seconds_(2);
|
||||
App.safe_reboot();
|
||||
|
||||
id(is_uploading_tft) = false;
|
||||
ESP_LOGD(TAG, "Finished!");
|
||||
|
||||
select:
|
||||
|
||||
Reference in New Issue
Block a user