[GH-ISSUE #1678] Feature request: connect with specific BSSID obtaining from of a networkscann #1423

Open
opened 2026-02-28 01:30:01 +03:00 by kerem · 16 comments
Owner

Originally created by @lastphoenx on GitHub (Nov 18, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1678

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.

Originally created by @lastphoenx on GitHub (Nov 18, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1678 ### 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.
Author
Owner

@tablatronix commented on GitHub (Nov 18, 2023):

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

<!-- gh-comment-id:1817514993 --> @tablatronix commented on GitHub (Nov 18, 2023): 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
Author
Owner

@lastphoenx commented on GitHub (Nov 18, 2023):

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

<!-- gh-comment-id:1817519595 --> @lastphoenx commented on GitHub (Nov 18, 2023): @tablatronix okay, I'd be really grateful for examples because I couldn't figure it out with custom parameters/add parameters.
Author
Owner

@tablatronix commented on GitHub (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

<!-- gh-comment-id:1817533895 --> @tablatronix commented on GitHub (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
Author
Owner

@lastphoenx commented on GitHub (Nov 18, 2023):

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?

<!-- gh-comment-id:1817539660 --> @lastphoenx commented on GitHub (Nov 18, 2023): 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?
Author
Owner

@tablatronix commented on GitHub (Nov 18, 2023):

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

<!-- gh-comment-id:1817543070 --> @tablatronix commented on GitHub (Nov 18, 2023): Esp will save bssid for you. I did some work on this in #1342 I will revisit the status
Author
Owner

@lastphoenx commented on GitHub (Nov 18, 2023):

oh - I see. thx!

<!-- gh-comment-id:1817546104 --> @lastphoenx commented on GitHub (Nov 18, 2023): oh - I see. thx!
Author
Owner

@lastphoenx commented on GitHub (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.

<!-- gh-comment-id:1817598064 --> @lastphoenx commented on GitHub (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.
Author
Owner

@tablatronix commented on GitHub (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

<!-- gh-comment-id:1817622895 --> @tablatronix commented on GitHub (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
Author
Owner

@lastphoenx commented on GitHub (Nov 18, 2023):

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")`

<!-- gh-comment-id:1817654966 --> @lastphoenx commented on GitHub (Nov 18, 2023): 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")`
Author
Owner

@tablatronix commented on GitHub (Nov 19, 2023):

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

<!-- gh-comment-id:1817710029 --> @tablatronix commented on GitHub (Nov 19, 2023): yeah I thought I added this somewhere but I cant find it
Author
Owner

@lastphoenx commented on GitHub (Nov 19, 2023):

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

<!-- gh-comment-id:1817755703 --> @lastphoenx commented on GitHub (Nov 19, 2023): You told that so i searched it on here in different request, discussions but did Not find it.
Author
Owner

@lastphoenx commented on GitHub (Nov 19, 2023):

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 ?

<!-- gh-comment-id:1817808851 --> @lastphoenx commented on GitHub (Nov 19, 2023): 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 ?
Author
Owner

@tablatronix commented on GitHub (Nov 19, 2023):

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

<!-- gh-comment-id:1817871969 --> @tablatronix commented on GitHub (Nov 19, 2023): I dont think so, the begin() should be doing a scan every connect before, unless you have issues like ap not found or something
Author
Owner

@lastphoenx commented on GitHub (Nov 19, 2023):

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

<!-- gh-comment-id:1817880145 --> @lastphoenx commented on GitHub (Nov 19, 2023): thx, whatever, it would be great to pass a specifi bssid to wifimanger anyway.
Author
Owner

@tablatronix commented on GitHub (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

<!-- gh-comment-id:1817885348 --> @tablatronix commented on GitHub (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
Author
Owner

@lastphoenx commented on GitHub (Nov 19, 2023):

okay, gerat. let me know. I will help to test as i have a great mesh with 5 AP.

<!-- gh-comment-id:1817889567 --> @lastphoenx commented on GitHub (Nov 19, 2023): okay, gerat. let me know. I will help to test as i have a great mesh with 5 AP.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1423
No description provided.