mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 01:34:18 +01:00
removed connecting state
This commit is contained in:
parent
4f74cec977
commit
c9f1ee0a62
3 changed files with 75 additions and 42 deletions
|
@ -36,9 +36,6 @@ std::string state_to_string(ModemComponentState state) {
|
||||||
case ModemComponentState::DISCONNECTED:
|
case ModemComponentState::DISCONNECTED:
|
||||||
str = "DISCONNECTED";
|
str = "DISCONNECTED";
|
||||||
break;
|
break;
|
||||||
case ModemComponentState::CONNECTING:
|
|
||||||
str = "CONNECTING";
|
|
||||||
break;
|
|
||||||
case ModemComponentState::CONNECTED:
|
case ModemComponentState::CONNECTED:
|
||||||
str = "CONNECTED";
|
str = "CONNECTED";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -242,11 +242,14 @@ void ModemComponent::create_dte_dce_() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Connected to the modem in %" PRIu32 "ms", elapsed_ms);
|
ESP_LOGD(TAG, "Connected to the modem in %" PRIu32 "ms", elapsed_ms);
|
||||||
this->send_init_at_();
|
}
|
||||||
if (!this->prepare_sim_()) {
|
}
|
||||||
// fatal error
|
|
||||||
this->disable();
|
if (this->modem_ready()) {
|
||||||
}
|
this->send_init_at_();
|
||||||
|
if (!this->prepare_sim_()) {
|
||||||
|
// fatal error
|
||||||
|
this->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,8 +362,9 @@ void ModemComponent::ip_event_handler(void *arg, esp_event_base_t event_base, in
|
||||||
|
|
||||||
void ModemComponent::loop() {
|
void ModemComponent::loop() {
|
||||||
static ModemComponentState last_state = this->state_;
|
static ModemComponentState last_state = this->state_;
|
||||||
|
|
||||||
static uint32_t next_loop_millis = millis();
|
static uint32_t next_loop_millis = millis();
|
||||||
|
static bool connecting = false;
|
||||||
|
static uint8_t network_attach_retry = 10;
|
||||||
|
|
||||||
if (this->power_transition_ || (millis() < next_loop_millis)) {
|
if (this->power_transition_ || (millis() < next_loop_millis)) {
|
||||||
// No loop on power transition, or if some commands need some delay
|
// No loop on power transition, or if some commands need some delay
|
||||||
|
@ -395,19 +399,52 @@ void ModemComponent::loop() {
|
||||||
case ModemComponentState::DISCONNECTED:
|
case ModemComponentState::DISCONNECTED:
|
||||||
if (this->enabled_) {
|
if (this->enabled_) {
|
||||||
if (this->start_) {
|
if (this->start_) {
|
||||||
if (is_network_attached_()) {
|
if (connecting) {
|
||||||
if (this->start_connect_()) {
|
if (this->connected_) {
|
||||||
this->state_ = ModemComponentState::CONNECTING;
|
connecting = false;
|
||||||
} else if (!this->modem_ready()) {
|
ESP_LOGI(TAG, "Connected via Modem");
|
||||||
if (this->power_pin_) {
|
this->state_ = ModemComponentState::CONNECTED;
|
||||||
this->poweron_();
|
|
||||||
} else {
|
this->dump_connect_params_();
|
||||||
this->state_ = ModemComponentState::NOT_RESPONDING;
|
this->status_clear_warning();
|
||||||
}
|
this->watchdog_.reset();
|
||||||
|
} else if (millis() - this->connect_begin_ > 15000) {
|
||||||
|
ESP_LOGW(TAG, "Connecting via Modem failed! Re-connecting...");
|
||||||
|
connecting = false;
|
||||||
|
} else {
|
||||||
|
// Wait for IP from PPP event
|
||||||
|
next_loop_millis = millis() + 1000; // delay for next loop
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
ESP_LOGD(TAG, "Waiting for the modem to be attached to a network");
|
if (is_network_attached_()) {
|
||||||
next_loop_millis = millis() + 1000; // delay to retry
|
network_attach_retry = 10;
|
||||||
|
if (this->start_connect_()) {
|
||||||
|
connecting = true;
|
||||||
|
next_loop_millis = millis() + 1000; // delay for next loop
|
||||||
|
// this->state_ = ModemComponentState::CONNECTING;
|
||||||
|
} else if (!this->modem_ready()) {
|
||||||
|
if (this->power_pin_) {
|
||||||
|
this->poweron_();
|
||||||
|
} else {
|
||||||
|
this->state_ = ModemComponentState::NOT_RESPONDING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGD(TAG, "Waiting for the modem to be attached to a network (left retries: %" PRIu8 ")",
|
||||||
|
network_attach_retry);
|
||||||
|
network_attach_retry--;
|
||||||
|
if (network_attach_retry == 0) {
|
||||||
|
ESP_LOGE(TAG, "modem is uanble to attach to a network");
|
||||||
|
if (this->power_pin_) {
|
||||||
|
this->poweroff_();
|
||||||
|
} else {
|
||||||
|
// fatal error ?
|
||||||
|
this->start_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next_loop_millis = millis() + 1000; // delay to retry
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this->start_ = true;
|
this->start_ = true;
|
||||||
}
|
}
|
||||||
|
@ -417,28 +454,28 @@ void ModemComponent::loop() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ModemComponentState::CONNECTING:
|
// case ModemComponentState::CONNECTING:
|
||||||
if (!this->start_) {
|
// if (!this->start_) {
|
||||||
ESP_LOGI(TAG, "Stopped modem connection");
|
// ESP_LOGI(TAG, "Stopped modem connection");
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
// this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
} else if (this->connected_) {
|
// } else if (this->connected_) {
|
||||||
ESP_LOGI(TAG, "Connected via Modem");
|
// ESP_LOGI(TAG, "Connected via Modem");
|
||||||
this->state_ = ModemComponentState::CONNECTED;
|
// this->state_ = ModemComponentState::CONNECTED// ;
|
||||||
|
|
||||||
this->dump_connect_params_();
|
// this->dump_connect_params_();
|
||||||
this->status_clear_warning();
|
// this->status_clear_warning();
|
||||||
this->watchdog_.reset();
|
// this->watchdog_.reset()// ;
|
||||||
|
|
||||||
} else if (millis() - this->connect_begin_ > 45000) {
|
// } else if (millis() - this->connect_begin_ > 15000) {
|
||||||
ESP_LOGW(TAG, "Connecting via Modem failed! Re-connecting...");
|
// ESP_LOGW(TAG, "Connecting via Modem failed! Re-connecting...");
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
// this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
} else {
|
// } else {
|
||||||
// ESP_LOGD(TAG, "Connecting...");
|
// // ESP_LOGD(TAG, "Connecting...");
|
||||||
App.feed_wdt();
|
// App.feed_wdt();
|
||||||
App.get_app_state();
|
// App.get_app_state();
|
||||||
// yield();
|
// // yield();
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
case ModemComponentState::CONNECTED:
|
case ModemComponentState::CONNECTED:
|
||||||
if (!this->start_) {
|
if (!this->start_) {
|
||||||
|
|
|
@ -34,7 +34,6 @@ static const char *const TAG = "modem";
|
||||||
enum class ModemComponentState {
|
enum class ModemComponentState {
|
||||||
NOT_RESPONDING,
|
NOT_RESPONDING,
|
||||||
DISCONNECTED,
|
DISCONNECTED,
|
||||||
CONNECTING,
|
|
||||||
CONNECTED,
|
CONNECTED,
|
||||||
DISCONNECTING,
|
DISCONNECTING,
|
||||||
DISABLED,
|
DISABLED,
|
||||||
|
|
Loading…
Reference in a new issue