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 roaming" by channel scan (AP switching at low RSSI) #2120

Merged
merged 3 commits into from
Mar 4, 2023

Conversation

Slider0007
Copy link
Collaborator

@Slider0007 Slider0007 commented Mar 4, 2023

Implement a kind of roaming feature #2092 which has less dependencies in terms of capabilities of AP / mesh system and is lightwight to ensure less impact to memory usage of ESP32.

WIFI AP switching by channel scan (simplified "roaming")

  • Implement wifi channel scanning (background scan, scan possible even ESP is connected) to have kind of "roaming" like feature
  • Function needs to be activated using RSSIThreshold parameter by setting a value lower than 0 (0 = disable)
  • Scan and evaluation gets triggered when actual RSSI < RSSI Threshold (RSSIThreshold, e.g. -75dBm) and flow is finished (Info gets printed with DEBUG level)
    image
  • Process:
  • Scan all channels for configured SSID
  • Compare if (actual RSSI + 5) < AP RSSIs found by scan (+ 5 to avoid switching by almost equal RSSI)
  • If an AP with better RSSI is found, force wifi disconnect to reconnect to AP with hopefully better RSSI
  • The reconnect to new AP will not get forced by BSSID, to avoid issues when potentially AP with better RSSI reject connection for some reason. Therefore the selection is related to the following config and wifi library.
    image
  • Switch on all channel scan option --> Wifi scan will performed for all channels before choosing an AP and not use first matching AP (This is also valid even AP switching function is disabled => RSSIThreshold = 0)

Alternative: WIFI roaming 802.11kv --> deactivated by default

NOTE: Fully implemented, but not fully tested (be aware: additional ca. 6-10kB internal heap is consumed to run this feature)

  • basic roaming functionality is disabled by default, compile time (--> This feature needs to be activated in define.h --> #define WLAN_USE_MESH_ROAMING and sdkconfig.default + disabling roaming by scanning feature)
  • This is needed to handle any roaming request triggered by AP/mesh (802.11k, 802.11v)
  • Optional WIFI roaming feature (needs to be enabled in defines.h --> #define WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES) to enable ESP triggered query to roam using RSSIThreshold parameter can be activated when parameter is set to a value lower than 0 (0 = disable this optional feature)
    --> The query is only sent when actual RSSI < RSSI Threshold (RSSIThreshold, e.g. -75dBm)
    --> The evaluation is only triggered after flow is finished and RSSI < RSSI Threshold every round (The trigger and the neighbour table gets printed with DEBUG level)
    image

--> This does not guarantee that ESP will roam because only a query to AP/mesh is going to be sent. The actual request that ESP needs to roam is still triggered by AP/mesh. If AP/mesh does not see any need to roam, no roam request will sent to ESP and nothing will happen

The info if AP is supporting the roaming features 802.11k and 802.11v will be logged to logfile after wifi connection gets established
image

@Slider0007 Slider0007 changed the title "WIFI roaming" by channel scan (only AP switching at low RSSI) "WIFI roaming" by channel scan (AP switching at low RSSI) Mar 4, 2023
@caco3
Copy link
Collaborator

caco3 commented Mar 4, 2023

general question:
With the threshold set to 0, what will happen on the startup? Does it still use the first AP it finds or does it a scan und picks the best one? I would prefer the 2nd option, so also users who do not want to go into expert functions get this improvement. Most might even be unaware or not able to understand what it does.

@Slider0007
Copy link
Collaborator Author

With the threshold set to 0, what will happen on the startup? Does it still use the first AP it finds or does it a scan und picks the best one? I would prefer the 2nd option, so also users who do not want to go into expert functions get this improvement. Most might even be unaware or not able to understand what it does.

The threshold only activates the evaluation to switch APs. If set to 0 no triggered switching will happen.

After any scan always best AP is / should be selected. This a wifi library config setting:
image

@caco3
Copy link
Collaborator

caco3 commented Mar 4, 2023

so the picking of the best AP on startup works also with threshold=0?

@Slider0007
Copy link
Collaborator Author

Slider0007 commented Mar 4, 2023

so the picking of the best AP on startup works also with threshold=0?

yes, as long the wifi library is working correctly. Also Wifi connect function initiates a wifi scan first (in this case a scan of all channels, then sorting by RSSI and choosing the "best" AP)

@jomjol jomjol merged commit 6ca7897 into rolling Mar 4, 2023
@jomjol jomjol deleted the activate-wifi-roaming branch March 4, 2023 10:49
caco3 pushed a commit that referenced this pull request Mar 4, 2023
* Activate 802.11kv wifi mesh roaming

* Activate roaming by scanning

* Revert stack reducation
jomjol pushed a commit that referenced this pull request Mar 5, 2023
* Run the Homeassistant Discovery directly after connecting to the broker. Before it was delayed 10s and happened while the first round alredy was in progress

* schedule sending HA discovery and static topics

* Allow setting QOS for MQTT topics

* .

* .

* change MQTT QOS1 expiration time from (default) 30 to 5s

* add logging of heap change on MQTT topic sendings

* wait for MQTT transmission timeout after publishing

* use QOS0 for Homeassistant Discovery topics. the messages then could possibly get lost but we save a lot of heap

* .

* use PSRAM for the MQTT outbox

* use QOS1 for HA discovery again

* .

* .

* disable delay, not needed with PSRAM

* .

* consolidated scheduledSendingOf_DiscoveryAndStaticTopics into sendingOf_DiscoveryAndStaticTopics_scheduled

* Send Homeasstsiatnt Discovery and static data in MQTT step instead of when the wifi gets connected

* "WIFI roaming" by channel scan (AP switching at low RSSI) (#2120)

* Activate 802.11kv wifi mesh roaming

* Activate roaming by scanning

* Revert stack reducation

* move Wifi, LWIP and BSSI to PSRAm

* added State Class "measurement" to rate_per_time_unit (#2116)

Co-authored-by: CaCO3 <caco@ruinelli.ch>

* use QOS0 for Homeassistant Discovery topics. the messages then could possibly get lost but we save a lot of heap

* use QOS0 for Homeassistant Discovery topics. the messages then could possibly get lost but we save a lot of heap

# Conflicts:
#	code/components/jomjol_mqtt/server_mqtt.cpp

# Conflicts:
#	code/components/jomjol_mqtt/server_mqtt.cpp

* .

* .

* move to next PR

* Update code/components/jomjol_mqtt/server_mqtt.cpp

* Update code/components/jomjol_mqtt/server_mqtt.cpp

---------

Co-authored-by: CaCO3 <caco@ruinelli.ch>
Co-authored-by: Slider0007 <115730895+Slider0007@users.noreply.github.com>
@caco3 caco3 mentioned this pull request Mar 11, 2023
31 tasks
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.

3 participants