diff --git a/examples/esp32/device-dashboard/Makefile b/examples/esp32/device-dashboard/Makefile index 3fc92995..ae089e2f 100644 --- a/examples/esp32/device-dashboard/Makefile +++ b/examples/esp32/device-dashboard/Makefile @@ -1,5 +1,5 @@ THISDIR = $(realpath $(CURDIR)) -ROOTDIR = $(realpath $(CURDIR)/../..) +ROOTDIR = $(realpath $(CURDIR)/../../..) all: example diff --git a/examples/esp32/device-dashboard/main/CMakeLists.txt b/examples/esp32/device-dashboard/main/CMakeLists.txt index ef191df4..e665b9e2 100644 --- a/examples/esp32/device-dashboard/main/CMakeLists.txt +++ b/examples/esp32/device-dashboard/main/CMakeLists.txt @@ -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) diff --git a/examples/esp32/device-dashboard/main/main.c b/examples/esp32/device-dashboard/main/main.c index 82250c6d..13fd6fa9 100644 --- a/examples/esp32/device-dashboard/main/main.c +++ b/examples/esp32/device-dashboard/main/main.c @@ -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 } diff --git a/examples/esp32/device-dashboard/main/mongoose.c b/examples/esp32/device-dashboard/main/mongoose.c index 5e522bbc..7a2752cb 120000 --- a/examples/esp32/device-dashboard/main/mongoose.c +++ b/examples/esp32/device-dashboard/main/mongoose.c @@ -1 +1 @@ -../../../mongoose.c \ No newline at end of file +../../../../mongoose.c \ No newline at end of file diff --git a/examples/esp32/device-dashboard/main/mongoose.h b/examples/esp32/device-dashboard/main/mongoose.h index ee4ac823..daff1633 120000 --- a/examples/esp32/device-dashboard/main/mongoose.h +++ b/examples/esp32/device-dashboard/main/mongoose.h @@ -1 +1 @@ -../../../mongoose.h \ No newline at end of file +../../../../mongoose.h \ No newline at end of file diff --git a/examples/esp32/device-dashboard/main/net.c b/examples/esp32/device-dashboard/main/net.c new file mode 120000 index 00000000..d0758f09 --- /dev/null +++ b/examples/esp32/device-dashboard/main/net.c @@ -0,0 +1 @@ +../../../device-dashboard/net.c \ No newline at end of file diff --git a/examples/esp32/device-dashboard/main/packed_fs.c b/examples/esp32/device-dashboard/main/packed_fs.c new file mode 120000 index 00000000..ebd127df --- /dev/null +++ b/examples/esp32/device-dashboard/main/packed_fs.c @@ -0,0 +1 @@ +../../../device-dashboard/packed_fs.c \ No newline at end of file diff --git a/examples/esp32/device-dashboard/main/wifi.c b/examples/esp32/device-dashboard/main/wifi.c index cc619da5..a913c308 100644 --- a/examples/esp32/device-dashboard/main/wifi.c +++ b/examples/esp32/device-dashboard/main/wifi.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); }