wifi restart implementation in progress
This commit is contained in:
parent
1e9bbccd66
commit
2b6f70378c
|
|
@ -56,7 +56,10 @@ void StartTimeGet(void);
|
|||
|
||||
void WiFiAPStart(void);
|
||||
void WiFiSTAStart(void);
|
||||
void WiFiStop(void);
|
||||
|
||||
void WiFiDisconnect(void);
|
||||
void WiFiConnect(void);
|
||||
|
||||
void WiFiScan(void);
|
||||
void EthStart(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -482,12 +482,12 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
|
|||
{
|
||||
if (!strcmp(tmp, (const char*) "1"))
|
||||
{
|
||||
WiFiAPStart();
|
||||
WiFiConnect();
|
||||
return HTTP_IO_DONE_NOREFRESH;
|
||||
}
|
||||
else if (!strcmp(tmp, (const char*) "2"))
|
||||
{
|
||||
WiFiStop();
|
||||
WiFiDisconnect();
|
||||
return HTTP_IO_DONE_NOREFRESH;
|
||||
}
|
||||
else if (!strcmp(tmp, (const char*) "3"))
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ static EventGroupHandle_t s_wifi_event_group;
|
|||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
static int s_retry_num = 0;
|
||||
static bool isWiFiGotIp = false;
|
||||
|
||||
#define DEFAULT_SCAN_LIST_SIZE 20
|
||||
|
|
@ -82,32 +81,42 @@ 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();
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_STOP)
|
||||
{
|
||||
isWiFiGotIp = false;
|
||||
ESP_LOGI(TAG, "WiFi STA stopped");
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED)
|
||||
{
|
||||
|
||||
ESP_LOGI(TAG, "Connected to AP");
|
||||
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
|
||||
{
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
}
|
||||
else
|
||||
{
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
isWiFiGotIp = false;
|
||||
ESP_LOGI(TAG, "connect to the AP fail");
|
||||
esp_wifi_connect();
|
||||
ESP_LOGI(TAG, "Disconnected from AP, try reconnect...");
|
||||
}
|
||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
{
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t*) event_data;
|
||||
const esp_netif_ip_info_t *ip_info = &event->ip_info;
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
s_retry_num = 0;
|
||||
|
||||
memcpy(&GetSysConf()->wifiSettings.InfIPAddr, &event->ip_info.ip, sizeof(event->ip_info.ip));
|
||||
memcpy(&GetSysConf()->wifiSettings.InfMask, &event->ip_info.netmask, sizeof(event->ip_info.netmask));
|
||||
memcpy(&GetSysConf()->wifiSettings.InfGateway, &event->ip_info.gw, sizeof(event->ip_info.gw));
|
||||
|
||||
ESP_LOGI(TAG, "WIFI Got IP Address");
|
||||
ESP_LOGI(TAG, "~~~~~~~~~~~");
|
||||
ESP_LOGI(TAG, "WIFIIP:" IPSTR, IP2STR(&ip_info->ip));
|
||||
ESP_LOGI(TAG, "WIFIMASK:" IPSTR, IP2STR(&ip_info->netmask));
|
||||
ESP_LOGI(TAG, "WIFIGW:" IPSTR, IP2STR(&ip_info->gw));
|
||||
ESP_LOGI(TAG, "~~~~~~~~~~~");
|
||||
|
||||
isWiFiGotIp = true;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
|
|
@ -115,19 +124,16 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
|||
if (event_id == WIFI_EVENT_AP_STACONNECTED)
|
||||
{
|
||||
wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t*) event_data;
|
||||
ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
|
||||
MAC2STR(event->mac),
|
||||
event->aid);
|
||||
ESP_LOGI(TAG, "station "MACSTR" join, AID=%d", MAC2STR(event->mac), event->aid);
|
||||
}
|
||||
else if (event_id == WIFI_EVENT_AP_STADISCONNECTED)
|
||||
{
|
||||
wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t*) event_data;
|
||||
ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d",
|
||||
MAC2STR(event->mac),
|
||||
event->aid);
|
||||
ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d", MAC2STR(event->mac), event->aid);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
static void wifi_init_softap(void *pvParameter)
|
||||
{
|
||||
char if_key_str[24];
|
||||
|
|
@ -197,6 +203,7 @@ static void wifi_init_softap(void *pvParameter)
|
|||
ESP_LOGI(TAG, "wifi_init_softap finished");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
*/
|
||||
|
||||
static void wifi_init_sta(void *pvParameter)
|
||||
{
|
||||
|
|
@ -286,6 +293,7 @@ static void wifi_init_sta(void *pvParameter)
|
|||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
/*
|
||||
if (bits & WIFI_CONNECTED_BIT)
|
||||
{
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
|
|
@ -302,7 +310,7 @@ static void wifi_init_sta(void *pvParameter)
|
|||
{
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
|
||||
*/
|
||||
/* The event will not be processed after unregister */
|
||||
// ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip));
|
||||
// ESP_ERROR_CHECK(esp_event_handler_instance_unregister( WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id));
|
||||
|
|
@ -466,6 +474,7 @@ static void wifi_init_apsta(void *pvParameter)
|
|||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
/*
|
||||
if (bits & WIFI_CONNECTED_BIT)
|
||||
{
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
|
|
@ -482,13 +491,13 @@ static void wifi_init_apsta(void *pvParameter)
|
|||
{
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
*/
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void WiFiAPStart(void)
|
||||
{
|
||||
//xTaskCreate(wifi_init_softap, "InitSoftAPTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||
xTaskCreate(wifi_init_apsta, "InitSoftAPTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -497,10 +506,14 @@ void WiFiSTAStart(void)
|
|||
xTaskCreate(wifi_init_sta, "InitStationTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||
}
|
||||
|
||||
void WiFiStop(void)
|
||||
void WiFiDisconnect(void)
|
||||
{
|
||||
esp_wifi_scan_stop();
|
||||
esp_wifi_deinit();
|
||||
esp_wifi_disconnect();
|
||||
}
|
||||
|
||||
void WiFiConnect(void)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
}
|
||||
|
||||
static void wifi_scan(void *arg)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user