mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 18:54:14 +01:00
removed disconnecting state
This commit is contained in:
parent
c9f1ee0a62
commit
72119838d9
3 changed files with 94 additions and 49 deletions
|
@ -39,9 +39,6 @@ std::string state_to_string(ModemComponentState state) {
|
||||||
case ModemComponentState::CONNECTED:
|
case ModemComponentState::CONNECTED:
|
||||||
str = "CONNECTED";
|
str = "CONNECTED";
|
||||||
break;
|
break;
|
||||||
case ModemComponentState::DISCONNECTING:
|
|
||||||
str = "DISCONNECTING";
|
|
||||||
break;
|
|
||||||
case ModemComponentState::DISABLED:
|
case ModemComponentState::DISABLED:
|
||||||
str = "DISABLED";
|
str = "DISABLED";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -364,7 +364,9 @@ 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 bool connecting = false;
|
||||||
|
static bool disconnecting = false;
|
||||||
static uint8_t network_attach_retry = 10;
|
static uint8_t network_attach_retry = 10;
|
||||||
|
static uint8_t ip_lost_retries = 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
|
||||||
|
@ -410,6 +412,7 @@ void ModemComponent::loop() {
|
||||||
this->watchdog_.reset();
|
this->watchdog_.reset();
|
||||||
} else if (millis() - this->connect_begin_ > 15000) {
|
} 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...");
|
||||||
|
// TODO: exit data/cmux without error check
|
||||||
connecting = false;
|
connecting = false;
|
||||||
} else {
|
} else {
|
||||||
// Wait for IP from PPP event
|
// Wait for IP from PPP event
|
||||||
|
@ -478,19 +481,19 @@ void ModemComponent::loop() {
|
||||||
// break;
|
// break;
|
||||||
|
|
||||||
case ModemComponentState::CONNECTED:
|
case ModemComponentState::CONNECTED:
|
||||||
if (!this->start_) {
|
if (this->enabled_) {
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
if (!this->connected_) {
|
||||||
} else if (!this->connected_) {
|
|
||||||
this->status_set_warning("Connection via Modem lost!");
|
this->status_set_warning("Connection via Modem lost!");
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
}
|
}
|
||||||
break;
|
disconnecting = false;
|
||||||
|
} else {
|
||||||
case ModemComponentState::DISCONNECTING:
|
|
||||||
if (this->start_) {
|
|
||||||
if (this->connected_) {
|
if (this->connected_) {
|
||||||
// watchdog::WatchdogManager wdt(60000);
|
if (!disconnecting) {
|
||||||
ESP_LOGD(TAG, "Going to hang up...");
|
disconnecting = true;
|
||||||
|
ip_lost_retries = 10;
|
||||||
|
this->watchdog_ = std::make_shared<watchdog::WatchdogManager>(60000);
|
||||||
|
ESP_LOGD(TAG, "Disconnecting...");
|
||||||
this->dump_connect_params_();
|
this->dump_connect_params_();
|
||||||
if (this->cmux_) {
|
if (this->cmux_) {
|
||||||
assert(this->dce->set_mode(modem_mode::CMUX_MANUAL_COMMAND));
|
assert(this->dce->set_mode(modem_mode::CMUX_MANUAL_COMMAND));
|
||||||
|
@ -500,17 +503,11 @@ void ModemComponent::loop() {
|
||||||
}
|
}
|
||||||
delay(200); // NOLINT
|
delay(200); // NOLINT
|
||||||
ESP_LOGD(TAG, "Hanging up connection after %.1fmin", float(this->connect_begin_) / (1000 * 60));
|
ESP_LOGD(TAG, "Hanging up connection after %.1fmin", float(this->connect_begin_) / (1000 * 60));
|
||||||
ESPMODEM_ERROR_CHECK(this->dce->hang_up(), "Unable to hang up modem. Trying to continue anyway.");
|
ESPMODEM_ERROR_CHECK(this->dce->hang_up(),
|
||||||
|
"Unable to hang up modem. Trying to continue anyway."); // FIXME: needed ?
|
||||||
this->dump_connect_params_();
|
this->dump_connect_params_();
|
||||||
}
|
|
||||||
this->start_ = false;
|
|
||||||
} else if (!this->connected_) {
|
|
||||||
// ip lost as expected
|
|
||||||
this->cancel_timeout("wait_lost_ip");
|
|
||||||
ESP_LOGI(TAG, "Modem disconnected");
|
|
||||||
this->dump_connect_params_();
|
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
|
||||||
} else {
|
} else {
|
||||||
|
// disconnecting
|
||||||
// Waiting for IP_EVENT_PPP_LOST_IP.
|
// Waiting for IP_EVENT_PPP_LOST_IP.
|
||||||
// This can take a long time, so we ckeck the IP addr, and trigger the event manualy if it's null.
|
// This can take a long time, so we ckeck the IP addr, and trigger the event manualy if it's null.
|
||||||
esp_netif_ip_info_t ip_info;
|
esp_netif_ip_info_t ip_info;
|
||||||
|
@ -519,16 +516,70 @@ void ModemComponent::loop() {
|
||||||
// lost IP
|
// lost IP
|
||||||
esp_event_post(IP_EVENT, IP_EVENT_PPP_LOST_IP, nullptr, 0, 0);
|
esp_event_post(IP_EVENT, IP_EVENT_PPP_LOST_IP, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP_LOGD(TAG, "Waiting for lost IP... (retries %" PRIu8 ")", ip_lost_retries);
|
||||||
|
ip_lost_retries--;
|
||||||
|
if (ip_lost_retries == 0) {
|
||||||
|
// Something goes wrong, we have still an IP
|
||||||
|
ESP_LOGE(TAG, "No IP lost event recieved. Sending one manually");
|
||||||
|
esp_event_post(IP_EVENT, IP_EVENT_PPP_LOST_IP, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next_loop_millis = millis() + 2000; // delay for next loop
|
||||||
|
}
|
||||||
|
} else { // if (this->connected_)
|
||||||
|
// ip lost as expected
|
||||||
|
ESP_LOGI(TAG, "PPPoS disconnected");
|
||||||
|
this->dump_connect_params_();
|
||||||
|
this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// case ModemComponentState::DISCONNECTING:
|
||||||
|
// if (this->start_) {
|
||||||
|
// if (this->connected_) {
|
||||||
|
// // watchdog::WatchdogManager wdt(60000);
|
||||||
|
// ESP_LOGD(TAG, "Going to hang up...");
|
||||||
|
// this->dump_connect_params_();
|
||||||
|
// if (this->cmux_) {
|
||||||
|
// assert(this->dce->set_mode(modem_mode::CMUX_MANUAL_COMMAND));
|
||||||
|
// } else {
|
||||||
|
// // assert(this->dce->set_mode(modem_mode::COMMAND_MODE)); // OK on 7600, nok on 7670...
|
||||||
|
// this->dce->set_mode(modem_mode::COMMAND_MODE);
|
||||||
|
// }
|
||||||
|
// delay(200); // NOLINT
|
||||||
|
// ESP_LOGD(TAG, "Hanging up connection after %.1fmin", float(this->connect_begin_) / (1000 * 60));
|
||||||
|
// ESPMODEM_ERROR_CHECK(this->dce->hang_up(), "Unable to hang up modem. Trying to continue anyway.");
|
||||||
|
// this->dump_connect_params_();
|
||||||
|
// }
|
||||||
|
// this->start_ = false;
|
||||||
|
// } else if (!this->connected_) {
|
||||||
|
// // ip lost as expected
|
||||||
|
// this->cancel_timeout("wait_lost_ip");
|
||||||
|
// ESP_LOGI(TAG, "Modem disconnected");
|
||||||
|
// this->dump_connect_params_();
|
||||||
|
// this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
|
// } else {
|
||||||
|
// // Waiting for IP_EVENT_PPP_LOST_IP.
|
||||||
|
// // This can take a long time, so we ckeck the IP addr, and trigger the event manualy if it's null.
|
||||||
|
// esp_netif_ip_info_t ip_info;
|
||||||
|
// esp_netif_get_ip_info(this->ppp_netif_, &ip_info);
|
||||||
|
// if (ip_info.ip.addr == 0) {
|
||||||
|
// // lost IP
|
||||||
|
// esp_event_post(IP_EVENT, IP_EVENT_PPP_LOST_IP, nullptr, 0, 0);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
|
||||||
case ModemComponentState::DISABLED:
|
case ModemComponentState::DISABLED:
|
||||||
if (this->enabled_) {
|
if (this->enabled_) {
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
} else if (this->get_power_status()) { // FIXME long time in loop because of get_power_status
|
} // else if (this->get_power_status()) { // FIXME long time in loop because of get_power_status
|
||||||
this->poweroff_();
|
// this->poweroff_();
|
||||||
}
|
//}
|
||||||
|
next_loop_millis = millis() + 2000; // delay for next loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,9 +604,7 @@ void ModemComponent::enable() {
|
||||||
void ModemComponent::disable() {
|
void ModemComponent::disable() {
|
||||||
ESP_LOGD(TAG, "Disabling modem");
|
ESP_LOGD(TAG, "Disabling modem");
|
||||||
this->enabled_ = false;
|
this->enabled_ = false;
|
||||||
if (this->state_ == ModemComponentState::CONNECTED) {
|
if (this->state_ != ModemComponentState::CONNECTED) {
|
||||||
this->state_ = ModemComponentState::DISCONNECTING;
|
|
||||||
} else {
|
|
||||||
this->state_ = ModemComponentState::DISCONNECTED;
|
this->state_ = ModemComponentState::DISCONNECTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ enum class ModemComponentState {
|
||||||
NOT_RESPONDING,
|
NOT_RESPONDING,
|
||||||
DISCONNECTED,
|
DISCONNECTED,
|
||||||
CONNECTED,
|
CONNECTED,
|
||||||
DISCONNECTING,
|
|
||||||
DISABLED,
|
DISABLED,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue