Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures that we don't start STA wifi when AP-only is requested. #783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/freertos_drivers/esp32/Esp32WiFiManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ void Esp32WiFiManager::start_mdns_system()

void Esp32WiFiManager::on_station_started()
{
if (!(wifiMode_ == WIFI_MODE_STA || wifiMode_ == WIFI_MODE_APSTA))
{
LOG(INFO, "[Station] Did not want station.");
return;
}

// Set the generated hostname prior to connecting to the SSID
// so that it shows up with the generated hostname instead of
// the default "Espressif".
Expand Down Expand Up @@ -999,6 +1005,12 @@ void Esp32WiFiManager::on_station_ip_lost()

void Esp32WiFiManager::on_softap_start()
{
if (!(wifiMode_ == WIFI_MODE_AP || wifiMode_ == WIFI_MODE_APSTA))
{
LOG(INFO, "[SoftAP] Did not want SoftAP.");
return;
}

uint32_t ip_address = 0;
uint8_t mac[6];
esp_wifi_get_mac(WIFI_IF_AP, mac);
Expand Down Expand Up @@ -1228,10 +1240,18 @@ StateFlowBase::Action Esp32WiFiManager::WiFiStackFlow::init_interface()
esp_err_to_name(err));
}

parent_->espNetIfaces_[STATION_INTERFACE] =
esp_netif_create_default_wifi_sta();
parent_->espNetIfaces_[SOFTAP_INTERFACE] =
esp_netif_create_default_wifi_ap();
if (parent_->wifiMode_ == WIFI_MODE_STA ||
parent_->wifiMode_ == WIFI_MODE_APSTA)
{
parent_->espNetIfaces_[STATION_INTERFACE] =
esp_netif_create_default_wifi_sta();
}
if (parent_->wifiMode_ == WIFI_MODE_AP ||
parent_->wifiMode_ == WIFI_MODE_APSTA)
{
parent_->espNetIfaces_[SOFTAP_INTERFACE] =
esp_netif_create_default_wifi_ap();
}

// Connect our event listeners.
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID,
Expand Down Expand Up @@ -1287,15 +1307,8 @@ StateFlowBase::Action Esp32WiFiManager::WiFiStackFlow::init_wifi()
// or mDNS systems.
parent_->wifiStatusEventGroup_ = xEventGroupCreate();

wifi_mode_t requested_wifi_mode = parent_->wifiMode_;
if (parent_->wifiMode_ == WIFI_MODE_AP)
{
// override the wifi mode from AP only to AP+STA so we can perform wifi
// scans on demand.
requested_wifi_mode = WIFI_MODE_APSTA;
}
// Set the requested WiFi mode.
ESP_ERROR_CHECK(esp_wifi_set_mode(requested_wifi_mode));
ESP_ERROR_CHECK(esp_wifi_set_mode(parent_->wifiMode_));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested that when in AP mode that WiFi scan works? I had tested it long ago and found that it is required to use APSTA mode for scan to work this the comment in the section that was removed above.


// This disables storage of SSID details in NVS which has been shown to be
// problematic at times for the ESP32, it is safer to always pass fresh
Expand Down