I want to log the MAC address of the access point my ESP-8266 connects to in order to verify its data. But I have not found any command to do this...
I have scanned the ESP8266 WiFi documentation about how to retrieve the AP MAC address here.
But the command WiFi.macAddress() returns the MAC of the ESP itself, which is not what I want...
Is there some way to read the MAC address of the AccessPoint itself to which the ESP is connected?
When starting this thread I found a link to a similar question but the reply was to "read the docs" and no other help provided...
However in that linked reply the advice was to use WiFi.BSSID(), for which the doc states:
Return the mac address of the access point to which the ESP module was directed to connect to.
This address is formally called Basic Service Set Identification (BSSID).
The returned pointer is what the user configured when calling begin() with a bssid argument. It does not necessarily reflect the mac address of the access point to which the ESP module’s station interface is currently connected to.
So as you can see it is not really what is asked for....
But what about the following reference doc sentence then? It seems to say the opposite....
The returned pointer is what the user configured when calling begin() with a bssid argument. It does not necessarily reflect the mac address of the access point to which the ESP module’s station interface is currently connected to
Or does this comment ONLY apply when using the WiFi.Begin() method with the 3rd argument bssid?
I.e. if one uses WiFi.Begin(ssid, password) THEN the command WiFi.BSSID()will return the actual MAC of the AP?
Final report
I have now updated the IoT f/w with the code shown and it does log the correct WiFi AP MAC address via MQTT after it connects!
I have not tried the WiFi.Begin(ssid, passwd, APmacaddr) command since I changed the SSID on the AccessPoint for it to be unique.
REOPENING the thread since I ran into trouble later...
The code works fine as is with a WiFi.begin(MySSID, MyPasswd); command to connect.
But it turns out that it takes more than 4 seconds to connect and this is not quick enough for my use...
The device is supposed to quickly perform some simple reporting action when reset and then go to deep sleep, and I need the total time to be around a second. Right now it takes about 4.5 seconds and I have read somewhere that by specifying the bssid MAC address in the call it can be dropped to below a second.
So I am looking at the version of begin that specifies the AP by MAC address: WiFi.begin(MySSID, MyPasswd, myap_bssid);
I have tried several ways to set the extra parameter based on stuff I have read here, but it won't compile!
I do not understand what you ask...
I am not using a phone but an ESP-01 device (based on ESP8266).
It is supposed to be idling in deep sleep running on battery power until an event happens and then wake up connect and send an MQTT message then go back to deep sleep.
The wakeup is done by using the reset pin since the real wake from deep sleep pin is not exposed on an ESP-01.
I do read other people needing quick connects and getting it via use of bssid as 3rd argument to Wifi.begin(). They even mention a few hundred milliseconds.
I thought that upwards of 10 seconds would be acceptable between reactions but I found out yesterday that the events may trigger with an interval sometimes even below 4 seconds. So the entire process may not take longer of course.
OK thanks Juraj!
I guess that what you are showing is the underlying library function that gets called with WiFi.begin()....
So what I was missing is that the AP MAC address item is #4 rather than #3...
When I changed the command by adding a 0 for the channel entry so it reads like this it seems to work (compile without errors):