mirror of
https://github.com/esphome/esphome.git
synced 2025-02-07 21:51:00 +00:00
allow reconnect
This commit is contained in:
parent
c4705967bd
commit
0b6708ddbe
@ -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 ModemComponent::get_ip_addresses() {
|
||||||
network::IPAddresses addresses;
|
network::IPAddresses addresses;
|
||||||
esp_netif_ip_info_t ip;
|
esp_netif_ip_info_t ip;
|
||||||
@ -233,7 +244,6 @@ void ModemComponent::loop() {
|
|||||||
static uint32_t last_health_check = millis();
|
static uint32_t last_health_check = millis();
|
||||||
static bool connecting = false;
|
static bool connecting = false;
|
||||||
static uint8_t network_attach_retry = 10;
|
static uint8_t network_attach_retry = 10;
|
||||||
static uint8_t ip_lost_retries = 10;
|
|
||||||
|
|
||||||
if ((millis() < next_loop_millis)) {
|
if ((millis() < next_loop_millis)) {
|
||||||
// some commands need some delay
|
// some commands need some delay
|
||||||
@ -380,7 +390,12 @@ void ModemComponent::loop() {
|
|||||||
if (!this->internal_state_.connected) {
|
if (!this->internal_state_.connected) {
|
||||||
this->status_set_warning("Connection via Modem lost!");
|
this->status_set_warning("Connection via Modem lost!");
|
||||||
this->component_state_ = ModemComponentState::DISCONNECTED;
|
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");
|
ESP_LOGD(TAG, "modem health check");
|
||||||
last_health_check = millis();
|
last_health_check = millis();
|
||||||
if (!this->get_imei()) {
|
if (!this->get_imei()) {
|
||||||
|
@ -77,6 +77,7 @@ class ModemComponent : public Component {
|
|||||||
bool modem_ready(bool force_check);
|
bool modem_ready(bool force_check);
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
void reconnect();
|
||||||
|
|
||||||
network::IPAddresses get_ip_addresses();
|
network::IPAddresses get_ip_addresses();
|
||||||
std::string get_use_address() const;
|
std::string get_use_address() const;
|
||||||
@ -166,6 +167,8 @@ class ModemComponent : public Component {
|
|||||||
bool power_transition{false};
|
bool power_transition{false};
|
||||||
// states for triggering on/off signals
|
// states for triggering on/off signals
|
||||||
ModemPowerState power_state{ModemPowerState::TOFFUART};
|
ModemPowerState power_state{ModemPowerState::TOFFUART};
|
||||||
|
// ask the modem to reconnect
|
||||||
|
bool reconnect{false};
|
||||||
};
|
};
|
||||||
InternalState internal_state_;
|
InternalState internal_state_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user