mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-02 06:22:52 +07:00
Unbreak esp32 device dashboard build
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
THISDIR = $(realpath $(CURDIR))
|
||||
ROOTDIR = $(realpath $(CURDIR)/../..)
|
||||
ROOTDIR = $(realpath $(CURDIR)/../../..)
|
||||
|
||||
all: example
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
"wifi.c"
|
||||
"net.c"
|
||||
"packed_fs.c"
|
||||
"mongoose.c")
|
||||
component_compile_options(-DMG_ENABLE_LINES)
|
||||
component_compile_options(-DMG_ENABLE_PACKED_FS)
|
||||
|
||||
@@ -2,27 +2,15 @@
|
||||
// All rights reserved
|
||||
|
||||
#include "esp_spiffs.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
//#include "freertos/FreeRTOS.h"
|
||||
#include "mongoose.h"
|
||||
|
||||
#define WIFI_SSID "VMDF554B9" // SET THIS!
|
||||
#define WIFI_PASS "Mp7wjmamPafa" // SET THIS!
|
||||
#define FS_ROOT "/spiffs"
|
||||
const char *s_listening_url = "http://0.0.0.0:80";
|
||||
void device_dashboard_fn(struct mg_connection *, int, void *, void *);
|
||||
|
||||
// Event handler for an server (accepted) connection. Implemented endpoints:
|
||||
// /api/stats - return JSON object with ESP32 stats (free RAM)
|
||||
// any other - serve files from the filesystem
|
||||
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = ev_data;
|
||||
if (mg_http_match_uri(hm, "/api/stats")) {
|
||||
mg_http_reply(c, 200, "", "{\"ram\": %lu}\n", xPortGetFreeHeapSize());
|
||||
} else {
|
||||
struct mg_http_serve_opts opts = {.root_dir = FS_ROOT};
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
#define WIFI_SSID "YOUR_WIFI_NETWORK_NAME" // SET THIS!
|
||||
#define WIFI_PASS "YOUR_WIFI_PASSWORD" // SET THIS!
|
||||
#define FS_ROOT "/spiffs"
|
||||
|
||||
void app_main(void) {
|
||||
// Mount filesystem
|
||||
@@ -39,9 +27,9 @@ void app_main(void) {
|
||||
|
||||
// Connected to WiFi, now start HTTP server
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("4");
|
||||
mg_log_set("3");
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:80", cb, &mgr); // Listening server
|
||||
MG_INFO(("Starting Mongoose web server v%s", MG_VERSION));
|
||||
MG_INFO(("Mongoose v%s on %s", MG_VERSION, s_listening_url));
|
||||
mg_http_listen(&mgr, s_listening_url, device_dashboard_fn, &mgr);
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
../../../mongoose.c
|
||||
../../../../mongoose.c
|
||||
@@ -1 +1 @@
|
||||
../../../mongoose.h
|
||||
../../../../mongoose.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../device-dashboard/net.c
|
||||
@@ -0,0 +1 @@
|
||||
../../../device-dashboard/packed_fs.c
|
||||
@@ -42,7 +42,7 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
MG_ERROR(("connect to the AP fail"));
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
|
||||
MG_INFO(("got ip:" IPSTR, IP2STR(&event->ip_info.ip)));
|
||||
MG_INFO(("IP ADDRESS:" IPSTR, IP2STR(&event->ip_info.ip)));
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user