Skip to content

ESP32 AP+STA and scanNetworks fails if STA not connected #8916

@astrogene1000

Description

@astrogene1000

Board

PICO-D4 and Devkit 3

Device Description

None

Hardware Configuration

None

Version

v2.0.14

IDE Name

Arduino IDE

Operating System

W11

Flash frequency

80

PSRAM enabled

yes

Upload speed

115200

Description

I have a build that always presents an Access point.
There is a need for also for connecting to a STA whose info the user enters via a web interface.
The issue is if the STA is not connected (which is possible as device may move to another physical area and need to connect to a different network) then while in main application if a scanNetworks is done it -always- returns a -2 (WIFI_SCAN_FAILED) basically immediately.

If a scanNetworks is done and the device is connected to a STA then works as expected.
If a scanNetworks is done prior to attempting to connect to the (non-existent) AP then it works as expected.

This is what I see as far as response time to scan
start_time = esp_timer_get_time();
numnets = WiFi.scanNetworks();
total_time = esp_timer_get_time() - start_time;
Serial.println(total_time);

total_time for scan prints out as 307/255/287 for three subsequent tries when not able to connected to
configured access point.

Here is what I see if successfully connected to an AP

total_time prints out as 7238971/8131168/8779417

For seeing 61, 66 and 59 unique external access points.

I believe the err is kick from this call in WiFiScan.cpp
if(esp_wifi_scan_start(&config, false) == ESP_OK) {

Based on this thread
espressif/esp-idf#11437

ESP_OK: succeed
ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout
ESP_ERR_WIFI_STATE: wifi still connecting when invoke esp_wifi_scan_start
others: refer to error code in esp_err.h

esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block);

Which is getting back a "ESP_ERR_WIFI_STATE: wifi still connecting" and scanNetworks returns it as a generic failure.

Question, how to get around this issue?
Can I shutdown the attempts to connect to the non-existent AP

I cannot stop then restart the whole wifi subsystem as that would drop the connection to the internal AP of the esp32.

Thoughts?

Thanks!

Gene

Sketch

int64_t start_time, total_time;
WiFi.begin("IDONOTEXIST", "123456789");
delay(1000);
int numnets = 0;

  start_time = esp_timer_get_time();
  numnets = WiFi.scanNetworks();
  total_time = esp_timer_get_time() - start_time;
  Serial.print("Total time: "); Serial.println(total_time);
  Serial.print("Numnets = "); Serial.println(numnets);

Debug Message

WiFi.scanNetworks() returns a -2 (WIFI_SCAN_FAILED)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Area: BT&WifiBT & Wifi related issuesStatus: SolvedThe issue has been resolved and requires no further action.Type: QuestionOnly question

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions