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

Feature request: connect with specific BSSID obtaining from of a networkscann #1678

Open
lastphoenx opened this issue Nov 18, 2023 · 16 comments

Comments

@lastphoenx
Copy link

Basic Infos

Hardware

WiFimanager Branch/Release: Master 2.016-rc.2

Esp8266/Esp32:

Hardware: ESP32CAM AI Thinker ESP32-Cam

Description

Problem description

it would be very useful to be able to do soemthing like this, after a networkscan:

WiFi.begin(ssid, password, Kanal, WiFi.BSSID(i))

Message:
As I found, that it often reconnects to first BSSID it has ever connectet, it tends to only reconnect to this BSSID.
with WiFi.begin(ssid, password, Kanal, WiFi.BSSID(i)) i can change that behavior easily, but I cant do that with Wifi.Manger as I dont have access to the password for example and as i dont wanna store it in my coding I use Wifi-Manger.

@tablatronix
Copy link
Collaborator

This is based on the scan options esp does this because its faster but sucks for mesh. You can adjust this and you can also save bssid automatically.
I will find examples

@lastphoenx
Copy link
Author

@tablatronix
okay, I'd be really grateful for examples because I couldn't figure it out with custom parameters/add parameters.

@tablatronix
Copy link
Collaborator

tablatronix commented Nov 18, 2023

  // Set ESP WIFI specifics 
  // WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // wifi_scan_method_t scanMethod [WIFI_FAST_SCAN],WIFI_ALL_CHANNEL_SCAN
  // WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); // wifi_sort_method_t sortMethod - [WIFI_CONNECT_AP_BY_SIGNAL],WIFI_CONNECT_AP_BY_SECURITY
  // WiFi.setMinSecurity(WIFI_AUTH_WPA2_PSK); [WIFI_AUTH_WPA2_PSK]

check the super example

I might add a UI toggle for this at some point

@lastphoenx
Copy link
Author

wow, looks brilliant. thx so much.
meanwhile I tried this:

`
#include <EEPROM.h>
#include <WiFi.h>

    // Definiere die Adresse im EEPROM, an der die BSSID gespeichert wird
    #define BSSID_EEPROM_ADDRESS 0
    #define BSSID_LENGTH 6
    
    void saveBSSID(uint8_t *bssid) {
      // Speichere die BSSID in EEPROM
      for (int i = 0; i < BSSID_LENGTH; ++i) {
        EEPROM.write(BSSID_EEPROM_ADDRESS + i, bssid[i]);
      }
      EEPROM.commit();
    }
    
    // Hier in deiner Funktion (scan oder wie auch immer du sie nennst)
    void scanForNetwork() {
      // Ermitteln, welches Netz mit der passenden SSID das beste Signal hat
      // Das Ergebnis des Scans ist automatisch immer nach vom stärksten zum schwächsten Signal sortiert
      for (int i5 = 0; i5 < n && String(ssid) != String(WiFi.SSID(i5)); ++i5);
    
      if (i5 < n) {
        uint8_t currentBSSID[BSSID_LENGTH];
        memcpy(currentBSSID, WiFi.BSSID(i5), BSSID_LENGTH);
    
        // Speichere die BSSID im EEPROM
        saveBSSID(currentBSSID);
    
        WiFi.disconnect();
        WiFi.mode(WIFI_STA);
        initwifimanager()
        WiFi.reconnect();
      }
    }

`

what do you think about that? to complicated?

@tablatronix
Copy link
Collaborator

Esp will save bssid for you. I did some work on this in #1342 I will revisit the status

@lastphoenx
Copy link
Author

oh - I see. thx!

@lastphoenx
Copy link
Author

lastphoenx commented Nov 18, 2023

Esp will save bssid for you. I did some work on this in #1342 I will revisit the status

I tested it (your three Lines of code by putting it in first Place of My void Setup. Workshop Perfect. I Would like to say thank you a) for your Library and b) for your fast reply.

@tablatronix
Copy link
Collaborator

tablatronix commented Nov 18, 2023

WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
This is the key, otherwise esp by default uses the FIRST AP not the strongest

They turned it to fast so battery low power devices connect much faster

@lastphoenx
Copy link
Author

yes, thats true. knowing this, maybe even a wifiManager.setConnectTimeout(20000); would fix it? (not best practice though)

would still be nice to know how to pass a specific BSSID to wifi.mangers autoconect or add optional BSSID paramater so that someone could fill it (like: res=wm.autoConnect("AutoConnectAP", "password", "BSSID")`

@tablatronix
Copy link
Collaborator

yeah I thought I added this somewhere but I cant find it

@lastphoenx
Copy link
Author

You told that so i searched it on here in different request, discussions but did Not find it.

@lastphoenx
Copy link
Author

It is not consistent. sometimes now it gets the best rssi but not always. it seems as if I need to make a time out.
would something like this help: wm.setConnectTimeout(7) where would i place it ?

@tablatronix
Copy link
Collaborator

I dont think so, the begin() should be doing a scan every connect before, unless you have issues like ap not found or something

@lastphoenx
Copy link
Author

thx, whatever, it would be great to pass a specifi bssid to wifimanger anyway.

@tablatronix
Copy link
Collaborator

tablatronix commented Nov 19, 2023

Yeah I will try to test this a bit, I have a mesh network, I also just updated the fastconnect feature branch to test that
Might be later this week

I might have made a branch that I never pushed, or maybe its a PR, I know I had basic set bssid as one, but maybe there was esp bugs and I abandoned it at the time

I even had it set to auto use bssid if you have AP grouping turned off

@lastphoenx
Copy link
Author

okay, gerat. let me know. I will help to test as i have a great mesh with 5 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

No branches or pull requests

2 participants