wifi_provisioning_softap: Allow applications to start webserver externally

If an application wants to use webserver, instead of creating another
webserver instance, the wifi provisioning manager can re-use the same.
The webserver handle can be passed using this new API.

Signed-off-by: Piyush Shah <piyush@espressif.com>
This commit is contained in:
Piyush Shah 2019-11-27 17:41:47 +05:30
parent 9e49a5dc34
commit f9ec0a7172
2 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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,