RTOS版本wifi_station_scan为什么总是失败

Lucifer3502
Posts: 20
Joined: Fri Jul 24, 2015 3:00 pm

RTOS版本wifi_station_scan为什么总是失败

Postby Lucifer3502 » Thu Aug 20, 2015 9:27 am

代码如下:
wifi_set_opmode_current(STATION_IF);

if(!wifi_station_scan(NULL, wifi_station_scan_cb))
{
printf("station scan failed.\r\n");
}

执行结果总是打印station scan failed.为什么呢?

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: RTOS版本wifi_station_scan为什么总是失败

Postby ESP_Faye » Thu Aug 20, 2015 1:52 pm

您好,

请勿在 user_init 中调用 wifi_station_scan,ESP8266 station 接口初始化完成后,才可以扫描附近 AP。

您可以参考如下代码:

Code: Select all


void scan_done(void *arg, STATUS status)
{
  uint8 ssid[33];
  char temp[128];

  if (status == OK)
  {
    struct bss_info *bss_link = (struct bss_info *)arg;
    bss_link = bss_link->next.stqe_next;//ignore the first one , it's invalid.

    while (bss_link != NULL)
    {
      memset(ssid, 0, 33);
      if (strlen(bss_link->ssid) <= 32)
      {
        memcpy(ssid, bss_link->ssid, strlen(bss_link->ssid));
      }
      else
      {
        memcpy(ssid, bss_link->ssid, 32);
      }
      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
  {
     printf("scan fail !!!\r\n");
  }

}

void user_scan(void)
{
    // wifi scan has to after system init done

   if(wifi_get_opmode() == SOFTAP_MODE)
   {
     printf("ap mode can't scan !!!\r\n");
     return;
   }
   wifi_station_scan(NULL,scan_done);

}


void scan_task(void *pvParameters)
{
    printf("Hello, welcome to scan-task!\r\n");

    user_scan();

while (1) {

}
}
void user_init(void)
{
   //Set softAP + station mode
   wifi_set_opmode(STATIONAP_MODE);
   
   xTaskCreate(scan_task, "scantsk", 256, NULL, 2, NULL);

}

Who is online

Users browsing this forum: No registered users and 28 guests