ESP8266设置为station+ap模式,手机可以连接AP,但是PC连接AP时连接不上,通过串口输出的信息看应该是PC反复连接,断开AP(ESP8266),请问是哪里出现问题?
我的代码如下:
#include "esp_common.h"
#include "uart.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
extern void vTask_ap( void * pvParameters );
extern void vTask_station( void * pvParameters );
void user_init(void)
{
xTaskHandle xHandle = NULL;
uart_init_new();
printf("SDK version:%s\n", system_get_sdk_version());
if(wifi_set_opmode_current(0x03) == 0)
{
printf("wifi set mode 0x03 failed!\r\n");
while(1);
}
printf("wifi set mode 0x03 success!\r\n");
xTaskCreate(
vTask_ap, /* Function that implements the task. */
"ap_task", /* Text name for the task. */
512, /* Stack size in words, not bytes. */
NULL, /* Parameter passed into the task. */
1,/* Priority at which the task is created. */
&xHandle ); /* Used to pass out the created task's handle. */
xTaskCreate(
vTask_station, /* Function that implements the task. */
"station_task", /* Text name for the task. */
512, /* Stack size in words, not bytes. */
NULL, /* Parameter passed into the task. */
1,/* Priority at which the task is created. */
&xHandle ); /* Used to pass out the created task's handle. */
}
void vTask_station( void * pvParameters )
{
while(1)
{
//printf("task_station\r\n");
vTaskDelay(2);
}
}
void wifi_handle_event_cb(System_Event_t *evt)
{
printf("event %x\n", evt->event_id);
switch (evt->event_id) {
case EVENT_STAMODE_CONNECTED:
printf("connect to ssid %s, channel %d\n",
evt->event_info.connected.ssid,
evt->event_info.connected.channel);
break;
case EVENT_STAMODE_DISCONNECTED:
printf("disconnect from ssid %s, reason %d\n",
evt->event_info.disconnected.ssid,
evt->event_info.disconnected.reason);
break;
case EVENT_STAMODE_AUTHMODE_CHANGE:
printf("mode: %d -> %d\n",
evt->event_info.auth_change.old_mode,
evt->event_info.auth_change.new_mode);
break;
case EVENT_STAMODE_GOT_IP:
printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
IP2STR(&evt->event_info.got_ip.ip),
IP2STR(&evt->event_info.got_ip.mask),
IP2STR(&evt->event_info.got_ip.gw));
printf("\n");
break;
case EVENT_SOFTAPMODE_STACONNECTED:
printf("station: " MACSTR "join, AID = %d\n",
MAC2STR(evt->event_info.sta_connected.mac),
evt->event_info.sta_connected.aid);
break;
case EVENT_SOFTAPMODE_STADISCONNECTED:
printf("station: " MACSTR "leave, AID = %d\n",
MAC2STR(evt->event_info.sta_disconnected.mac),
evt->event_info.sta_disconnected.aid);
break;
default:
break;
}
}
void vTask_ap( void * pvParameters )
{
struct station_info * station;
struct softap_config *config = (struct softap_config *)zalloc(sizeof(struct softap_config)); // initialization
wifi_set_event_handler_cb(wifi_handle_event_cb);
wifi_softap_get_config(config); // Get soft-AP config first.
sprintf(config->ssid, "test");
sprintf(config->password, "11111111");
config->authmode = AUTH_WPA_WPA2_PSK;
config->ssid_len = 0; // or its actual SSID length
config->max_connection = 2;
wifi_softap_set_config(config); // Set ESP8266 soft-AP config
free(config);
while(1)
{
//station = wifi_softap_get_station_info();
//while(station)
//{
//printf("bssid:%s\r\nip:%s\r\n",MAC2STR(station->bssid), IP2STR(&station->ip));
//station = STAILQ_NEXT(station, next);
//}
//wifi_softap_free_station_info(); // Free it by calling functions
//printf("task_ap\r\n");
vTaskDelay(2);
}
}
输出调试信息如下:
SDK version:1.4.0(c599790)
wifi set mode 0x03 success!
mode : sta(5c:cf:7f:12:67:b1) + softAP(5e:cf:7f:12:67:b1)
add if0
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
add if1
bcn 100
event 8
event 8
event 8
event 8
event 8
event 8
event 8
add 1
aid 1
station: 3c:46:d8:3a:6d:16 join, AID = 1
event 6
station: 3c:46:d8:3a:6d:16join, AID = 1
station: 3c:46:d8:3a:6d:16 leave, AID = 1
rm 1
event 7
station: 3c:46:d8:3a:6d:16leave, AID = 1
add 1
aid 1
station: 3c:46:d8:3a:6d:16 join, AID = 1
event 6
station: 3c:46:d8:3a:6d:16join, AID = 1
event 8
event 8
station: 3c:46:d8:3a:6d:16 leave, AID = 1
rm 1
event 7
station: 3c:46:d8:3a:6d:16leave, AID = 1
add 1
aid 1
station: 3c:46:d8:3a:6d:16 join, AID = 1
event 6
station: 3c:46:d8:3a:6d:16join, AID = 1
event 8
station: 3c:46:d8:3a:6d:16 leave, AID = 1
rm 1
event 7
station: 3c:46:d8:3a:6d:16leave, AID = 1
add 1
aid 1
station: 3c:46:d8:3a:6d:16 join, AID = 1
event 6
station: 3c:46:d8:3a:6d:16join, AID = 1
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.