mirror of
https://github.com/esphome/esphome.git
synced 2025-08-01 07:57:47 +00:00
Add WiFi shutdown hook to fix long deep sleep issue
Co-authored-by: jesserockz <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
331d98830a
commit
12db82e03a
@ -210,6 +210,13 @@ void WiFiComponent::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiComponent::on_safe_shutdown() {
|
||||
if (this->has_sta()) {
|
||||
ESP_LOGD(TAG, "Disconnecting from WiFi...");
|
||||
this->wifi_disconnect_();
|
||||
}
|
||||
}
|
||||
|
||||
WiFiComponent::WiFiComponent() { global_wifi_component = this; }
|
||||
|
||||
bool WiFiComponent::has_ap() const { return this->has_ap_; }
|
||||
|
@ -263,6 +263,9 @@ class WiFiComponent : public Component {
|
||||
/// Reconnect WiFi if required.
|
||||
void loop() override;
|
||||
|
||||
/// Safely shutdown WiFi before deep sleep
|
||||
void on_safe_shutdown() override;
|
||||
|
||||
bool has_sta() const;
|
||||
bool has_ap() const;
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
---
|
||||
esphome:
|
||||
name: test_esp8266_wifi_deep_sleep
|
||||
|
||||
esp8266:
|
||||
board: esp12e
|
||||
|
||||
wifi:
|
||||
ssid: "test"
|
||||
password: "test"
|
||||
|
||||
api:
|
||||
actions:
|
||||
- action: goto_sleep
|
||||
variables:
|
||||
duration_ms: int
|
||||
then:
|
||||
- deep_sleep.enter:
|
||||
id: deep_sleep_1
|
||||
sleep_duration: !lambda 'return duration_ms;'
|
||||
|
||||
deep_sleep:
|
||||
id: deep_sleep_1
|
||||
run_duration: 10s
|
Loading…
x
Reference in New Issue
Block a user