From 0339726a730cd8a5eec8419b22747b9b42308c6f Mon Sep 17 00:00:00 2001 From: Chelios Date: Tue, 15 Oct 2024 06:48:55 +0300 Subject: [PATCH] add check pins in dump_config --- esphome/components/modem/modem_component.cpp | 21 +++++++++++++------- esphome/components/modem/modem_component.h | 6 +++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/esphome/components/modem/modem_component.cpp b/esphome/components/modem/modem_component.cpp index aac76ee814..ab73ae9d36 100644 --- a/esphome/components/modem/modem_component.cpp +++ b/esphome/components/modem/modem_component.cpp @@ -47,7 +47,9 @@ void ModemComponent::setup() { if (this->pwrkey_pin_) { this->pwrkey_pin_->setup(); } - this->reset_pin_->setup(); + if (this->reset_pin_) { + this->reset_pin_->setup(); + } if (esp_reset_reason() != ESP_RST_DEEPSLEEP) { // Delay here to allow power to stabilise before Modem is initialized. delay(300); // NOLINT @@ -85,7 +87,7 @@ void ModemComponent::loop() { } } else { ESP_LOGD(TAG, "Can't turn on modem power pin because it is not configured, go to turn on pwrkey"); - this->set_state(ModemComponentState::TURNING_ON_PWRKEY); + this->set_state(ModemComponentState::TURNING_ON_RESET); } this->dce_init(); break; @@ -105,9 +107,10 @@ void ModemComponent::loop() { this->set_state(ModemComponentState::TURNING_OFF_PWRKEY); } else { ESP_LOGD(TAG, "Can't turn on pwrkey pin because it is not configured, go to reset power modem"); - this->set_state(ModemComponentState::TURNING_ON_RESET); + this->set_state(ModemComponentState::TURNING_ON_POWER); break; } + this->dce_init(); break; // The state releases the power key @@ -125,8 +128,10 @@ void ModemComponent::loop() { this->set_state(ModemComponentState::TURNING_OFF_RESET); } else { ESP_LOGD(TAG, "Can't turn on reset pin because it is not configured, go to turn on pwkey"); - this->set_state(ModemComponentState::TURNING_ON_PWRKEY); + this->set_state(ModemComponentState::TURNING_OFF_POWER); + break; } + this->dce_init(); break; // The state of the end of the reset of the modem @@ -211,7 +216,8 @@ bool ModemComponent::check_modem_component_state_timings() { ModemComponentStateTiming timing = this->modemComponentStateTimingMap[this->state_]; if (timing.time_limit && ((this->change_state_ + timing.time_limit) < now)) { ESP_LOGE(TAG, "State time limit %s", this->state_to_string(this->state_)); - this->turn_on_reset(); + this->set_state(ModemComponentState::TURNING_ON_RESET); + return true; } if (!timing.poll_period) { return true; @@ -261,8 +267,9 @@ void ModemComponent::dump_config() { this->dump_connect_params(); ESP_LOGCONFIG(TAG, "Modem:"); ESP_LOGCONFIG(TAG, " Type: %d", this->type_); - ESP_LOGCONFIG(TAG, " Reset Pin: %u", this->reset_pin_->get_pin()); ESP_LOGCONFIG(TAG, " Power pin : %s", (this->power_pin_) ? this->power_pin_->dump_summary().c_str() : "Not defined"); + ESP_LOGCONFIG(TAG, " Reset pin : %s", (this->reset_pin_) ? this->reset_pin_->dump_summary().c_str() : "Not defined"); + ESP_LOGCONFIG(TAG, " Pwrkey pin : %s", (this->pwrkey_pin_) ? this->pwrkey_pin_->dump_summary().c_str() : "Not defined"); ESP_LOGCONFIG(TAG, " APN: %s", this->apn_.c_str()); ESP_LOGCONFIG(TAG, " TX Pin: %d", this->tx_pin_); ESP_LOGCONFIG(TAG, " RX Pin: %d", this->rx_pin_); @@ -338,7 +345,7 @@ void ModemComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base ESP_LOGD(TAG, "GOT ip event!!!"); } else if (event_id == IP_EVENT_PPP_LOST_IP) { ESP_LOGD(TAG, "Modem Disconnect from PPP Server"); - global_modem_component->turn_on_reset(); + global_modem_component->set_state(ModemComponentState::TURNING_ON_RESET); } } diff --git a/esphome/components/modem/modem_component.h b/esphome/components/modem/modem_component.h index 3d04d7e4bb..b9aa0b62da 100644 --- a/esphome/components/modem/modem_component.h +++ b/esphome/components/modem/modem_component.h @@ -77,14 +77,14 @@ class ModemComponent : public Component { std::map modemComponentStateTimingMap = { {ModemComponentState::TURNING_ON_POWER, ModemComponentStateTiming(2000, 0)}, {ModemComponentState::TURNING_OFF_POWER, ModemComponentStateTiming(2000, 0)}, - {ModemComponentState::TURNING_ON_PWRKEY, ModemComponentStateTiming(0, 0)}, + {ModemComponentState::TURNING_ON_PWRKEY, ModemComponentStateTiming(2000, 0)}, {ModemComponentState::TURNING_OFF_PWRKEY, ModemComponentStateTiming(2000, 0)}, - {ModemComponentState::TURNING_ON_RESET, ModemComponentStateTiming(0, 0)}, + {ModemComponentState::TURNING_ON_RESET, ModemComponentStateTiming(2000, 0)}, {ModemComponentState::TURNING_OFF_RESET, ModemComponentStateTiming(2000, 0)}, {ModemComponentState::SYNC, ModemComponentStateTiming(2000, 15000)}, {ModemComponentState::REGISTRATION_IN_NETWORK, ModemComponentStateTiming(2000, 15000)}, {ModemComponentState::CONNECTING, ModemComponentStateTiming(2000, 15000)}, - {ModemComponentState::CONNECTED, ModemComponentStateTiming(0, 0)}, + {ModemComponentState::CONNECTED, ModemComponentStateTiming(5000, 0)}, }; static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data);