From 7e1b9a6ce63b5f1c87d8fa873574dd0a72cbdfb0 Mon Sep 17 00:00:00 2001 From: andreas Date: Fri, 15 Oct 2021 21:09:36 +0200 Subject: [PATCH] improved web page, some initial status --- platformio.ini | 3 +++ src/main.cpp | 20 +++++++++++++++++--- src/index_html.h => web/index.html | 29 ++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 6 deletions(-) rename src/index_html.h => web/index.html (50%) diff --git a/platformio.ini b/platformio.ini index 80d8549..a9fa875 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,9 +16,12 @@ lib_deps = ttlappalainen/NMEA2000_esp32 @ ^1.0.3 ttlappalainen/NMEA0183 @ ^1.7.1 bblanchon/ArduinoJson@^6.18.5 +board_build.embed_txtfiles= + web/index.html [env:m5stack-atom] board = m5stack-atom lib_deps = ${env.lib_deps} build_flags= -D BOARD_M5ATOM +upload_port=/dev/esp32 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8b2e66c..5559228 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,6 @@ #include "N2kDataToNMEA0183.h" #include "List.h" -#include "index_html.h" #include "BoatData.h" @@ -67,6 +66,9 @@ IPAddress CL_subnet(255, 255, 255, 0); int wifiType = 0; // 0= Client 1= AP +//counter +int numCan=0; + const uint16_t ServerPort = 2222; // Define the port, where server sends data. Use this e.g. on OpenCPN. Use 39150 for Navionis AIS // UPD broadcast for Navionics, OpenCPN, etc. @@ -149,9 +151,12 @@ void debug_log(char* str) { #endif } +//embedded files +extern const char indexFile[] asm("_binary_web_index_html_start"); + void web_index() // Wenn "http:///" aufgerufen wurde { - webserver.send(200, "text/html", indexHTML); //dann Index Webseite senden + webserver.send(200, "text/html", indexFile); //dann Index Webseite senden } void js_reset() // Wenn "http:///gauge.min.js" aufgerufen wurde @@ -161,6 +166,14 @@ void js_reset() // Wenn "http:///gauge.min.js" aufgerufen wurde } +void js_status(){ + DynamicJsonDocument status(50); + status["numcan"]=numCan; + String buf; + serializeJson(status,buf); + webserver.send(200,F("application/json"),buf); +} + void handleNotFound() { webserver.send(404, "text/plain", "File Not Found\n\n"); @@ -229,6 +242,7 @@ void setup() { // Start Web Server webserver.on("/", web_index); webserver.on("/api/reset", js_reset); + webserver.on("/api/status", js_status); webserver.onNotFound(handleNotFound); webserver.begin(); @@ -297,7 +311,7 @@ void SendBufToClients(const char *buf) { //NMEA 2000 message handler void HandleNMEA2000Msg(const tN2kMsg &N2kMsg) { - + numCan++; if ( !SendSeaSmart ) return; char buf[MAX_NMEA2000_MESSAGE_SEASMART_SIZE]; diff --git a/src/index_html.h b/web/index.html similarity index 50% rename from src/index_html.h rename to web/index.html index ad15ab7..a33a039 100644 --- a/src/index_html.h +++ b/web/index.html @@ -1,5 +1,3 @@ - -const char indexHTML[] PROGMEM = R"=====( @@ -9,7 +7,21 @@ const char indexHTML[] PROGMEM = R"=====(

NMEA 2000 Gateway

+
+ # CAN messages + --- +
-)=====" ;