diff --git a/esphome/components/modem/__init__.py b/esphome/components/modem/__init__.py index 27ddcd7c40..f264bcf348 100644 --- a/esphome/components/modem/__init__.py +++ b/esphome/components/modem/__init__.py @@ -7,6 +7,7 @@ from esphome.components.esp32 import add_idf_component, add_idf_sdkconfig_option # from esphome.components.wifi import wifi_has_sta # uncomment after PR#4091 merged import esphome.config_validation as cv from esphome.const import ( + CONF_DEBUG, CONF_ENABLE_ON_BOOT, CONF_ID, CONF_MODEL, @@ -81,6 +82,7 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_INIT_AT): cv.All(cv.ensure_list(cv.string)), cv.Optional(CONF_ENABLE_ON_BOOT, default=True): cv.boolean, cv.Optional(CONF_ENABLE_CMUX, default=False): cv.boolean, + cv.Optional(CONF_DEBUG, default=False): cv.boolean, # needs also cv.Optional(CONF_ENABLE_GNSS, default=False): cv.boolean, cv.Optional(CONF_ON_NOT_RESPONDING): automation.validate_automation( { @@ -186,6 +188,9 @@ async def to_code(config): if config[CONF_ENABLE_GNSS]: cg.add(var.enable_gnss()) + if config[CONF_DEBUG]: + cg.add(var.enable_debug()) + if init_at := config.get(CONF_INIT_AT, None): for cmd in init_at: cg.add(var.add_init_at_command(cmd)) diff --git a/esphome/components/modem/modem_component.h b/esphome/components/modem/modem_component.h index 29b1888a03..6c0d3ce0dc 100644 --- a/esphome/components/modem/modem_component.h +++ b/esphome/components/modem/modem_component.h @@ -60,6 +60,8 @@ class ModemComponent : public Component { void set_apn(const std::string &apn) { this->apn_ = apn; } void set_not_responding_cb(Trigger<> *not_responding_cb) { this->not_responding_cb_ = not_responding_cb; } void enable_cmux() { this->cmux_ = true; } + void enable_gnss() { this->gnss_ = true; } + void enable_debug() { esp_log_level_set("command_lib", ESP_LOG_VERBOSE); } void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); } bool is_connected() { return this->component_state_ == ModemComponentState::CONNECTED; } bool is_disabled() { return this->component_state_ == ModemComponentState::DISABLED; } @@ -120,6 +122,7 @@ class ModemComponent : public Component { std::vector init_at_commands_; std::string use_address_; bool cmux_{false}; + bool gnss_{false}; // separate handler for `on_not_responding` (we want to know when it's ended) Trigger<> *not_responding_cb_{nullptr}; CallbackManager on_state_callback_; @@ -130,7 +133,7 @@ class ModemComponent : public Component { uint8_t uart_event_queue_size_ = 30; // 10-40 size_t uart_event_task_stack_size_ = 2048; // 2000-6000 uint8_t uart_event_task_priority_ = 5; // 3-22 - uint32_t command_delay_ = 500; // timeout for AT commands + uint32_t command_delay_ = 10000; // timeout for AT commands uint32_t update_interval_ = 60 * 1000; // Changes will trigger user callback @@ -141,9 +144,6 @@ class ModemComponent : public Component { std::shared_ptr dte_{nullptr}; esp_netif_t *ppp_netif_{nullptr}; - // Many operation blocks a long time. - std::shared_ptr watchdog_; - struct InternalState { bool start{false}; bool enabled{false};