I need to get the RSSI of the networks and they MAC addresss to a IPS (indoor position system) program. I was able to get ssid, signal strength and security using the sample code, but not mac addresses. I tryed to use this, but itsn't working:
void loop() {
int n = WiFi.scanNetworks();
if(n == 0){
Serial.println("no networks found");
}
else{
for (int i = 0; i < n; ++i) {
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
Serial.println(WiFi.macAddress(i));
delay(10);
}
}
delay(10000);
}
@Tarmo's answer is correct, but the Arduino core does provide a simpler interface to getting the AP's access point without having to directly call ESP-IDF functions.
Use the BSSID
method to get the MAC address of the base station's wifi radio.
You can call either the BSSID()
method to get a pointer to the six byte MAC address or BSSIDstr()
to get the MAC address as a string.
So for instance:
Serial.print(WiFi.BSSIDstr(i));
will print the MAC address as a string.
When you're stuck on this kind of things referring to the library's source code can help you find out more than documentation and tutorials may.