ESP8266 Developer Zone The Official ESP8266 Forum 2019-09-25T11:30:33+08:00 https://bbs.espressif.com:443/feed.php?f=31&t=229 2019-09-25T11:30:33+08:00 2019-09-25T11:30:33+08:00 https://bbs.espressif.com:443/viewtopic.php?t=229&p=66098#p66098 <![CDATA[ESP8266 Station mode Scan for routers]]> Statistics: Posted by Tofd8lger — Wed Sep 25, 2019 11:30 am


]]>
2015-02-28T11:24:00+08:00 2015-02-28T11:24:00+08:00 https://bbs.espressif.com:443/viewtopic.php?t=229&p=839#p839 <![CDATA[[ESP8266] Station mode: Scan for routers]]>
ESP8266 init with station mode, then it can scan routers nearby.

Code:

/******************************************************************************
 * FunctionName : scan_done
 * Description  : scan done callback
 * Parameters   :  arg: contain the aps information;
                          status: scan over status
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
scan_done(void *arg, STATUS status)
{
  uint8 ssid[33];
  char temp[128];

  if (status == OK)
  {
    struct bss_info *bss_link = (struct bss_info *)arg;

    while (bss_link != NULL)
    {
      os_memset(ssid, 0, 33);
      if (os_strlen(bss_link->ssid) <= 32)
      {
        os_memcpy(ssid, bss_link->ssid, os_strlen(bss_link->ssid));
      }
      else
      {
        os_memcpy(ssid, bss_link->ssid, 32);
      }
      os_printf("(%d,\"%s\",%d,\""MACSTR"\",%d)\r\n",
                 bss_link->authmode, ssid, bss_link->rssi,
                 MAC2STR(bss_link->bssid),bss_link->channel);
      bss_link = bss_link->next.stqe_next;
    }
  }
  else
  {
     os_printf("scan fail !!!\r\n");
  }

}

/******************************************************************************
 * FunctionName : user_scan
 * Description  : wifi scan, only can be called after system init done.
 * Parameters   :  none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_scan(void)
{
   if(wifi_get_opmode() == SOFTAP_MODE)
   {
     os_printf("ap mode can't scan !!!\r\n");
     return;
   }
   wifi_station_scan(NULL,scan_done);

}


/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());
   
   //Set softAP + station mode
   wifi_set_opmode(STATIONAP_MODE);

   // wifi scan has to after system init done.
   system_init_done_cb(user_scan);

}


If you want to scan a specific AP, for example, scan an AP of which SSID is "ESP8266". You only need to set the value of parameter "SSID" in structure "scan_config" when calling wifi_station_scan.

Code:

void ICACHE_FLASH_ATTR
user_scan(void)
{
   if(wifi_get_opmode() == SOFTAP_MODE)
   {
     os_printf("ap mode can't scan !!!\r\n");
     return;
   }
   struct scan_config config;

   os_memset(&config, 0, sizeof(config));

   config.ssid = "ESP8266";
   
   wifi_station_scan(&config,scan_done);

}

Statistics: Posted by ESP_Faye — Sat Feb 28, 2015 11:24 am


]]>