ESP8266 with multiple WiFi SSIDs

Working on a small project using an ESP8266 that is trying to connect to a local SSID and failing. I have 3 separate APs all using the same SSID so I can roam around and always get a solid connection. I'll use WIFILOCAL as the SSID in this example.

Using the ESP8266WiFi.h header library I enter the SSID and password and try to connect. I get an error code 7 returned to the sketch. I believe this is because the ESP8266 is seeing multiple APs advertising the SSID WIFILOCAL. So, I want to force connection to a specific AP that is closest to where the ESP8266 will be located.

According to the ESP doco the WiFi.begin method supports attaching to a specific AP using it's MAC address. The listed format is:

WiFi.begin(ssid, password, channel, bssid, connect)

Where the meaning of parameters is as follows:

  • ssid - a character string containing the SSID of Access Point we would like to connect to, may have up to 32 characters
  • password to the access point, a character string that should be minimum 8 characters long and not longer than 64 characters
  • channel of AP, if we like to operate using specific channel, otherwise this parameter may be omitted
  • bssid - mac address of AP, this parameter is also optional
  • connect - a boolean parameter that if set to false, will instruct module just to save the other parameters without actually establishing connection to the access point

I've added the following code line to my set up...

const byte bssid[] = {0xE8, 0x9C, 0x25, 0x71, 0x85, 0x70};

which is the MAC address for the AP, and then I use the following command to initiate the wifi connection...

WiFi.begin(ssid, password, 0, bssid);

But I get error code 7 returned.

So I am obviously not implementing the call properly.

The ESP8266 doco says that bssid is defined as "const uint8_t * bssid = 0".

HELP!

And in case you ask...

I have all the APs set up serving up two SSIDs, one for 2.4 and one for 5.0. I have many different IOT devices connecting to the 2.4 wifi set up, and then seem to work just fine even if they "see" several SSIDs being advertised. But this particular device (the ESP8266 for this project) is located between two reasonably strong 2.4 signals and is unable to connect, I guess. If I check the SSID to be something like WIFILOCAL-A, WIFILOCAL-B, etc, then I'd break the connections for all the other devices. If I have to, I can do that, but it will be a real PITA.

I have a Draytek router with built in WiFi and a Draytek wireless access point, both configured with the same SSID and password. I've been using ESP8266s for years without seeing any problems with them connecting to whichever access point is closer. I have had problems with handover from one to the other when moving an ESP8266 around, but I don't think that's the problem you are seeing. So, I believe it should work okay.

I just remembered something: Are your wireless access points using WiFi 6? There are problems with WiFi 6 connecting to some devices, and I would expect problems connecting to an ESP8266. I'm not an expert on this but a friend maintains multiple WiFi networks for his employer's customers and has seen problems with older devices connected to WiFi 6, to the point of having to revert to WiFi 5.

For the record, that's WL_DISCONNECTED

Are you checking the connection in a loop, after setting the mode to WIFI_STA, as shown in the WiFiClient example?

To both… the exact same code works just fine if I log onto the router and change the SSID to a unique name (add an “x” to the end of the name). So it’s definitely an issue with the ESP seeing two strong signals and failing to pick and connect.

Please post your code here, in code tags, for me to try. To be clear, please post it exactly as you have it but without the password. It might be useful to see the SSID if you don't mind sharing that publicly. I will try the code on an ESP8266.

I can do that if needed but… Turns out there are several bugs reported on GitHub dealing with this issue. The current board core (3.x) does has problems dealing with newer routers and the current solution is to revert to board code 2.5.2 and remove code that doesn’t work for that older core (like WiFi scanning). I did that and everything works just fine. Ugh…

1 Like

Can you please expand on how you changed the "board code to 2.5.2"?

I am having a problem trying to use WiFi.begin(ssid, passwd, apbssid) where apbssid is a container for the AP's MAC address.

It does not compile but throws an error regarding the apbssid item..

Maybe I am hit by the same problem, my project uses an ESP-01 if that matters.

Open the Board Manager, find your ESP board, and then you will see a list of board core versions. Select the core version you want and the IDE will update its processes and use that core version for compiling and linking your code. Hope that helps...

Turns out that the syntax is wrong, the bssid is argument #4 and there must be a #3 too (channel) in order to use bssid:
WiFi.begin(ssid, passwd, 0, apbssid)

I have a setting in platformio.ini to use an older version:
platform = espressif8266@2.5.2

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