Skip to content

Commit

Permalink
Fixed : First Stable Version
Browse files Browse the repository at this point in the history
  • Loading branch information
bulutbekdemir committed May 31, 2024
1 parent 94f8ff0 commit 3edc708
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
28 changes: 16 additions & 12 deletions components/wifiManager/Src/wifiManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static void wm_init_task(void *pvParameters)
while (1)
{
EventBits_t uxBits = xEventGroupWaitBits(wm_task_event_group, WM_EVENTG_TASK_ALL_INIT | WM_EVENTG_TASK_WIFI_INIT
| WM_EVENTG_TASK_DEINIT, pdTRUE, pdFALSE, portMAX_DELAY);
| WM_EVENTG_TASK_DEINIT, pdFALSE, pdFALSE, portMAX_DELAY);

if ((uxBits & WM_EVENTG_TASK_WIFI_INIT) != 0)
{
Expand All @@ -182,10 +182,15 @@ static void wm_init_task(void *pvParameters)
}else if ((uxBits & WM_EVENTG_TASK_DEINIT) != 0){
ESP_LOGI(TAG, "Deinit Task Triggered");
wm_http_server_stop();
xEventGroupWaitBits(wm_main_event_group, WM_EVENTG_MAIN_HTTP_CLOSED, pdFALSE, pdFALSE, portMAX_DELAY);
wm_scan_task_stop();
xEventGroupWaitBits(wm_main_event_group, WM_EVENTG_MAIN_SCAN_TASK_CLOSED, pdFALSE, pdFALSE, portMAX_DELAY);
xEventGroupSetBits(wm_task_event_group, WM_EVENTG_TASK_DEINIT_DONE);
xEventGroupClearBits(wm_task_event_group, WM_EVENTG_TASK_DEINIT);
ESP_LOGI(TAG, "Deinit Completed");
vTaskDelete(NULL);
}
xEventGroupClearBits(wm_task_event_group, WM_EVENTG_TASK_ALL_INIT | WM_EVENTG_TASK_WIFI_INIT);
}
}

Expand All @@ -212,18 +217,15 @@ static void wm_http_server_start(void)
*/
static void wm_http_server_stop(void)
{
ESP_LOGI(TAG, "Stopping HTTP Server");
BaseType_t xReturn = http_server_stop();
if (xReturn != pdPASS)
{
ESP_LOGE(TAG, "Failed to stop HTTP Server");
return;
}
vEventGroupDelete(wm_http_event_group);
if (wm_http_event_group != NULL)
{
wm_http_event_group = NULL;
}
xEventGroupClearBits(wm_main_event_group, WM_EVENTG_MAIN_HTTP_OPEN);
ESP_LOGI(TAG, "HTTP Server Stopped");
xEventGroupSetBits(wm_main_event_group, WM_EVENTG_MAIN_HTTP_CLOSED);
}

Expand All @@ -236,7 +238,7 @@ static void wm_scan_task_start(void)
{
BaseType_t xReturned = pdFAIL;
xReturned = xTaskCreatePinnedToCore(&wm_wifi_scan_task, "wm_scan_task", WIFI_SCAN_TASK_STACK_SIZE, NULL, \
WIFI_SCAN_TASK_PRIORITY, NULL, WIFI_SCAN_TASK_CORE_ID);
WIFI_SCAN_TASK_PRIORITY, &wm_wifi_scan_task_handle, WIFI_SCAN_TASK_CORE_ID);
if (xReturned != pdPASS)
{
ESP_LOGE(TAG, "Failed to create Wifi Scan Task");
Expand All @@ -252,16 +254,18 @@ static void wm_scan_task_start(void)
*/
static void wm_scan_task_stop(void)
{
vQueueDelete(wm_queue_wifi_scan_handle);
if (wm_queue_wifi_scan_handle != NULL)
{
wm_queue_wifi_scan_handle = NULL;
}
ESP_LOGI(TAG, "Stopping Wifi Scan Task");
vTaskDelete(wm_wifi_scan_task_handle);
if (wm_wifi_scan_task_handle != NULL)
{
wm_wifi_scan_task_handle = NULL;
}
vQueueDelete(wm_queue_wifi_scan_handle);
if (wm_queue_wifi_scan_handle != NULL)
{
wm_queue_wifi_scan_handle = NULL;
}
ESP_LOGI(TAG, "Wifi Scan Task Stopped and Queue Deleted");
xEventGroupSetBits(wm_main_event_group, WM_EVENTG_MAIN_SCAN_TASK_CLOSED);
}

16 changes: 8 additions & 8 deletions components/wifiManager/Src/wm_httpServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,23 +483,23 @@ BaseType_t http_server_init(void)
*/
BaseType_t http_server_stop(void)
{
if(wm_http_server_task_handle != NULL)
if(wm_http_wifi_request_semaphore != NULL)
{
httpd_stop(wm_http_server_task_handle);
wm_http_server_task_handle = NULL;
vSemaphoreDelete(wm_http_wifi_request_semaphore);
wm_http_wifi_request_semaphore = NULL;
}
else
{
ESP_LOGW(TAG, "HTTP Server is already stopped");
ESP_LOGW(TAG, "HTTP Wifi Request Semaphore is already deleted");
}
if(wm_http_wifi_request_semaphore != NULL)
if(wm_http_server_task_handle != NULL)
{
vSemaphoreDelete(wm_http_wifi_request_semaphore);
wm_http_wifi_request_semaphore = NULL;
httpd_stop(wm_http_server_task_handle);
wm_http_server_task_handle = NULL;
}
else
{
ESP_LOGW(TAG, "HTTP Wifi Request Semaphore is already deleted");
ESP_LOGW(TAG, "HTTP Server is already stopped");
}
if(wm_http_server_task_handle == NULL && wm_http_wifi_request_semaphore == NULL)
{
Expand Down
27 changes: 20 additions & 7 deletions components/wifiManager/Src/wm_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ static void wifi_app_event_handler(void *arg, esp_event_base_t event_base, int32
break;*/
case WIFI_REASON_AUTH_FAIL:
ESP_LOGI(TAG, "Auth Fail");
if((mainStaBits & WM_EVENTG_MAIN_HTTP_OPEN) == WM_EVENTG_MAIN_HTTP_OPEN)
if(++wifi_connect_retry < 2)
{
xEventGroupSetBits(wm_http_event_group, WM_EVENTG_HTTP_WIFI_AUTH_FAIL);
}else
{
xEventGroupSetBits(wm_wifi_event_group, WM_EVENTG_WIFI_CONNECT_FAIL);
}
esp_wifi_connect();
}else {
ESP_LOGI(TAG, "Max Retries Reached for AUTH fail");
if((mainStaBits & WM_EVENTG_MAIN_HTTP_OPEN) == WM_EVENTG_MAIN_HTTP_OPEN)
{
xEventGroupSetBits(wm_http_event_group, WM_EVENTG_HTTP_WIFI_AUTH_FAIL);
}else
{
xEventGroupSetBits(wm_wifi_event_group, WM_EVENTG_WIFI_CONNECT_FAIL);
}
}
break;
default:
wifi_connect_retry++;
Expand Down Expand Up @@ -254,7 +260,7 @@ void wm_wifi_connect_task(void *pvParameters)
ESP_LOGI(TAG, "Wifi Connect Event Received");
EventBits_t mainBits;
mainBits = xEventGroupGetBits(wm_task_event_group);
if((mainBits & WM_EVENTG_TASK_ALL_INIT_DONE) != WM_EVENTG_TASK_ALL_INIT_DONE)
if((mainBits & WM_EVENTG_TASK_ALL_INIT_DONE) == WM_EVENTG_TASK_ALL_INIT_DONE)
{
xEventGroupSetBits(wm_http_event_group, WM_EVENTG_HTTP_BLOCK_REQ);
BaseType_t xStatus = wm_wifi_ap_close();
Expand All @@ -263,6 +269,7 @@ void wm_wifi_connect_task(void *pvParameters)
xEventGroupSetBits(wm_nvs_event_group, WM_EVENTG_NVS_WRITE_CREDS);
wm_wifi_send_message(&wifi_config_msg.wifi_config);
xEventGroupWaitBits(wm_nvs_event_group, WM_EVENTG_NVS_DONE, pdTRUE, pdFALSE, portMAX_DELAY);
xEventGroupClearBits(wm_main_event_group, WM_EVENTG_MAIN_AP_OPEN);
xEventGroupSetBits(wm_main_event_group, WM_EVENTG_MAIN_AP_CLOSED);
xEventGroupSetBits(wm_task_event_group, WM_EVENTG_TASK_DEINIT);
}
Expand All @@ -288,6 +295,12 @@ void wm_wifi_connect_task(void *pvParameters)
xEventGroupSetBits(wm_nvs_event_group, WM_EVENTG_NVS_CLEAR_CREDS);
xEventGroupWaitBits(wm_nvs_event_group, WM_EVENTG_NVS_DONE, pdTRUE, pdFALSE, portMAX_DELAY);
}
if((xEventGroupGetBits(wm_task_event_group) & WM_EVENTG_TASK_ALL_INIT) == WM_EVENTG_TASK_ALL_INIT)
{
ESP_LOGI(TAG, "Standard Init Process");
}else{
xEventGroupSetBits(wm_task_event_group, WM_EVENTG_TASK_ALL_INIT);
}
xEventGroupSetBits(wm_main_event_group, WM_EVENTG_MAIN_AP_OPEN);
}
}
Expand Down

0 comments on commit 3edc708

Please sign in to comment.