代码如下:
wifi_set_opmode_current(STATION_IF);
if(!wifi_station_scan(NULL, wifi_station_scan_cb))
{
printf("station scan failed.\r\n");
}
执行结果总是打印station scan failed.为什么呢?
RTOS版本wifi_station_scan为什么总是失败
-
- Posts: 20
- Joined: Fri Jul 24, 2015 3:00 pm
Re: RTOS版本wifi_station_scan为什么总是失败
Postby ESP_Faye » Thu Aug 20, 2015 1:52 pm
您好,
请勿在 user_init 中调用 wifi_station_scan,ESP8266 station 接口初始化完成后,才可以扫描附近 AP。
您可以参考如下代码:
请勿在 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 53 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.