Skip to content

WiFi: select strongest signal when multiple APs with same SSID exist#31

Open
JinruiWang wants to merge 2 commits into78:mainfrom
JinruiWang:main
Open

WiFi: select strongest signal when multiple APs with same SSID exist#31
JinruiWang wants to merge 2 commits into78:mainfrom
JinruiWang:main

Conversation

@JinruiWang
Copy link

Summary

When remember_bssid_ is enabled and there are multiple APs with the same SSID (e.g., mesh network or dual-band router), connect to the one with the strongest signal instead of using the remembered BSSID which may have weaker signal.

Changes

include/wifi_station.h

Added has_multiple_same_ssid field to WifiApRecord struct to track if multiple APs with the same SSID were found during scan.

wifi_station.cc

HandleScanResult():

  • Count how many APs with the same SSID name exist during scan
  • Pass this info via has_multiple_same_ssid flag

StartConnect():

  • If remember_bssid_ is enabled AND only one AP with this SSID exists → use remembered BSSID (original behavior)
  • If remember_bssid_ is enabled AND multiple APs with same SSID exist → connect to strongest signal (new behavior)
  • If remember_bssid_ is disabled → connect to strongest signal (unchanged)

Use Case

Useful for mesh networks or dual-band routers where you want to remember the WiFi credentials but always connect to the strongest available AP with that SSID.

Randy added 2 commits March 24, 2026 20:19
When multiple APs share the same SSID name, only select the one with the strongest signal (RSSI) to connect, instead of relying on the WiFi driver's BSSID selection which may choose a weaker signal or a previously remembered BSSID.
When remember_bssid_ is enabled and there are multiple APs with the same SSID (e.g., mesh network or dual-band router), connect to the one with the strongest signal instead of using the remembered BSSID which may have weaker signal.
@78
Copy link
Owner

78 commented Mar 24, 2026

对于当前的方案,如果 remember_bssid_ 是 false,esp-idf会动态管理当前连接的AP,并在掉线后自动切换到相同SSID的信号强的AP。当 remember_bssid_ 是 true时,会记住当前连接的AP,并在下次仍然连接该AP。

需要考虑一个问题,esp-idf第一轮拿到的AP列表,信号强度不一定准确,AP列表也不一定完整,有可能信号最强的那个AP并没有出现在第一次扫描的结果中。

@JinruiWang
Copy link
Author

对于当前的方案,如果 remember_bssid_ 是 false,esp-idf会动态管理当前连接的AP,并在掉线后自动切换到相同SSID的信号强的AP。当 remember_bssid_ 是 true时,会记住当前连接的AP,并在下次仍然连接该AP。

需要考虑一个问题,esp-idf第一轮拿到的AP列表,信号强度不一定准确,AP列表也不一定完整,有可能信号最强的那个AP并没有出现在第一次扫描的结果中。

可能我理解的不够深刻。这是我这几天调试固件时碰到的问题,它总是在启动时连接到离我工位远的一个同名 ap 上,导致无法正常连接到我电脑上运行的 server,所以才有了这个 PR。

@78
Copy link
Owner

78 commented Mar 25, 2026

你需要的应该是:

  1. 打开 rembember_bssid_
  2. 删掉已经保存的ssid(因为它已记住远距离的AP了),重新添加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants