mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-15 06:53:07 +01:00
improved web page, some initial status
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
|
||||
const char indexHTML[] PROGMEM = R"=====(
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||
<title>NMEA 2000 Gateway</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
function reset(){
|
||||
fetch('/api/reset');
|
||||
}
|
||||
</script>
|
||||
<style type="text/css">
|
||||
#wrap
|
||||
{
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
max-width: 900px;
|
||||
margin:0 auto;
|
||||
background:#dcd;
|
||||
border-radius: 10px;
|
||||
padding:10px; /*innen*/
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="main">
|
||||
<h1>NMEA 2000 Gateway </h1>
|
||||
<button id="reset" onclick="reset();">Reset</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
)=====" ;
|
||||
|
||||
|
||||
20
src/main.cpp
20
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://<ip address>/" 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://<ip address>/gauge.min.js" aufgerufen wurde
|
||||
@@ -161,6 +166,14 @@ void js_reset() // Wenn "http://<ip address>/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];
|
||||
|
||||
Reference in New Issue
Block a user