diff --git a/src/main.c b/src/main.c index 0311334..901434c 100644 --- a/src/main.c +++ b/src/main.c @@ -202,7 +202,28 @@ void app_main(void) { } } - ESP_LOGI(TAG, "WiFi Connected, continuing main task thread . . . "); + // Create a timer to auto-shutdown the AP after 5 minutes + TimerHandle_t ap_shutdown_timer = xTimerCreate( + "ap_shutdown_timer", + pdMS_TO_TICKS(2 * 60 * 1000), // 2 minutes in milliseconds + pdFALSE, // One-shot timer + NULL, // No timer ID + wifi_shutdown_ap // Callback function (now with correct signature) + ); + + if (ap_shutdown_timer != NULL) { + // Timer created successfully, now try to start it + BaseType_t timer_started = xTimerStart(ap_shutdown_timer, 0); + if (timer_started == pdPASS) { + ESP_LOGI(TAG, "AP will automatically shut down in 2 minutes"); + } else { + ESP_LOGE(TAG, "Failed to start AP shutdown timer"); + // Clean up the timer if we couldn't start it + xTimerDelete(ap_shutdown_timer, 0); + } + } else { + ESP_LOGE(TAG, "Failed to create AP shutdown timer"); + } // Get the image URL from WiFi manager const char* image_url = wifi_get_image_url(); diff --git a/src/wifi.c b/src/wifi.c index 3662c92..7bcbd6a 100644 --- a/src/wifi.c +++ b/src/wifi.c @@ -62,44 +62,49 @@ static void (*s_connect_callback)(void) = NULL; static void (*s_disconnect_callback)(void) = NULL; // HTML for the configuration page -static const char *s_html_page = "" -"" -"" -"Tronbyt WiFi Setup" -"" -"" -"" -"" -"
" -"

Tronbyt WiFi Setup

" -"
" -"
" -"" -"" -"
" -"
" -"" -"" -"
" -"
" -"" -"" -"
" -"" -"
" -"
" -"" -""; +static const char *s_html_page = + "" + "" + "" + "Tronbyt WiFi Setup" + "" + "" + "" + "" + "
" + "

Tronbyt WiFi Setup

" + "
" + "
" + "" + "" + "
" + "
" + "" + "" + "
" + "
" + "" + "" + "( If modifying Image URL reboot Tronbyt after saving. )" + "
" + "" + "
" + "
" + "" + ""; // Success page HTML static const char *s_success_html = "" @@ -117,6 +122,7 @@ static const char *s_success_html = "" "

Configuration Saved!

" "

WiFi credentials and image URL have been saved.

" "

The device will now attempt to connect to the WiFi network.

" +"

If you modified a previously saved Image URL please manually reboot your tron for the changes to take effect." "

You can close this page.

" "" ""; @@ -295,6 +301,13 @@ static bool has_saved_config = false; return 0; } +// Shutdown the AP by switching wifi mode to STA +void wifi_shutdown_ap(TimerHandle_t xTimer) { + ESP_LOGI(TAG, "Shutting down config portal"); + stop_webserver(); + esp_wifi_set_mode(WIFI_MODE_STA); +} + // Shutdown WiFi void wifi_shutdown() { // Stop the web server if it's running @@ -737,8 +750,8 @@ static void url_decode(char *str) { *dst = (char)strtol(hex, NULL, 16); src += 3; } else if (*src == '+') { - *dst = ' '; - src++; + *dst = ' '; + src++; } else { *dst = *src; src++; diff --git a/src/wifi.h b/src/wifi.h index edf739a..94275d2 100644 --- a/src/wifi.h +++ b/src/wifi.h @@ -14,6 +14,12 @@ */ int wifi_initialize(const char *ssid, const char *password); + +/** + * @brief Shutdown WiFi Config Portal + */ +void wifi_shutdown_ap(TimerHandle_t xTimer); + /** * @brief Shutdown WiFi */