[wifi] Fix ap_active condition (#12227)

This commit is contained in:
Flo
2025-12-02 17:12:27 +01:00
committed by GitHub
parent 6ce2a45691
commit 8f97f3b81f
6 changed files with 14 additions and 4 deletions

View File

@@ -580,7 +580,7 @@ void WiFiComponent::loop() {
WiFiComponent::WiFiComponent() { global_wifi_component = this; }
bool WiFiComponent::has_ap() const { return this->has_ap_; }
bool WiFiComponent::is_ap_active() const { return this->state_ == WIFI_COMPONENT_STATE_AP; }
bool WiFiComponent::is_ap_active() const { return this->ap_started_; }
bool WiFiComponent::has_sta() const { return !this->sta_.empty(); }
#ifdef USE_WIFI_11KV_SUPPORT
void WiFiComponent::set_btm(bool btm) { this->btm_ = btm; }

View File

@@ -616,6 +616,7 @@ class WiFiComponent : public Component {
bool error_from_callback_{false};
bool scan_done_{false};
bool ap_setup_{false};
bool ap_started_{false};
bool passive_scan_{false};
bool has_saved_wifi_settings_{false};
#ifdef USE_WIFI_11KV_SUPPORT

View File

@@ -82,8 +82,11 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
if (!ret) {
ESP_LOGW(TAG, "Set mode failed");
return false;
}
this->ap_started_ = target_ap;
return ret;
}
bool WiFiComponent::wifi_apply_power_save_() {

View File

@@ -53,7 +53,6 @@ static esp_netif_t *s_ap_netif = nullptr; // NOLINT(cppcoreguidelines-avoid-
#endif // USE_WIFI_AP
static bool s_sta_started = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static bool s_sta_connected = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static bool s_ap_started = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static bool s_sta_connect_not_found = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static bool s_sta_connect_error = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static bool s_sta_connecting = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
@@ -831,11 +830,11 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
} else if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_AP_START) {
ESP_LOGV(TAG, "AP start");
s_ap_started = true;
this->ap_started_ = true;
} else if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_AP_STOP) {
ESP_LOGV(TAG, "AP stop");
s_ap_started = false;
this->ap_started_ = false;
} else if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_AP_PROBEREQRECVED) {
const auto &it = data->data.ap_probe_req_rx;

View File

@@ -50,8 +50,11 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
if (!ret) {
ESP_LOGW(TAG, "Setting mode failed");
return false;
}
this->ap_started_ = enable_ap;
return ret;
}
bool WiFiComponent::wifi_apply_output_power_(float output_power) {

View File

@@ -28,11 +28,15 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_STA, true, CYW43_COUNTRY_WORLDWIDE);
}
}
bool ap_state = false;
if (ap.has_value()) {
if (ap.value()) {
cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_AP, true, CYW43_COUNTRY_WORLDWIDE);
ap_state = true;
}
}
this->ap_started_ = ap_state;
return true;
}