I have been working for a while with the ESP8266 I have a question:

According to the online documentation of GitHub from the esp8266wifi library I can initialize the WiFi in Station mode to (obviously) connect to a nearby AP, I can initialize the station mode in 3 "different ways":

  • WiFi.begin (): The module initializes the Station mode and connects to the last network that is connected, because the credentials (SSID and Password) are stored in its internal memory (flash?).

  • WiFi.begin (ssid, password): The module initializes the Station mode and connects to the network with "ssid" and "password".

  • WiFi.begin (ssid, password, channel, bssid, connect): The same as the previous one, only that you pass more parameters: the one that interests me is the bssid, which is the MAC address of the AP to which I am going to connect.

Now comes the question: if I wanted to use the last mode, because I want to make sure that the ESP connects ONLY to an AP (a kind of MAC filtering), I also have to specify the channel and set the connect parameter? Or I can simply use something like this:

WiFi.begin ("MyOwnNetwork", "123456789", "00: 1B: 44: 11: 3A: B7")

I can not prove it right now, I do not have the module in my hands.


1 Answer 1


This is the function prototype:


Per C++ rules, in order to supply an argument for bssid, you have to pass an argument for channel as well, but connect is optional since it's positioned after your target argument. This should not be a problem though since you can just pass the default value of channel (i.e. 0) into the function; the channel argument is only relevant if you enter a value between 1 and 13 inclusive.

So your call should basically look like:

char ssid[] = "ssid";
char pwd[] = "pwd";
uint8_t bssid[] = {0x00, 0x1b, 0x44, 0x11, 0x3a, 0xb7};
WiFi.begin(ssid, pwd, 0, bssid);
  • Great answer!!! Just the one I was looking for!!! Thanks!!!!!
    – k.Cyborg
    Commented Feb 23, 2018 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.