temporal solution of AP and STA coexistence
This commit is contained in:
parent
d7d38b1524
commit
89d33842ec
|
|
@ -55,6 +55,7 @@ static int TempAPCounter = 0;
|
|||
#define DEFAULT_SCAN_LIST_SIZE 20
|
||||
static wifi_ap_record_t ap_info[DEFAULT_SCAN_LIST_SIZE];
|
||||
static bool isScanExecuting = false;
|
||||
static bool isStaConnecting = false;
|
||||
|
||||
wifi_ap_record_t* GetWiFiAPRecord(uint8_t n)
|
||||
{
|
||||
|
|
@ -93,8 +94,11 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
|||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||
{
|
||||
ESP_LOGI(TAG, "WiFi STA started, connecting to AP...");
|
||||
esp_wifi_connect();
|
||||
if (GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA)
|
||||
{
|
||||
ESP_LOGI(TAG, "WiFi STA started, connecting to AP...");
|
||||
esp_wifi_connect();
|
||||
}
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_STOP)
|
||||
{
|
||||
|
|
@ -374,19 +378,17 @@ static void wifi_init_apsta(void *pvParameter)
|
|||
;
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&ap_cfg));
|
||||
/*
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
NULL));
|
||||
*/
|
||||
wifi_config_t ap_wifi_config = {
|
||||
.ap = {
|
||||
|
||||
.channel = EXAMPLE_ESP_WIFI_CHANNEL,
|
||||
.max_connection = EXAMPLE_MAX_STA_CONN,
|
||||
.authmode = WIFI_AUTH_WPA_WPA2_PSK
|
||||
.authmode = WIFI_AUTH_WPA_WPA2_PSK,
|
||||
/*
|
||||
.pmf_cfg = {
|
||||
.capable = false,
|
||||
.required = false}
|
||||
*/
|
||||
},
|
||||
};
|
||||
if (strlen(CONFIG_WEBGUIAPP_WIFI_KEY_AP) == 0)
|
||||
|
|
@ -447,10 +449,12 @@ static void wifi_init_apsta(void *pvParameter)
|
|||
* doesn't support WPA2, these mode can be enabled by commenting below line */
|
||||
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
|
||||
.pmf_cfg = {
|
||||
.capable = true,
|
||||
.required = false
|
||||
},
|
||||
/*
|
||||
.pmf_cfg = {
|
||||
.capable = false,
|
||||
.required = false
|
||||
},
|
||||
*/
|
||||
},
|
||||
};
|
||||
memcpy(sta_wifi_config.sta.ssid, GetSysConf()->wifiSettings.InfSSID, strlen(GetSysConf()->wifiSettings.InfSSID));
|
||||
|
|
@ -461,6 +465,8 @@ static void wifi_init_apsta(void *pvParameter)
|
|||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_wifi_config));
|
||||
esp_wifi_disable_pmf_config(WIFI_IF_STA);
|
||||
esp_wifi_disable_pmf_config(WIFI_IF_AP);
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
int max_power = GetSysConf()->wifiSettings.MaxPower;
|
||||
|
|
@ -486,13 +492,16 @@ void WiFiConnect(void)
|
|||
esp_wifi_connect();
|
||||
}
|
||||
|
||||
#define RECONNECT_INTERVAL 10
|
||||
#define RECONNECT_INTERVAL_AP 200
|
||||
#define RECONNECT_INTERVAL_STA 20
|
||||
#define WAITIP_INTERVAL 10
|
||||
|
||||
static void WiFiControlTask(void *arg)
|
||||
{
|
||||
//WiFi init and start block
|
||||
static int reconnect_counter = RECONNECT_INTERVAL;
|
||||
static int reconnect_counter;
|
||||
reconnect_counter =
|
||||
(GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA) ? RECONNECT_INTERVAL_STA : RECONNECT_INTERVAL_AP;
|
||||
static int waitip_counter = WAITIP_INTERVAL;
|
||||
//s_wifi_event_group = xEventGroupCreate();
|
||||
switch (GetSysConf()->wifiSettings.WiFiMode)
|
||||
|
|
@ -515,7 +524,7 @@ static void WiFiControlTask(void *arg)
|
|||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
if (isWiFiConnected)
|
||||
{
|
||||
reconnect_counter = RECONNECT_INTERVAL;
|
||||
reconnect_counter = RECONNECT_INTERVAL_STA;
|
||||
if (!isWiFiGotIp)
|
||||
{
|
||||
if (--waitip_counter <= 0)
|
||||
|
|
@ -532,7 +541,10 @@ static void WiFiControlTask(void *arg)
|
|||
{
|
||||
ESP_LOGI(TAG, "WiFi STA started, reconnecting to AP...");
|
||||
esp_wifi_connect();
|
||||
reconnect_counter = RECONNECT_INTERVAL;
|
||||
reconnect_counter =
|
||||
(GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA) ?
|
||||
RECONNECT_INTERVAL_STA :
|
||||
RECONNECT_INTERVAL_AP;
|
||||
}
|
||||
}
|
||||
if (TempAPCounter > 0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user