chore(format): initial formatting

This commit is contained in:
HendrikRauh 2026-03-05 23:05:35 +01:00
parent fa08fcfe65
commit 008c79852b
21 changed files with 1021 additions and 1082 deletions

View file

@ -1,8 +1,7 @@
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -4,23 +4,22 @@
#include "esp_err.h" #include "esp_err.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
/** /**
* @brief Initialize and mount LittleFS filesystem * @brief Initialize and mount LittleFS filesystem
* *
* @return ESP_OK on success, error code otherwise * @return ESP_OK on success, error code otherwise
*/ */
esp_err_t storage_init(void); esp_err_t storage_init(void);
/** /**
* @brief Get the mount point for the LittleFS filesystem * @brief Get the mount point for the LittleFS filesystem
* *
* @return Pointer to the mount point string (e.g., "/data") * @return Pointer to the mount point string (e.g., "/data")
*/ */
const char *storage_get_mount_point(void); const char *storage_get_mount_point(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -7,8 +7,7 @@
static const char *TAG = "STORAGE"; static const char *TAG = "STORAGE";
static const char *LITTLEFS_MOUNT_POINT = "/data"; static const char *LITTLEFS_MOUNT_POINT = "/data";
esp_err_t storage_init(void) esp_err_t storage_init(void) {
{
esp_vfs_littlefs_conf_t conf = { esp_vfs_littlefs_conf_t conf = {
.base_path = LITTLEFS_MOUNT_POINT, .base_path = LITTLEFS_MOUNT_POINT,
.partition_label = "storage", .partition_label = "storage",
@ -18,18 +17,12 @@ esp_err_t storage_init(void)
esp_err_t ret = esp_vfs_littlefs_register(&conf); esp_err_t ret = esp_vfs_littlefs_register(&conf);
if (ret != ESP_OK) if (ret != ESP_OK) {
{ if (ret == ESP_FAIL) {
if (ret == ESP_FAIL)
{
ESP_LOGE(TAG, "Failed to mount LittleFS or format filesystem"); ESP_LOGE(TAG, "Failed to mount LittleFS or format filesystem");
} } else if (ret == ESP_ERR_INVALID_STATE) {
else if (ret == ESP_ERR_INVALID_STATE)
{
ESP_LOGE(TAG, "ESP_ERR_INVALID_STATE"); ESP_LOGE(TAG, "ESP_ERR_INVALID_STATE");
} } else {
else
{
ESP_LOGE(TAG, "Failed to initialize LittleFS: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to initialize LittleFS: %s", esp_err_to_name(ret));
} }
return ret; return ret;
@ -37,20 +30,14 @@ esp_err_t storage_init(void)
size_t total = 0, used = 0; size_t total = 0, used = 0;
ret = esp_littlefs_info(conf.partition_label, &total, &used); ret = esp_littlefs_info(conf.partition_label, &total, &used);
if (ret == ESP_OK) if (ret == ESP_OK) {
{
ESP_LOGI(TAG, "LittleFS mounted at %s. Total: %d bytes, Used: %d bytes", ESP_LOGI(TAG, "LittleFS mounted at %s. Total: %d bytes, Used: %d bytes",
LITTLEFS_MOUNT_POINT, total, used); LITTLEFS_MOUNT_POINT, total, used);
} } else {
else
{
ESP_LOGE(TAG, "Failed to get LittleFS information"); ESP_LOGE(TAG, "Failed to get LittleFS information");
} }
return ESP_OK; return ESP_OK;
} }
const char *storage_get_mount_point(void) const char *storage_get_mount_point(void) { return LITTLEFS_MOUNT_POINT; }
{
return LITTLEFS_MOUNT_POINT;
}

View file

@ -1,6 +1,7 @@
/** /**
* @file web_server.h * @file web_server.h
* @brief Simple HTTP web server component for ESP32 with async FreeRTOS support. * @brief Simple HTTP web server component for ESP32 with async FreeRTOS
* support.
*/ */
#pragma once #pragma once
@ -8,41 +9,40 @@
#include "esp_http_server.h" #include "esp_http_server.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
/** /**
* @brief Web server configuration structure. * @brief Web server configuration structure.
*/ */
typedef struct typedef struct {
{
uint16_t port; ///< HTTP server port (default: 80) uint16_t port; ///< HTTP server port (default: 80)
size_t max_uri_handlers; ///< Maximum number of URI handlers size_t max_uri_handlers; ///< Maximum number of URI handlers
size_t stack_size; ///< FreeRTOS task stack size size_t stack_size; ///< FreeRTOS task stack size
UBaseType_t task_priority; ///< FreeRTOS task priority UBaseType_t task_priority; ///< FreeRTOS task priority
} webserver_config_t; } webserver_config_t;
/** /**
* @brief Initialize and start the HTTP web server. * @brief Initialize and start the HTTP web server.
* *
* This function creates a FreeRTOS task that manages the HTTP server. * This function creates a FreeRTOS task that manages the HTTP server.
* It serves static files from the data/ folder and supports dynamic handler registration. * It serves static files from the data/ folder and supports dynamic handler
* registration.
* *
* @param config Configuration structure. If NULL, default values are used. * @param config Configuration structure. If NULL, default values are used.
* @return HTTP server handle on success, NULL on failure. * @return HTTP server handle on success, NULL on failure.
*/ */
httpd_handle_t webserver_start(const webserver_config_t *config); httpd_handle_t webserver_start(const webserver_config_t *config);
/** /**
* @brief Stop the web server and cleanup resources. * @brief Stop the web server and cleanup resources.
* *
* @param server HTTP server handle returned by webserver_start(). * @param server HTTP server handle returned by webserver_start().
* Safe to pass NULL. * Safe to pass NULL.
*/ */
void webserver_stop(httpd_handle_t server); void webserver_stop(httpd_handle_t server);
/** /**
* @brief Register a custom URI handler. * @brief Register a custom URI handler.
* *
* This allows dynamic registration of API endpoints and other custom handlers. * This allows dynamic registration of API endpoints and other custom handlers.
@ -51,7 +51,8 @@ extern "C"
* @param uri_handler Pointer to httpd_uri_t structure. * @param uri_handler Pointer to httpd_uri_t structure.
* @return ESP_OK on success, error code otherwise. * @return ESP_OK on success, error code otherwise.
*/ */
esp_err_t webserver_register_handler(httpd_handle_t server, const httpd_uri_t *uri_handler); esp_err_t webserver_register_handler(httpd_handle_t server,
const httpd_uri_t *uri_handler);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -3,12 +3,12 @@
#include "esp_err.h" #include "esp_err.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel, uint8_t max_connections); esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
void wifi_stop_ap(void); uint8_t max_connections);
void wifi_stop_ap(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -25,8 +25,7 @@ static TaskHandle_t s_server_task_handle = NULL;
/** /**
* @brief Get MIME type based on file extension * @brief Get MIME type based on file extension
*/ */
static const char *get_mime_type(const char *filename) static const char *get_mime_type(const char *filename) {
{
const char *dot = strrchr(filename, '.'); const char *dot = strrchr(filename, '.');
if (!dot) if (!dot)
return "application/octet-stream"; return "application/octet-stream";
@ -64,21 +63,20 @@ static const char *get_mime_type(const char *filename)
/** /**
* @brief HTTP handler for static files from LittleFS * @brief HTTP handler for static files from LittleFS
*/ */
static esp_err_t static_file_handler(httpd_req_t *req) static esp_err_t static_file_handler(httpd_req_t *req) {
{
// Build the file path // Build the file path
char filepath[1024]; char filepath[1024];
snprintf(filepath, sizeof(filepath), "%s%s", storage_get_mount_point(), req->uri); snprintf(filepath, sizeof(filepath), "%s%s", storage_get_mount_point(),
req->uri);
// Handle root path // Handle root path
if (strcmp(req->uri, "/") == 0) if (strcmp(req->uri, "/") == 0) {
{ snprintf(filepath, sizeof(filepath), "%s/index.html",
snprintf(filepath, sizeof(filepath), "%s/index.html", storage_get_mount_point()); storage_get_mount_point());
} }
FILE *f = fopen(filepath, "r"); FILE *f = fopen(filepath, "r");
if (!f) if (!f) {
{
ESP_LOGW(TAG, "File not found: %s", filepath); ESP_LOGW(TAG, "File not found: %s", filepath);
httpd_resp_send_404(req); httpd_resp_send_404(req);
return ESP_OK; return ESP_OK;
@ -91,10 +89,8 @@ static esp_err_t static_file_handler(httpd_req_t *req)
// Send file in chunks // Send file in chunks
char buf[1024]; char buf[1024];
size_t read_len; size_t read_len;
while ((read_len = fread(buf, 1, sizeof(buf), f)) > 0) while ((read_len = fread(buf, 1, sizeof(buf), f)) > 0) {
{ if (httpd_resp_send_chunk(req, buf, read_len) != ESP_OK) {
if (httpd_resp_send_chunk(req, buf, read_len) != ESP_OK)
{
ESP_LOGW(TAG, "Failed to send data chunk for %s", filepath); ESP_LOGW(TAG, "Failed to send data chunk for %s", filepath);
break; break;
} }
@ -108,8 +104,7 @@ static esp_err_t static_file_handler(httpd_req_t *req)
/** /**
* @brief HTTP handler for API health check (GET /api/health) * @brief HTTP handler for API health check (GET /api/health)
*/ */
static esp_err_t health_check_handler(httpd_req_t *req) static esp_err_t health_check_handler(httpd_req_t *req) {
{
httpd_resp_set_type(req, "application/json"); httpd_resp_set_type(req, "application/json");
httpd_resp_sendstr(req, "{\"status\":\"ok\"}"); httpd_resp_sendstr(req, "{\"status\":\"ok\"}");
return ESP_OK; return ESP_OK;
@ -119,14 +114,12 @@ static esp_err_t health_check_handler(httpd_req_t *req)
* @brief FreeRTOS task function for the HTTP server. * @brief FreeRTOS task function for the HTTP server.
* Allows non-blocking server operation and future extensibility. * Allows non-blocking server operation and future extensibility.
*/ */
static void webserver_task(void *arg) static void webserver_task(void *arg) {
{
(void)arg; // Unused parameter (void)arg; // Unused parameter
ESP_LOGI(TAG, "Web server task started"); ESP_LOGI(TAG, "Web server task started");
// Keep task alive - the server runs in the background // Keep task alive - the server runs in the background
while (s_server_handle != NULL) while (s_server_handle != NULL) {
{
vTaskDelay(pdMS_TO_TICKS(10000)); // 10 second check interval vTaskDelay(pdMS_TO_TICKS(10000)); // 10 second check interval
} }
@ -134,18 +127,15 @@ static void webserver_task(void *arg)
vTaskDelete(NULL); vTaskDelete(NULL);
} }
httpd_handle_t webserver_start(const webserver_config_t *config) httpd_handle_t webserver_start(const webserver_config_t *config) {
{ if (s_server_handle != NULL) {
if (s_server_handle != NULL)
{
ESP_LOGW(TAG, "Web server already running"); ESP_LOGW(TAG, "Web server already running");
return s_server_handle; return s_server_handle;
} }
// Initialize LittleFS // Initialize LittleFS
esp_err_t ret = storage_init(); esp_err_t ret = storage_init();
if (ret != ESP_OK) if (ret != ESP_OK) {
{
ESP_LOGE(TAG, "Failed to initialize storage"); ESP_LOGE(TAG, "Failed to initialize storage");
return NULL; return NULL;
} }
@ -156,8 +146,7 @@ httpd_handle_t webserver_start(const webserver_config_t *config)
size_t stack_size = WEBSERVER_DEFAULT_STACK_SIZE; size_t stack_size = WEBSERVER_DEFAULT_STACK_SIZE;
UBaseType_t task_priority = WEBSERVER_DEFAULT_TASK_PRIORITY; UBaseType_t task_priority = WEBSERVER_DEFAULT_TASK_PRIORITY;
if (config) if (config) {
{
port = config->port; port = config->port;
max_handlers = config->max_uri_handlers; max_handlers = config->max_uri_handlers;
stack_size = config->stack_size; stack_size = config->stack_size;
@ -173,8 +162,7 @@ httpd_handle_t webserver_start(const webserver_config_t *config)
// Start HTTP server // Start HTTP server
ret = httpd_start(&s_server_handle, &http_config); ret = httpd_start(&s_server_handle, &http_config);
if (ret != ESP_OK) if (ret != ESP_OK) {
{
ESP_LOGE(TAG, "Failed to start HTTP server: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to start HTTP server: %s", esp_err_to_name(ret));
s_server_handle = NULL; s_server_handle = NULL;
return NULL; return NULL;
@ -202,17 +190,13 @@ httpd_handle_t webserver_start(const webserver_config_t *config)
httpd_register_uri_handler(s_server_handle, &file_uri); httpd_register_uri_handler(s_server_handle, &file_uri);
// Create FreeRTOS task for the server // Create FreeRTOS task for the server
// This allows other tasks to continue running and makes the server async-ready // This allows other tasks to continue running and makes the server
BaseType_t task_ret = xTaskCreate( // async-ready
webserver_task, BaseType_t task_ret = xTaskCreate(webserver_task, "webserver", stack_size,
"webserver", (void *)s_server_handle, task_priority,
stack_size,
(void *)s_server_handle,
task_priority,
&s_server_task_handle); &s_server_task_handle);
if (task_ret != pdPASS) if (task_ret != pdPASS) {
{
ESP_LOGE(TAG, "Failed to create web server task"); ESP_LOGE(TAG, "Failed to create web server task");
httpd_stop(s_server_handle); httpd_stop(s_server_handle);
s_server_handle = NULL; s_server_handle = NULL;
@ -223,10 +207,8 @@ httpd_handle_t webserver_start(const webserver_config_t *config)
return s_server_handle; return s_server_handle;
} }
void webserver_stop(httpd_handle_t server) void webserver_stop(httpd_handle_t server) {
{ if (server == NULL) {
if (server == NULL)
{
return; return;
} }
@ -234,8 +216,7 @@ void webserver_stop(httpd_handle_t server)
s_server_handle = NULL; s_server_handle = NULL;
// Wait for task to finish // Wait for task to finish
if (s_server_task_handle != NULL) if (s_server_task_handle != NULL) {
{
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
s_server_task_handle = NULL; s_server_task_handle = NULL;
} }
@ -243,21 +224,19 @@ void webserver_stop(httpd_handle_t server)
ESP_LOGI(TAG, "Web server stopped"); ESP_LOGI(TAG, "Web server stopped");
} }
esp_err_t webserver_register_handler(httpd_handle_t server, const httpd_uri_t *uri_handler) esp_err_t webserver_register_handler(httpd_handle_t server,
{ const httpd_uri_t *uri_handler) {
if (server == NULL || uri_handler == NULL) if (server == NULL || uri_handler == NULL) {
{
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
esp_err_t ret = httpd_register_uri_handler(server, uri_handler); esp_err_t ret = httpd_register_uri_handler(server, uri_handler);
if (ret == ESP_OK) if (ret == ESP_OK) {
{ ESP_LOGI(TAG, "Registered handler: %s [%d]", uri_handler->uri,
ESP_LOGI(TAG, "Registered handler: %s [%d]", uri_handler->uri, uri_handler->method); uri_handler->method);
} } else {
else ESP_LOGE(TAG, "Failed to register handler %s: %s", uri_handler->uri,
{ esp_err_to_name(ret));
ESP_LOGE(TAG, "Failed to register handler %s: %s", uri_handler->uri, esp_err_to_name(ret));
} }
return ret; return ret;

View file

@ -11,32 +11,28 @@
static const char *TAG = "WIFI"; static const char *TAG = "WIFI";
static bool s_wifi_started = false; static bool s_wifi_started = false;
esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel, uint8_t max_connections) esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
{ uint8_t max_connections) {
if (s_wifi_started) if (s_wifi_started) {
{
return ESP_OK; return ESP_OK;
} }
if (!ssid || strlen(ssid) == 0 || strlen(ssid) > 32) if (!ssid || strlen(ssid) == 0 || strlen(ssid) > 32) {
{
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
const bool has_password = password && strlen(password) > 0; const bool has_password = password && strlen(password) > 0;
if (has_password && strlen(password) < 8) if (has_password && strlen(password) < 8) {
{
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
esp_err_t err = nvs_flash_init(); esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) if (err == ESP_ERR_NVS_NO_FREE_PAGES ||
{ err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase()); ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init(); err = nvs_flash_init();
} }
if (err != ESP_OK) if (err != ESP_OK) {
{
return err; return err;
} }
@ -48,11 +44,13 @@ esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = { wifi_config_t wifi_config = {
.ap = { .ap =
{
.channel = channel, .channel = channel,
.max_connection = max_connections, .max_connection = max_connections,
.authmode = has_password ? WIFI_AUTH_WPA2_PSK : WIFI_AUTH_OPEN, .authmode = has_password ? WIFI_AUTH_WPA2_PSK : WIFI_AUTH_OPEN,
.pmf_cfg = { .pmf_cfg =
{
.required = false, .required = false,
}, },
}, },
@ -61,9 +59,9 @@ esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
strlcpy((char *)wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid)); strlcpy((char *)wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
wifi_config.ap.ssid_len = strlen(ssid); wifi_config.ap.ssid_len = strlen(ssid);
if (has_password) if (has_password) {
{ strlcpy((char *)wifi_config.ap.password, password,
strlcpy((char *)wifi_config.ap.password, password, sizeof(wifi_config.ap.password)); sizeof(wifi_config.ap.password));
} }
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
@ -75,10 +73,8 @@ esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
return ESP_OK; return ESP_OK;
} }
void wifi_stop_ap(void) void wifi_stop_ap(void) {
{ if (!s_wifi_started) {
if (!s_wifi_started)
{
return; return;
} }

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
@ -60,11 +60,7 @@
<div class="card"> <div class="card">
<span>Signalstärke</span> <span>Signalstärke</span>
<span class="centered-vertical"> <span class="centered-vertical">
<img <img class="connection-icon small" src="" alt="" />
class="connection-icon small"
src=""
alt=""
/>
<span><span class="rssi"></span> dBm</span> <span><span class="rssi"></span> dBm</span>
</span> </span>
</div> </div>
@ -95,9 +91,7 @@
<div class="card"> <div class="card">
<span>PSRAM</span> <span>PSRAM</span>
<span <span><span class="psram-percentage"></span> %</span>
><span class="psram-percentage"></span> %</span
>
<span <span
><span class="psram-used"></span> / ><span class="psram-used"></span> /
<span class="psram-total"></span <span class="psram-total"></span
@ -208,15 +202,8 @@
title="Netzwerk" title="Netzwerk"
required required
></select> ></select>
<button <button type="button" id="refresh-networks" class="icon-button">
type="button" <img src="/icons/refresh.svg" alt="Neu laden" />
id="refresh-networks"
class="icon-button"
>
<img
src="/icons/refresh.svg"
alt="Neu laden"
/>
</button> </button>
</label> </label>
</div> </div>
@ -309,9 +296,7 @@
required required
> >
<option value="0">Nichts</option> <option value="0">Nichts</option>
<option value="1"> <option value="1">Konfiguration zurücksetzen</option>
Konfiguration zurücksetzen
</option>
<option value="2">Neustart</option> <option value="2">Neustart</option>
</select> </select>
</label> </label>

View file

@ -4,18 +4,18 @@ const dynamicInputs = form.querySelectorAll("[data-field][data-values]");
document.addEventListener("change", updateVisibility); document.addEventListener("change", updateVisibility);
function updateVisibility() { function updateVisibility() {
dynamicInputs.forEach((element) => { dynamicInputs.forEach(element => {
const input = form.querySelector(`#${element.dataset.field}`); const input = form.querySelector(`#${element.dataset.field}`);
if (element.dataset.values.split("|").includes(input.value)) { if (element.dataset.values.split("|").includes(input.value)) {
element.classList.remove("hidden"); element.classList.remove("hidden");
element element
.querySelectorAll("input, select, button, textarea") .querySelectorAll("input, select, button, textarea")
.forEach((childInput) => (childInput.disabled = false)); .forEach(childInput => (childInput.disabled = false));
} else { } else {
element.classList.add("hidden"); element.classList.add("hidden");
element element
.querySelectorAll("input, select, button, textarea") .querySelectorAll("input, select, button, textarea")
.forEach((childInput) => (childInput.disabled = true)); .forEach(childInput => (childInput.disabled = true));
} }
}); });
} }

View file

@ -1,4 +1,4 @@
document.querySelector("form.config").addEventListener("input", (event) => { document.querySelector("form.config").addEventListener("input", event => {
if (event.target.classList.contains("range")) { if (event.target.classList.contains("range")) {
updateValue(event.target); updateValue(event.target);
} }
@ -9,6 +9,6 @@ function updateValue(slider) {
slider.nextElementSibling.innerText = `${percentage}%`; slider.nextElementSibling.innerText = `${percentage}%`;
} }
document.querySelectorAll("input[type='range'].range").forEach((element) => { document.querySelectorAll("input[type='range'].range").forEach(element => {
updateValue(element); updateValue(element);
}); });

View file

@ -2,7 +2,7 @@ import { updateConfig } from "/submit.js";
const form = document.querySelector("form.config"); const form = document.querySelector("form.config");
form.addEventListener("reset", async (event) => { form.addEventListener("reset", async event => {
event.preventDefault(); event.preventDefault();
const ok = confirm( const ok = confirm(

View file

@ -18,7 +18,7 @@ function setStatus(status) {
setValue("rssi", status.connection.signalStrength); setValue("rssi", status.connection.signalStrength);
const icon = selectConnectionIcon(status.connection.signalStrength); const icon = selectConnectionIcon(status.connection.signalStrength);
document.querySelectorAll(".connection-icon").forEach((img) => { document.querySelectorAll(".connection-icon").forEach(img => {
img.src = `/icons/${icon}`; img.src = `/icons/${icon}`;
}); });
@ -29,10 +29,7 @@ function setStatus(status) {
const usedHeap = status.heap.total - status.heap.free; const usedHeap = status.heap.total - status.heap.free;
setValue("heap-used", formatBytes(usedHeap)); setValue("heap-used", formatBytes(usedHeap));
setValue("heap-total", formatBytes(status.heap.total)); setValue("heap-total", formatBytes(status.heap.total));
setValue( setValue("heap-percentage", Math.round((usedHeap / status.heap.total) * 100));
"heap-percentage",
Math.round((usedHeap / status.heap.total) * 100)
);
const usedPsram = status.psram.total - status.psram.free; const usedPsram = status.psram.total - status.psram.free;
setValue("psram-used", formatBytes(usedPsram)); setValue("psram-used", formatBytes(usedPsram));
@ -48,7 +45,7 @@ function setStatus(status) {
} }
function setValue(className, value) { function setValue(className, value) {
document.querySelectorAll("." + className).forEach((element) => { document.querySelectorAll("." + className).forEach(element => {
element.innerText = value; element.innerText = value;
}); });
} }

View file

@ -26,7 +26,7 @@ function parseValue(input) {
return input.value; return input.value;
} }
form.addEventListener("submit", (event) => { form.addEventListener("submit", event => {
event.preventDefault(); event.preventDefault();
const inputFields = document.querySelectorAll( const inputFields = document.querySelectorAll(
"form :is(input, select, textarea):not(:disabled)" "form :is(input, select, textarea):not(:disabled)"

View file

@ -12,18 +12,18 @@ export function initWebSocket() {
console.info("WebSocket connection opened"); console.info("WebSocket connection opened");
}; };
ws.onclose = (event) => { ws.onclose = event => {
console.info("WebSocket connection closed, reason:", event.reason); console.info("WebSocket connection closed, reason:", event.reason);
ws = null; ws = null;
}; };
ws.onerror = (event) => { ws.onerror = event => {
console.warn("WebSocket encountered error, closing socket.", event); console.warn("WebSocket encountered error, closing socket.", event);
ws.close(); ws.close();
ws = null; ws = null;
}; };
ws.onmessage = (event) => { ws.onmessage = event => {
const message = JSON.parse(event.data); const message = JSON.parse(event.data);
console.log("received websocket data", message); console.log("received websocket data", message);
if (message.type in callbacks) { if (message.type in callbacks) {

View file

@ -9,21 +9,18 @@
static const char *TAG = "MAIN"; static const char *TAG = "MAIN";
void app_main(void) void app_main(void) {
{
ESP_LOGI(TAG, "DMX Interface starting..."); ESP_LOGI(TAG, "DMX Interface starting...");
esp_err_t wifi_err = wifi_start_ap("DMX", "mbgmbgmbg", 1, 4); esp_err_t wifi_err = wifi_start_ap("DMX", "mbgmbgmbg", 1, 4);
if (wifi_err != ESP_OK) if (wifi_err != ESP_OK) {
{
ESP_LOGE(TAG, "Failed to start WiFi AP: %s", esp_err_to_name(wifi_err)); ESP_LOGE(TAG, "Failed to start WiFi AP: %s", esp_err_to_name(wifi_err));
return; return;
} }
// Start HTTP web server // Start HTTP web server
httpd_handle_t server = webserver_start(NULL); httpd_handle_t server = webserver_start(NULL);
if (server == NULL) if (server == NULL) {
{
ESP_LOGE(TAG, "Failed to start web server!"); ESP_LOGE(TAG, "Failed to start web server!");
return; return;
} }
@ -32,8 +29,7 @@ void app_main(void)
ESP_LOGI(TAG, "Open http://192.168.4.1 in your browser"); ESP_LOGI(TAG, "Open http://192.168.4.1 in your browser");
// Keep the app running // Keep the app running
while (1) while (1) {
{
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
} }
} }

View file

@ -1,7 +1,7 @@
## IDF Component Manager Manifest File ## IDF Component Manager Manifest File
dependencies: dependencies:
idf: idf:
version: '>=4.1.0' version: ">=4.1.0"
joltwallet/littlefs: ==1.20.2 joltwallet/littlefs: ==1.20.2
someweisguy/esp_dmx: someweisguy/esp_dmx:
git: https://github.com/davispolito/esp_dmx.git git: https://github.com/davispolito/esp_dmx.git