JohnySeven / TWatchSK

TTGO T-Watch 2020 v1 supporting Signal K features for displaying boat data and controlling devices on board.
MIT License
9 stars 1 forks source link

Wifi doesn't switch to the strongest Access Point as you move around #54

Open ba58smith opened 3 years ago

ba58smith commented 3 years ago

I have three wifi Access Points on my boat - engine room, salon, flybridge. The Watch connects to one of them, and then doesn't switch to the strongest one as I move around the boat. So if I start the Watch on the flybridge, then go through the salon to the engine room, it stays connected to the flybridge, and will lose wifi if I go into the engine room.

Helpful links: https://esp32.com/viewtopic.php?t=18979

JohnySeven commented 3 years ago

Regarding this, we could setup callback from Wi-Fi driver using this method: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv427esp_wifi_set_rssi_threshold7int32_t it will inform us if the RSSI of connected AP is below some threshold, and then we could eventually run active scan (while connected) and check if there are any other APs with same SSID with better signal. Also I would add this as configuration value (on/off) as it will consume more power and in cases where you have only one AP (my case) it won't help :-) This configuration could be set automatically if connecting to Wi-Fi that has multiple SSIDs.

It would be maybe good to have some data from your watch to set the Threshold correctly - something like -80 is expected value.

Thanks!

ba58smith commented 3 years ago

How do you find these things? (Like that method to set the RSSI threshold?) That's WAY better than the other solutions I've found that request the RSSI every few seconds. I'll definitely use that method / callback approach. Thanks!

JohnySeven commented 3 years ago

When I was playing with Wifi power saving I was reading those docs and when I was reading your issue for second time it just came to my mind :-)

ba58smith commented 3 years ago

The method referred to above (esp_wifi_set_rssi_threshold) is not available in the version of ESP-IDF that we're currently using. So we either wait until we upgrade to that version, or set up an "every X seconds" check of the strength of the wifi connection, and if it goes below a set level (I suggest -75), then scan for another AP with a better signal.

ba58smith commented 3 years ago

From a conversation with Jan on Slack:

  1. enable this roaming feature if you scan wifi and find multiple SSIDs after user has picked the Wifi name.
  2. if this feature is enabled and Wifi is connected just create new task that will be watching RSSI and this task will be in WifiManager
  3. if RSSI is lower than specific value just run the scan and pick Wifi with same SSID but better signal and then use BSSID to connect to network I would image task to be like: while(_check_wifi_rssi && connected) { if(current_rssi < rssi_threshold) { //run online scan and sort the result by RSSI //when done just connect to wifi } delay(5000); } it's just and idea before I'm going into bed, the code is just for illustration, will update it tomorrow with something real, the pain will be that scan is async, so you'll have to handle, then it's just simple go through the list of Wifi and find first with the same name and different BSSID than current Wifi, if you find the same BSSID as current AP it means you have the best signal available.