ESP8266 Wemos D1 Retrieving Wrong AP Mac Address Using WiFi.BSSID and WiFi.BSSIDstr gives me some weird mac address.

the code is:

#include "ESP8266WiFi.h"
#include "ESP8266WiFiScan.h"

void setup() {
Serial.begin(115200);
//WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
Serial.println(WiFi.macAddress());
}

void loop() {
   int n=WiFi.scanNetworks();
   Serial.println(n);
   for (int network = 0; network &lt; n; network++){
      Serial.println(WiFi.SSID(network));
      Serial.println(WiFi.RSSI(network));
      uint8_t* mac=WiFi.BSSID(n);
      char APmac[13];
      APmac[0]=0;
      for (int i=0; i&lt;6;i++) {
        char buffer[3];
        sprintf(buffer, "%02x", mac[i]);
        strncpy((char *)(APmac+(i*2)), buffer, 3);
        Serial.print("["); Serial.print(i); Serial.print("]"); Serial.println(buffer);
      }
      Serial.println(APmac);
      Serial.println(WiFi.BSSIDstr(n));

  }
  Serial.println();
  Serial.println();
  delay(10000);
}


The current output is 6D:98:C9:00:00:00 which is completely off. It duplicates this output for other APs too. Is this a hardware problem? I've seen other people using the same codes and it works for them. For reference WiFi.SSID(); and WiFi.RSSI(); both spits out correctly.

edit: I was testing both output to see which ever one was correct and unfortunately they're both wrong
This seems wrong, you are trying to get String to interpret a byte, but are passing in a pointer to a byte:

String digit = String(*mac, HEX);


Try changing your example to:

uint8_t* mac=WiFi.BSSID();              // Gather the byte array
String APmac;
for (int i=0; i&lt;6;i++) {
   String digit = String(mac[i], HEX);  // String() should see an int, not a pointer to a byte, with the directive to print it in HEX format
   if (digit.length() &lt;2)
     APmac += String("0")+digit;        // Corrected capitalization error
   else
     APmac +=digit;                     // Corrected capitalization error
   //mac++;                             // Not necessary
   Serial.print("["); Serial.print(i); Serial.print("]");
   Serial.println(mac[i], HEX);
}
Serial.println(APmac);                  // Print the constructed String
Serial.println(WiFi.BSSIDstr());        // Print the pre-formatted string


Consider not using the String object, which may help condense the code a bit:

uint8_t* mac=WiFi.BSSID();
char APmac[13];
APmac[0]=0;
for (int i=0; i&lt;6;i++) {
   char buffer[3];
   sprintf(buffer, "%02x", mac[i]);
   strncpy((char *)(APmac+(i*2)), buffer, 3);
   Serial.print("["); Serial.print(i); Serial.print("]"); Serial.println(buffer);
}
Serial.println(APmac);
Serial.println(WiFi.BSSIDstr());