2020-12-14 20:58:27 +08:00
|
|
|
// Copyright (c) 2020 Cesanta Software Limited
|
|
|
|
// All rights reserved
|
|
|
|
|
2021-02-03 10:13:05 +08:00
|
|
|
#include "esp_spiffs.h"
|
2022-06-08 20:54:20 +08:00
|
|
|
//#include "freertos/FreeRTOS.h"
|
2020-12-14 20:58:27 +08:00
|
|
|
#include "mongoose.h"
|
|
|
|
|
2022-06-08 20:54:20 +08:00
|
|
|
const char *s_listening_url = "http://0.0.0.0:80";
|
|
|
|
void device_dashboard_fn(struct mg_connection *, int, void *, void *);
|
2020-12-14 20:58:27 +08:00
|
|
|
|
2022-06-08 20:54:20 +08:00
|
|
|
#define WIFI_SSID "YOUR_WIFI_NETWORK_NAME" // SET THIS!
|
|
|
|
#define WIFI_PASS "YOUR_WIFI_PASSWORD" // SET THIS!
|
|
|
|
#define FS_ROOT "/spiffs"
|
2020-12-25 00:52:12 +08:00
|
|
|
|
2020-12-14 20:58:27 +08:00
|
|
|
void app_main(void) {
|
2021-02-03 10:13:05 +08:00
|
|
|
// Mount filesystem
|
|
|
|
esp_vfs_spiffs_conf_t conf = {
|
|
|
|
.base_path = FS_ROOT, .max_files = 20, .format_if_mount_failed = true};
|
|
|
|
int res = esp_vfs_spiffs_register(&conf);
|
2022-02-13 02:17:25 +08:00
|
|
|
MG_INFO(("FS %s, %d", conf.base_path, res));
|
2022-01-19 01:11:02 +08:00
|
|
|
mg_file_printf(&mg_fs_posix, FS_ROOT "/hello.txt", "%s", "hello from ESP");
|
2021-02-03 10:13:05 +08:00
|
|
|
|
2020-12-14 20:58:27 +08:00
|
|
|
// Setup wifi. This function is implemented in wifi.c
|
|
|
|
// It blocks until connected to the configured WiFi network
|
|
|
|
void wifi_init(const char *ssid, const char *pass);
|
|
|
|
wifi_init(WIFI_SSID, WIFI_PASS);
|
|
|
|
|
2021-02-03 10:13:05 +08:00
|
|
|
// Connected to WiFi, now start HTTP server
|
|
|
|
struct mg_mgr mgr;
|
2022-08-01 18:19:32 +08:00
|
|
|
mg_log_set(MG_LL_DEBUG); // Set log level
|
2021-02-03 10:13:05 +08:00
|
|
|
mg_mgr_init(&mgr);
|
2022-06-08 20:54:20 +08:00
|
|
|
MG_INFO(("Mongoose v%s on %s", MG_VERSION, s_listening_url));
|
|
|
|
mg_http_listen(&mgr, s_listening_url, device_dashboard_fn, &mgr);
|
2021-02-03 10:13:05 +08:00
|
|
|
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
|
2020-12-14 20:58:27 +08:00
|
|
|
}
|