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

WiFi scanNetworks may not find all APs #10281

Closed
1 task done
TD-er opened this issue Sep 3, 2024 · 0 comments · Fixed by #10282
Closed
1 task done

WiFi scanNetworks may not find all APs #10281

TD-er opened this issue Sep 3, 2024 · 0 comments · Fixed by #10282
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@TD-er
Copy link
Contributor

TD-er commented Sep 3, 2024

Board

ESP32-C3/C6

Device Description

Hardware Configuration

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Windows 11

Flash frequency

Any

PSRAM enabled

yes

Upload speed

115200

Description

The example WiFi scan code may not show all available APs.
Usually only a very small subset.

In ESP-IDF5.3 the struct wifi_scan_config_t does have a few new members:

    uint8_t home_chan_dwell_time;                      /**< time spent at home channel between scanning consecutive channels. */
    wifi_scan_channel_bitmap_t channel_bitmap;         /**< Channel bitmap for setting specific channels to be scanned. For 2.4ghz channels set ghz_2_channels from BIT(1) to BIT(14) from LSB to MSB order to indicate channels to be scanned. Currently scanning in 5ghz channels is not supported. Please note that the 'channel' parameter above needs to be set to 0 to allow scanning by bitmap. */

link

According to the comments and docs it looks like whenever these members are set to 0, some predefined default is used. See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv428esp_wifi_set_scan_parametersPK26wifi_scan_default_params_t
However for the channel bitmap no default is mentioned, so I guess we should just set those bits ourselves.

Suggested code change for WiFiScanClass::scanNetworks

  if (channel == 0) {
    config.channel_bitmap.ghz_2_channels = 0xFFFF;
  } else {
    config.channel_bitmap.ghz_2_channels = BIT(channel);
  }
  config.home_chan_dwell_time = 30; // The home_chan_dwell_time needs to be a minimum of 30ms and a maximum of 150ms.

N.B. The esp-idf example code does do a calloc to sneakily set all to 0 and thus hiding the fact they do not properly initialize their members.
See: https://github.com/espressif/esp-idf/blob/6673376297b921d438790d195014b860eaf8bb17/examples/wifi/scan/main/scan.c#L174-L182

It is yet unclear how the bitmask for 5GHz will be interpreted as there is not yet any function to set those flags given an array of channel numbers.
So for the ESP32-C5 this needs to be fixed when this chip arrives.

Sketch

https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiScanAsync/WiFiScanAsync.ino

May not fail on each build, but when `async` is set to false, it may fail on an ESP32-C3.
Since the bitmask is not initialized, it may show up some of the used channels and thus masking the bug.

Debug Message

-

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant