Description
The BSSIDstr method retrieves the MAC address (BSSID) of the currently connected Wi-Fi network Access Point device. This method is useful for identifying the specific access point the ESP32 is connected to.
Syntax and Usage
The BSSIDstr method does not require any arguments and returns the MAC address of the connected access point in string format. Here is how you can use it:
WiFi.BSSIDstr()This method does not accept any arguments and simply returns the BSSID as a string.
Argument(s)
This method does not accept any arguments.
Return Value
The BSSIDstr method returns a String containing the MAC address of the connected Wi-Fi network access point device. If the ESP32 is not connected to a Wi-Fi network, this method will return an empty string.
Example Codes
Example: Retrieve and print the BSSID
/*
* Author: Avant Maker
* Date: February 7, 2025
* Version: 1.0
* Description: This code demonstrates how to connect an ESP32 to a WiFi network and
* retrieve the BSSID (the MAC address) of the connected WiFi access point using
* the ESP32's WiFi library.
*
* License: MIT
*
* Code Source: This example code is sourced from the Comprehensive Guide
* to the ESP32 Arduino Core Library, accessible on AvantMaker.com.
* For additional code examples and in-depth documentation related to
* the ESP32 Arduino Core Library, please visit:
*
* https://avantmaker.com/references/esp32-arduino-core-index/
*
* AvantMaker.com, your premier destination for all things DIY, AI, IoT,
* Smart Home, and STEM projects. We are dedicated to empowering makers,
* learners, and enthusiasts with the resources they need to bring their
* innovative ideas to life.
*/
#include <WiFi.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi!");
// Retrieve and print the BSSID
String bssidStr = WiFi.BSSIDstr();
Serial.print("Current BSSID: ");
Serial.println(bssidStr);
}
void loop() {
// Your code here
}Note: Replace your_SSID and your_PASSWORD with the actual credentials of your Wi-Fi network. The BSSID will be printed to the Serial Monitor after connecting to the network. If the ESP32 is not connected to a network, the BSSID will be an empty string.