Merge branch 'main2' of git@gitlab.com:userbogd/webguiapp.git into main2

# Conflicts:
#	include/NetTransport.h
This commit is contained in:
Bogdan Pilyugin 2023-02-01 22:17:54 +02:00
commit 0cd3d9f1f9
2 changed files with 130 additions and 112 deletions

View File

@ -491,14 +491,12 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
{ {
if (!strcmp(tmp, (const char*) "1")) if (!strcmp(tmp, (const char*) "1"))
{ {
WiFiScan(); WiFiConnect();
return HTTP_IO_DONE_NOREFRESH; return HTTP_IO_DONE_NOREFRESH;
} }
else if (!strcmp(tmp, (const char*) "2")) else if (!strcmp(tmp, (const char*) "2"))
{ {
#if CONFIG_WEBGUIAPP_GPRS_ENABLE WiFiDisconnect();
PPPModemGetRSSI();
#endif
return HTTP_IO_DONE_NOREFRESH; return HTTP_IO_DONE_NOREFRESH;
} }
else if (!strcmp(tmp, (const char*) "3")) else if (!strcmp(tmp, (const char*) "3"))

View File

@ -45,7 +45,6 @@ static EventGroupHandle_t s_wifi_event_group;
#define WIFI_CONNECTED_BIT BIT0 #define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1 #define WIFI_FAIL_BIT BIT1
static int s_retry_num = 0;
static bool isWiFiGotIp = false; static bool isWiFiGotIp = false;
#define DEFAULT_SCAN_LIST_SIZE 20 #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) if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
{ {
ESP_LOGI(TAG, "WiFi STA started, connecting to AP...");
esp_wifi_connect(); 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) 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; 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) 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; 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)); 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.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.InfMask, &event->ip_info.netmask, sizeof(event->ip_info.netmask));
memcpy(&GetSysConf()->wifiSettings.InfGateway, &event->ip_info.gw, sizeof(event->ip_info.gw)); 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; isWiFiGotIp = true;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); 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) if (event_id == WIFI_EVENT_AP_STACONNECTED)
{ {
wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t*) event_data; wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t*) event_data;
ESP_LOGI(TAG, "station "MACSTR" join, AID=%d", ESP_LOGI(TAG, "station "MACSTR" join, AID=%d", MAC2STR(event->mac), event->aid);
MAC2STR(event->mac),
event->aid);
} }
else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) else if (event_id == WIFI_EVENT_AP_STADISCONNECTED)
{ {
wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t*) event_data; wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t*) event_data;
ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d", ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d", MAC2STR(event->mac), event->aid);
MAC2STR(event->mac),
event->aid);
} }
} }
/*
static void wifi_init_softap(void *pvParameter) static void wifi_init_softap(void *pvParameter)
{ {
char if_key_str[24]; char if_key_str[24];
@ -197,6 +203,7 @@ static void wifi_init_softap(void *pvParameter)
ESP_LOGI(TAG, "wifi_init_softap finished"); ESP_LOGI(TAG, "wifi_init_softap finished");
vTaskDelete(NULL); vTaskDelete(NULL);
} }
*/
static void wifi_init_sta(void *pvParameter) 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 /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */ * happened. */
/*
if (bits & WIFI_CONNECTED_BIT) if (bits & WIFI_CONNECTED_BIT)
{ {
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", 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"); ESP_LOGE(TAG, "UNEXPECTED EVENT");
} }
*/
/* The event will not be processed after unregister */ /* 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(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)); // 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 /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */ * happened. */
/*
if (bits & WIFI_CONNECTED_BIT) if (bits & WIFI_CONNECTED_BIT)
{ {
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
@ -482,6 +491,7 @@ static void wifi_init_apsta(void *pvParameter)
{ {
ESP_LOGE(TAG, "UNEXPECTED EVENT"); ESP_LOGE(TAG, "UNEXPECTED EVENT");
} }
*/
vTaskDelete(NULL); vTaskDelete(NULL);
} }
@ -501,6 +511,16 @@ void WiFiSTAStart(void)
xTaskCreate(wifi_init_sta, "InitStationTask", 1024 * 4, (void*) 0, 3, NULL); xTaskCreate(wifi_init_sta, "InitStationTask", 1024 * 4, (void*) 0, 3, NULL);
} }
void WiFiDisconnect(void)
{
esp_wifi_disconnect();
}
void WiFiConnect(void)
{
esp_wifi_connect();
}
static void wifi_scan(void *arg) static void wifi_scan(void *arg)
{ {
uint16_t number = DEFAULT_SCAN_LIST_SIZE; uint16_t number = DEFAULT_SCAN_LIST_SIZE;