title: How to get the MAC adress of an access point when esp8266 is in client (station) mode?
body: <p>I would like my <em>esp8266</em> to retrieve the mac address of the AP it`s connected to as a client (station), following this discussion on <a href="http://bbs.espressif.com/viewtopic.php?f=15&amp;t=3102&amp;p=10569&amp;hilit=Access+Point+MAC+adress&amp;sid=a68dcff311ea05ece032126d6f93902f#p10569" rel="nofollow noreferrer">How to get Access Point MAC adress</a>.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  
  const char* ssid     = "somrmthing";
  const char* password = "somrmthing"; //
  
  const char* host = "aubs.gear.host"; //create webserver &amp; correct address
  
  uint8_t MAC_array[6];
  char MAC_char[18];
  
  void setup() {
    // put your setup code here, to run once:
  
    Serial.begin(115200);
    delay(100);
  
    // We start by connecting to a WiFi network
  
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
  
    WiFi.begin(ssid, password);
  
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
  
    Serial.println("");
    Serial.println("WiFi connected");  
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  
  int value = 0;
  
  void loop() {
    // put your main code here, to run repeatedly:
  
  /*
   * http://stackoverflow.com/questions/34078497/esp8266-wificlient-simple-http-get
   */
    delay(30000);
      ++value;
  
      /*
       * https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino
       */
  
    Serial.print("connecting to ");
    Serial.println(host);
  
  // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
    }
  
  
  // getting the mac address  http://bbs.espressif.com/viewtopic.php?f=15&amp;t=3102&amp;p=10569&amp;hilit=Access+Point+MAC+adress&amp;sid=a68dcff311ea05ece032126d6f93902f#p10569
  void wifi_handle_event_cb(System_Event_t *evt) 
  {
        os_printf("event %x\n", evt-&gt;event);
                switch (evt-&gt;event){
                        case EVENT_STAMODE_CONNECTED:
                              os_printf("connect to ssid %s, channel %d\n", evt-&gt;event_info.connected.ssid, evt-&gt;event_info.connected.channel);
                              os_printf("AP MAC address is  %s\n", evt-&gt;event_info.connected.bssid);
                        break;
  
                        case ....
                        ....
                }
  }
  
  
  //old wrong MAC ADDRESS
    // getting the mac address //Serial.println(MAC_char); - See more at: http://www.esp8266.com/viewtopic.php?f=29&amp;t=3587#sthash.bwWPqcc6.dpuf
        WiFi.macAddress(MAC_array);
      for (int i = 0; i &lt; sizeof(MAC_array); ++i){
        sprintf(MAC_char,"%s%02x:",MAC_char,MAC_array[i]);
      }
  
    // We now create a URI for the request
    String url = "/store.php";                // String url = "/input/";
    url += "?dev_id=";
    url += "BikeShare9";
    url += "&amp;hoster=";
    url += MAC_char;
    url += "&amp;ip_add=";
    url += WiFi.localIP();
  
    Serial.print("Requesting URL: ");
    Serial.println(url);
  
    // This will send the request to the server
      client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" + 
                 "Connection: close\r\n\r\n");
    unsigned long timeout = millis();
    while (client.available() == 0) {
      if (millis() - timeout &gt; 5000) {
        Serial.println("&gt;&gt;&gt; Client Timeout !");
        client.stop();
        return;
      }
    }
  
     // Read all the lines of the reply from server and print them to Serial
    while(client.available()){
      String line = client.readStringUntil('\r');
      Serial.print(line);
    }
  
    Serial.println();
    Serial.println("closing connection");
  }
  </code></pre>
  
  <p>For <code>void wifi_handle_event_cb(System_Event_t *evt)</code> I get the following error:</p>
  
  <pre><code>C:\Users\Tinotenda\Desktop\ver1.0\ver1.0.ino: In function 'void setup()':
  
  ver1.0:48: error: a function-definition is not allowed here before '{' token
  
   void loop() {
  
               ^
  
  ver1.0:129: error: expected '}' at end of input
  
   }
  
   ^
  
  exit status 1
  a function-definition is not allowed here before '{' token
  </code></pre>
  
  <p>How can I fix that?</p>