diff --git a/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h b/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h index 043b14e20..eda48be0f 100644 --- a/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h +++ b/components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h @@ -29,6 +29,19 @@ extern "C" { */ extern const wifi_prov_scheme_t wifi_prov_scheme_softap; +/** + * + * @brief Provide HTTPD Server handle externally. + * + * Useful in cases wherein applications need the webserver for some + * different operations, and do not want the wifi provisioning component + * to start/stop a new instance. + * + * @note This API should be called before wifi_prov_mgr_start_provisioning() + * + * @param[in] handle Handle to HTTPD server instance + */ +void wifi_prov_scheme_softap_set_httpd_handle(void *handle); #ifdef __cplusplus } #endif diff --git a/components/wifi_provisioning/src/scheme_softap.c b/components/wifi_provisioning/src/scheme_softap.c index 84262e937..2b0c3c242 100644 --- a/components/wifi_provisioning/src/scheme_softap.c +++ b/components/wifi_provisioning/src/scheme_softap.c @@ -33,7 +33,7 @@ typedef struct softap_config { static const char *TAG = "wifi_prov_scheme_softap"; extern const wifi_prov_scheme_t wifi_prov_scheme_softap; - +static void *scheme_softap_prov_httpd_handle; static esp_err_t start_wifi_ap(const char *ssid, const char *pass) { /* Build Wi-Fi configuration for AP mode */ @@ -85,6 +85,11 @@ static esp_err_t prov_start(protocomm_t *pc, void *config) protocomm_httpd_config_t *httpd_config = &softap_config->httpd_config; + if (scheme_softap_prov_httpd_handle) { + httpd_config->ext_handle_provided = true; + httpd_config->data.handle = scheme_softap_prov_httpd_handle; + } + /* Start protocomm server on top of HTTP */ esp_err_t err = protocomm_httpd_start(pc, httpd_config); if (err != ESP_OK) { @@ -186,6 +191,11 @@ static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, ui return ESP_OK; } +void wifi_prov_scheme_softap_set_httpd_handle(void *handle) +{ + scheme_softap_prov_httpd_handle = handle; +} + const wifi_prov_scheme_t wifi_prov_scheme_softap = { .prov_start = prov_start, .prov_stop = prov_stop,