From 262838bb42f209af738d9f28674515364025c5e4 Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Sun, 13 Mar 2022 00:01:02 +0100 Subject: [PATCH] Added test api URL, configured static files caching --- ESP32/data/www | 1 + ESP32/vehicle-monitor.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 120000 ESP32/data/www diff --git a/ESP32/data/www b/ESP32/data/www new file mode 120000 index 0000000..f564555 --- /dev/null +++ b/ESP32/data/www @@ -0,0 +1 @@ +../../WebApp/www \ No newline at end of file diff --git a/ESP32/vehicle-monitor.cpp b/ESP32/vehicle-monitor.cpp index 799d27e..bd88526 100644 --- a/ESP32/vehicle-monitor.cpp +++ b/ESP32/vehicle-monitor.cpp @@ -30,7 +30,19 @@ void setup() Serial.print("Wifi connected, ip="); Serial.println(WiFi.localIP()); - server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html"); + server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request){ + int batteryVoltage = random(30000, 42000); + char json[128]; + sprintf(json, "{\"v\":%d}", batteryVoltage); + request->send(200, "text/json", json); + }); + + // Special case to send index.html without caching + server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/www/index.html", "text/html"); }); + server.serveStatic("/index.html", SPIFFS, "/www/index.html"); + + // Other static files are cached (index.html knows whether to ignore caching or not for each file) + server.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=5184000"); server.begin(); Serial.println("HTTP server started");