我最近一直在玩 SDK,我可以连接到 AP 并闪烁 LED 等等,但是当我尝试扫描附近的 AP 时,状态代码总是显示 FAIL。
这是我的代码,我已经 3 天改变了一些东西,但没有任何效果。希望任何人都可以提示
谢谢!
代码:
全选#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "ip_addr.h"
#include "espconn.h"
#include "user_interface.h"
#include "user_config.h"
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
sta
tic void loop(os_event_t *events);
/** WIFI Functions **/
void ICACHE_FLASH_ATTR wifiInit() {
os_printf(">>>%s\n", __FUNCTION__);
//wifi_station_set_hostname("autolocator");
wifi_set_opmode(STATION_MODE);
os_printf("<<<%s\n", __FUNCTION__);
}
static void ICACHE_FLASH_ATTR wifiScan_cb(void *arg, STATUS status) {
os_printf(">>>%s\n", __FUNCTION__);
uint8 ssid[33];
switch (status ) {
case OK:
os_printf("Status OK\n");
struct bss_info *bss_link = (struct bss_info *)arg;
bss_link = bss_link->next.stqe_next;//ignore first
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_sprintf("+CWLAP:(%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;
}
break;
case FAIL:
os_printf("Status FAIL\n");
break;
case PENDING:
os_printf("Status PENDING\n");
break;
case BUSY:
os_printf("Status BUSY\n");
break;
case CANCEL:
os_printf("Status CANCEL\n");
break;
default:
os_printf("Status UNKNOWN\n");
break;
}
os_printf("<<<%s\n", __FUNCTION__);
}
/** UART Functions **/
void ICACHE_FLASH_ATTR uartInit() {
os_printf(">>>%s\n", __FUNCTION__ );
uart_div_modify( 0, UART_CLK_FREQ / ( 115200 ) );
os_printf("<<<%s\n", __FUNCTION__);
}
/** GPIO Functions **/
void ICACHE_FLASH_ATTR gpioInit() {
os_printf(">>>%s\n", __FUNCTION__ );
gpio_init();
os_printf("<<<%s\n", __FUNCTION__);
}
/** Entry point **/
//Main code function
void ICACHE_FLASH_ATTR loop(os_event_t *events) {
os_printf(">>>%s\n", __FUNCTION__ );
os_delay_us(1*1000000);
wifi_promiscuous_enable(0);
os_printf("mode=%u\n",wifi_get_opmode());
os_printf("set mode=%u\n", wifi_set_opmode(STATION_MODE));
os_printf("mode_afterset=%u\n",wifi_get_opmode());
os_printf("scan_result=%u\n",wifi_station_scan(NULL,wifiScan_cb));
system_os_post(user_procTaskPrio,
0,
0);
os_printf("<<<%s\n", __FUNCTION__);
}
void ICACHE_FLASH_ATTR user_rf_pre_init(void) {}
//Init function
void ICACHE_FLASH_ATTR user_init( void ) {
os_printf(">>>%s\n", __FUNCTION__ );
uartInit();
os_delay_us(0.1*1000000);
gpioInit();
wifiInit();
//Start os task
//os_delay_us(5*1000000);
system_os_task(loop,
user_procTaskPrio,
user_procTaskQueue,
user_procTaskQueueLen);
system_os_post(user_procTaskPrio,
0,
0);
os_printf("<<<%s\n", __FUNCTION__);
}
0