ESP32 Fritz!Box-Mesh = same SSID for router & repeater force connecting to a certain MAC-Adress?

Hi everybody,

In my house I use a WLAN-Router AVM Fritz!Box 4060 and three repeaters
They are configured as a MESH which means the router and the repeaters have all the same SSID and password.

Now if the ESP32 connects the ESP32 seem to connect randomly to the router or a repeater but not the one with the strongest WiFi-signal.

The ESP32 is 50cm away from the router which means the signal from the router should really be the strongest but if I look up RSSI on the ESP32 it is at
-88 dbi which means the ESP32 has connected to the far away repeater.

So my question is:
is there a way to force the EPS32 to connect to either

  • the strongest signal
    or
  • to a specified MAC-Adress?

best regards Stefan

In the meantime I did some research on this and found

A device must support 802.11k or 802.11r-Standard for seamleas roaming between different devices with the same SSID.

If I look up the properties of the ESP32 in my FritzBox 4060 router I see only
STBC as entry. 802.11k or 802.11v are missing.

So I did some duckling (private googling with duckduckGo)
and found this thread

which mainly says espressif plan only to implement 802.11r (whatever 802.11r is)

So I guess the only way would be to re-connect again and again until RSSI is above a defined threshold-value

best regards Stefan

802.11r is only used if you move around, it will allow for fast roaming in a wireless network, allowing a client which leaves one Access Point to associate with another Access Point without requiring the client to re-authenticate.

I don't think it matters in your case as you don't move around.

Have you tried to configure your ESP's wifi_sort_method_t with WIFI_CONNECT_AP_BY_SIGNAL ? You'll also need to enforce an ALL_CHANNEL_SCAN

Hi @J-M-L

no never heard / read of these details before.

I was looking up your links. Aha .... --- .... ???
No idea how the real Arduino-code has to look like to set these details.
The link into the espressif-docs to me seems just as a huge list of details but I have no idea where I could look up code-examples

Would you mind posting a code-example?

best regards Stefan

sorry the links were if you use the ESP-IDF framework and not directly the Arduino environment

if you check the API you have two functions setScanMethod() and setSortMethod()

the default sort is WIFI_CONNECT_AP_BY_SIGNAL but the default scan is not WIFI_ALL_CHANNEL_SCAN so I would try

#include <WiFi.h>

const char* ssid = "XXX";
const char* password = "YYY";

void setup() {
  Serial.begin(115200);

  int numNetworks = WiFi.scanNetworks();
  if (numNetworks == 0) {
    Serial.println("No WiFi networks found.");
  } else {
    Serial.println("-----------------------");
    Serial.print("Found ");
    Serial.print(numNetworks);
    Serial.println(" WiFi networks:");

    for (int i = 0; i < numNetworks; i++) {
      Serial.print(WiFi.SSID(i));
      Serial.print(" with RSSI ");
      Serial.println(WiFi.RSSI(i));
    }
    Serial.println("-----------------------");
  }


  Serial.print("Connecting to ");  Serial.println(ssid);
  WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
  WiFi.disconnect();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
  Serial.print("IP Address: ");
  Serial.print(WiFi.localIP());
  Serial.print(" with RSSI ");
  Serial.println(WiFi.RSSI());
}

void loop() {}

you can see also that begin() can take a lot of various parameters so you could also explore that

Hi @J-M-L,

thank you very much for posting the example-code.
I experimented with different code-versions and had the following rather strange observations:

The complete project includes SD-card and onewire
If I start SD-card and onewire before the connection to the WiFi like this

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println( F("Setup-Start") );
  PrintFileNameDateTime();

  TestSD_Card();
  do_SD_Card_Tests();

  setupOneWireBus();
  SetupESPDASH_Cards();

  ConnectToWiFi();
  if (WiFi.status() != WL_CONNECTED) {
    scanWiFis();
  }

then the ESP32 seems to choose randomly between my WLAN-router (strongest signal) and the repeaters (weaker signals)

If connecting to is executed right after Serial.begin()
the WLAN-router which has the strongest signal is chosen each time.
( I repeated this test maybe 15 times)

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println( F("Setup-Start") );
  PrintFileNameDateTime();

  ConnectToWiFi();
  if (WiFi.status() != WL_CONNECTED) {
    scanWiFis();
  }

  TestSD_Card();
  do_SD_Card_Tests();

  setupOneWireBus();
  SetupESPDASH_Cards();

.
I have another question:
Do you think it is important to do the function-calls

  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
  WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
  WiFi.begin(home_ssid, home_password);

in a certain order?
.
.here is my connectToWiFi-function

void ConnectToWiFi() {
  const int maxCount = 120;
  int myCount = 0;
  // try to connect to existing network
  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
  WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
  //scanWiFis();
  Serial.print("\n\nTry to connect to existing network");
  Serial.print(" named #");
  Serial.print(home_ssid);
  Serial.println("#");
  WiFi.begin(home_ssid, home_password);
  Serial.println("WiFi.begin(home_ssid, home_password) done");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED && myCount < maxCount) {
    yield(); // very important to execute yield to make it work
    BlinkHeartBeatLED(OnBoard_LED, 50); // blink LED fast during attempt to connect

    if ( TimePeriodIsOver(myTestTimer, 500) ) { // once every 500 miliseconds
      Serial.print(".");                        // print a dot
      myCount++;
      if (myCount % 20 == 0) {
        Serial.println();
      }

      if (myCount > maxCount) { // after maxCount dots = maxCount / 2 seconds
        Serial.println();
        Serial.print("not connected ");
      }
    }
  }
  Serial.println();

  if (WiFi.status() == WL_CONNECTED ) {
    Serial.println("");
    Serial.print("Connected to #");
    Serial.print(home_ssid);
    Serial.println("#");
    Serial.println(" type the IP address into your browser to visit your dashboard: ");
    Serial.println(WiFi.localIP());
    Serial.print("RSSI:");
    Serial.println(WiFi.RSSI() );
  }
}

best regards Stefan

I think in practice, the ESP connect with the repeater who answer as first on a request. 5 Fritz repeaters and my 2 ESP32 outside connect with 4 of them. An ESP8266 on the other side of the garden connect with 3 of them.

yes you need to call the setSortMethod() and setScanMethod() before calling WiFi.begin()

it's documented in the .h just above the functions declarations

calling disconnect() is not mandatory, but cleans things up.


that's weird indeed.... I don't know why this would happen. May be some issues with signals on the board and the small built in antenna?


that might be because of the default WIFI_FAST_SCAN instead of WIFI_ALL_CHANNEL_SCAN

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.