ChaosDMX
Open-Source DMX-Interface
Loading...
Searching...
No Matches
web_server.c File Reference
#include "web_server.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "logger.h"
#include "storage.h"
Include dependency graph for web_server.c:

Go to the source code of this file.

Macros

#define LOG_TAG   "WEBSRV"
 Tag used for web server logging.
#define WEBSERVER_DEFAULT_PORT   80
 Default port for the web server.
#define WEBSERVER_DEFAULT_MAX_HANDLERS   32
 Default port for the web server.
#define WEBSERVER_DEFAULT_STACK_SIZE   (8 * 1024)
 Default maximum number of URI handlers.
#define WEBSERVER_DEFAULT_TASK_PRIORITY   5
 Default stack size for the web server task.

Functions

static const char * get_mime_type (const char *filename)
 Get MIME type based on file extension.
static esp_err_t static_file_handler (httpd_req_t *req)
 HTTP handler for static files from LittleFS.
static esp_err_t health_check_handler (httpd_req_t *req)
 HTTP handler for API health check (GET /api/health).
static void webserver_task (void *arg)
 FreeRTOS task function for the HTTP server. Allows non-blocking server operation and future extensibility.
httpd_handle_t webserver_start (const webserver_config_t *config)
 Start the web server with the given configuration.
void webserver_stop (httpd_handle_t server)
 Stop the web server and clean up resources.
esp_err_t webserver_register_handler (httpd_handle_t server, const httpd_uri_t *uri_handler)
 Register a URI handler with the web server.

Variables

static httpd_handle_t s_server_handle = NULL
 Default task priority for the web server task.
static TaskHandle_t s_server_task_handle = NULL
 Handle for the FreeRTOS web server task.

Macro Definition Documentation

◆ LOG_TAG

#define LOG_TAG   "WEBSRV"

Tag used for web server logging.

Definition at line 1 of file web_server.c.

◆ WEBSERVER_DEFAULT_MAX_HANDLERS

#define WEBSERVER_DEFAULT_MAX_HANDLERS   32

Default port for the web server.

Definition at line 29 of file web_server.c.

Referenced by webserver_start().

◆ WEBSERVER_DEFAULT_PORT

#define WEBSERVER_DEFAULT_PORT   80

Default port for the web server.

Definition at line 25 of file web_server.c.

Referenced by webserver_start().

◆ WEBSERVER_DEFAULT_STACK_SIZE

#define WEBSERVER_DEFAULT_STACK_SIZE   (8 * 1024)

Default maximum number of URI handlers.

Definition at line 33 of file web_server.c.

Referenced by webserver_start().

◆ WEBSERVER_DEFAULT_TASK_PRIORITY

#define WEBSERVER_DEFAULT_TASK_PRIORITY   5

Default stack size for the web server task.

Definition at line 37 of file web_server.c.

Referenced by webserver_start().

Function Documentation

◆ get_mime_type()

const char * get_mime_type ( const char * filename)
static

Get MIME type based on file extension.

Definition at line 55 of file web_server.c.

Referenced by static_file_handler().

Here is the caller graph for this function:

◆ health_check_handler()

esp_err_t health_check_handler ( httpd_req_t * req)
static

HTTP handler for API health check (GET /api/health).

Definition at line 134 of file web_server.c.

Referenced by webserver_start().

Here is the caller graph for this function:

◆ static_file_handler()

esp_err_t static_file_handler ( httpd_req_t * req)
static

HTTP handler for static files from LittleFS.

Definition at line 93 of file web_server.c.

References get_mime_type(), LOGW, and storage_get_mount_point().

Referenced by webserver_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ webserver_register_handler()

esp_err_t webserver_register_handler ( httpd_handle_t server,
const httpd_uri_t * uri_handler )

Register a URI handler with the web server.

Register a custom URI handler.

Parameters
serverHandle to the HTTP server instance
uri_handlerPointer to the URI handler struct
Returns
ESP_OK on success, ESP_ERR_INVALID_ARG or other error codes on failure

Definition at line 278 of file web_server.c.

References LOGE, and LOGI.

◆ webserver_start()

httpd_handle_t webserver_start ( const webserver_config_t * config)

Start the web server with the given configuration.

Initialize and start the HTTP web server.

Initializes storage, configures the HTTP server, registers default handlers, and starts the FreeRTOS task for async operation.

Parameters
configPointer to webserver configuration struct (optional)
Returns
Handle to the running HTTP server, or NULL on failure

Definition at line 166 of file web_server.c.

References health_check_handler(), LOGE, LOGI, LOGW, s_server_handle, s_server_task_handle, static_file_handler(), storage_init(), WEBSERVER_DEFAULT_MAX_HANDLERS, WEBSERVER_DEFAULT_PORT, WEBSERVER_DEFAULT_STACK_SIZE, WEBSERVER_DEFAULT_TASK_PRIORITY, and webserver_task().

Referenced by app_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ webserver_stop()

void webserver_stop ( httpd_handle_t server)

Stop the web server and clean up resources.

Stop the web server and cleanup resources.

Stops the HTTP server and deletes the FreeRTOS task.

Parameters
serverHandle to the HTTP server instance

Definition at line 253 of file web_server.c.

References LOGI, s_server_handle, and s_server_task_handle.

◆ webserver_task()

void webserver_task ( void * arg)
static

FreeRTOS task function for the HTTP server. Allows non-blocking server operation and future extensibility.

Definition at line 144 of file web_server.c.

References LOGI, and s_server_handle.

Referenced by webserver_start().

Here is the caller graph for this function:

Variable Documentation

◆ s_server_handle

httpd_handle_t s_server_handle = NULL
static

Default task priority for the web server task.

Handle for the HTTP server instance.

Definition at line 45 of file web_server.c.

Referenced by webserver_start(), webserver_stop(), and webserver_task().

◆ s_server_task_handle

TaskHandle_t s_server_task_handle = NULL
static

Handle for the FreeRTOS web server task.

Definition at line 50 of file web_server.c.

Referenced by webserver_start(), and webserver_stop().