EasyManua.ls Logo

Espressif ESP32-S2 - Page 595

Espressif ESP32-S2
1695 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 2. API Reference
//Function for starting the webserver
httpd_handle_t start_webserver(void)
{
// Generate default configuration
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
// Empty handle to http_server
httpd_handle_t server = NULL;
// Start the httpd server
if (httpd_start(&server, &config) == ESP_OK) {
// Register URI handlers
httpd_register_uri_handler(server, &uri_get);
httpd_register_uri_handler(server, &uri_post);
}
// If server failed to start, handle will be NULL
return server;
}
Return
• ESP_OK : Instance created successfully
• ESP_ERR_INVALID_ARG : Null argument(s)
• ESP_ERR_HTTPD_ALLOC_MEM : Failed to allocate memory for instance
• ESP_ERR_HTTPD_TASK : Failed to launch server task
Parameters
• [in] config: Configuration for new instance of the server
• [out] handle: Handle to newly created instance of the server. NULL on error
esp_err_t httpd_stop(httpd_handle_t handle)
Stops the web server.
Deallocates memory/resources used by an HTTP server instance and deletes it. Once deleted the handle can
no longer be used for accessing the instance.
Example usage:
// Function for stopping the webserver
void stop_webserver(httpd_handle_t server)
{
// Ensure handle is non NULL
if (server != NULL) {
// Stop the httpd server
httpd_stop(server);
}
}
Return
• ESP_OK : Server stopped successfully
• ESP_ERR_INVALID_ARG : Handle argument is Null
Parameters
• [in] handle: Handle to server returned by httpd_start
esp_err_t httpd_queue_work(httpd_handle_t handle, httpd_work_fn_t work, void *arg)
Queue execution of a function in HTTPD’s context.
This API queues a work function for asynchronous execution
Note Some protocols require that the web server generate some asynchronous data and send it to the persis-
tently opened connection. This facility is for use by such protocols.
Return
• ESP_OK : On successfully queueing the work
• ESP_FAIL : Failure in ctrl socket
• ESP_ERR_INVALID_ARG : Null arguments
Espressif Systems 584
Submit Document Feedback
Release v4.4

Table of Contents