mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
allow reconnect
This commit is contained in:
parent
c4705967bd
commit
0b6708ddbe
2 changed files with 20 additions and 2 deletions
|
@ -153,6 +153,17 @@ void ModemComponent::disable() {
|
|||
}
|
||||
}
|
||||
|
||||
void ModemComponent::reconnect() {
|
||||
if (!this->internal_state_.reconnect) {
|
||||
this->internal_state_.reconnect = true;
|
||||
this->component_state_ = ModemComponentState::NOT_RESPONDING;
|
||||
// if reconnect fail, let some time before retry
|
||||
set_timeout(120000, [this]() { this->internal_state_.reconnect = false; });
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Reconnecting already in progress.");
|
||||
}
|
||||
}
|
||||
|
||||
network::IPAddresses ModemComponent::get_ip_addresses() {
|
||||
network::IPAddresses addresses;
|
||||
esp_netif_ip_info_t ip;
|
||||
|
@ -233,7 +244,6 @@ void ModemComponent::loop() {
|
|||
static uint32_t last_health_check = millis();
|
||||
static bool connecting = false;
|
||||
static uint8_t network_attach_retry = 10;
|
||||
static uint8_t ip_lost_retries = 10;
|
||||
|
||||
if ((millis() < next_loop_millis)) {
|
||||
// some commands need some delay
|
||||
|
@ -380,7 +390,12 @@ void ModemComponent::loop() {
|
|||
if (!this->internal_state_.connected) {
|
||||
this->status_set_warning("Connection via Modem lost!");
|
||||
this->component_state_ = ModemComponentState::DISCONNECTED;
|
||||
} else if (this->cmux_ && (millis() - last_health_check) > 30000) {
|
||||
break;
|
||||
}
|
||||
// clear flags if previously set by this->reconnect()
|
||||
this->internal_state_.reconnect = false;
|
||||
|
||||
if (this->cmux_ && (millis() - last_health_check) > 30000) {
|
||||
ESP_LOGD(TAG, "modem health check");
|
||||
last_health_check = millis();
|
||||
if (!this->get_imei()) {
|
||||
|
|
|
@ -77,6 +77,7 @@ class ModemComponent : public Component {
|
|||
bool modem_ready(bool force_check);
|
||||
void enable();
|
||||
void disable();
|
||||
void reconnect();
|
||||
|
||||
network::IPAddresses get_ip_addresses();
|
||||
std::string get_use_address() const;
|
||||
|
@ -166,6 +167,8 @@ class ModemComponent : public Component {
|
|||
bool power_transition{false};
|
||||
// states for triggering on/off signals
|
||||
ModemPowerState power_state{ModemPowerState::TOFFUART};
|
||||
// ask the modem to reconnect
|
||||
bool reconnect{false};
|
||||
};
|
||||
InternalState internal_state_;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue