I have already tried to modify the WiFi examples for my porpuses.
The HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="20" name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
h2{margin-top: 60px;
margin-left: 60px;}
body {
font-family: Arial, Helvetica, sans-serif;
}
* {
box-sizing: border-box;
}
input[type=text], select, textarea {
width: 70%;
padding: 12px;
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
label {
padding: 24px 12px 12px 48px;
display: inline-block;
}
input[type=submit] {
background-color: #04AA6D;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
margin-top: 15px;
margin-right: 500px
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: white; /* #f2f2f2 */
padding: 20px;
margin-top: 75px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top:6px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
margin-top: 16px;
}
.navbar {
overflow: hidden;
background-color: white;
}
.navbar a {
float: left;
font-size: 16px;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.sidenav {
height: 70%;
width: 200px;
position: fixed;
z-index: 1;
top: 120px;
left: 100px;
background-color: white;
overflow-x: hidden;
padding-top: 20px;
}
.sidenav a {
padding: 6px 6px 36px 32px;
text-decoration: none;
font-size: 16px;
color: black;
display: block;
}
.dropdown {
float: left;
padding-left: 120px;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: black;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
color: blue;
}
.dropdown-content {
display: none;
position: absolute;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: white;
}
.dropdown:hover .dropdown-content {
display: block;
}
.sidenav a:hover {
color: blue;
}
.main {
margin-left: 200px; /* Same as the width of the sidenav */
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
table, th, td {
border:1px solid black;
margin-left: 55px;
margin-top: 35px;
}
</style>
</head>
<body style="background-color:white;">
<div class="w3-main" style="display: flex; justify-content: center; margin-top: 20px;">
<span class="w3-button w3-hide-large w3-xxlarge w3-hover-text-grey" onclick="w3_open()"></span>
<div class="w3-container">
<!---<nav class="navbar navbar-expand-xl navbar-light bg-light">--->
<!---<div class="w3-section w3-bottombar w3-padding-16" style="text-align: right;" >
<li class="nav-item dropdown">--->
<img src='https://wiki.amberg.deprag.de/allgemein/images/thumb/d/de/Logo-DEPRAG-machinesunlimited.svg/120px-Logo-DEPRAG-machinesunlimited.svg.png' style='margin-right: 20px; float: left;' id='deprag-logo' width= '100' height= '30'>
<div class="navbar">
<a href="index">Dashboard</a>
<a href="software">Software</a>
<a href="settings">Einstellungen</a>
<a href="#news">Systeminfo</a>
<a href="test">Service</a>
<div class="dropdown">
<button class="dropbtn"><i class="fa fa-fw fa-user"></i>Admin
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Mein Profil</a>
<a href="#">Abmelden</a>
</div>
</div>
</div>
<div class="sidenav">
<a href="sensordata">Sensordaten</a>
<a href="controlLED">Steuere LED</a>
</div>
<h2>Service<span style='font-size:30px;'>→</span>Sensordaten</h2>
<table style="width:80%">
<tr>
<th>IS</th>
<th>RS</th>
<th>GS</th>
<th>BS</th>
</tr>
<tr>
<td><span id="is1"></span></td>
<td><span id="r1"></span></td>
<td><span id="g1"></span></td>
<td><span id="b1"></span></td>
</tr>
<tr>
<td><span id="is2"></span></td>
<td><span id="r2"></span></td>
<td><span id="g2"></span></td>
<td><span id="b2"></span></td>
</tr>
<tr>
<td><span id="is3"></span></td>
<td><span id="r3"></span></td>
<td><span id="g3"></span></td>
<td><span id="b3"></span></td>
</tr>
<tr>
<td><span id="is4"></span></td>
<td><span id="r4"></span></td>
<td><span id="g4"></span></td>
<td><span id="b4"></span></td>
</tr>
</table>
<script>
setInterval(function() {
// Call a function repetatively with 2 Second interval
getData();
}, 2000); //2000mSeconds update rate
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("is1").innerHTML =
this.responseText;
}
};
xhttp.open("POST", "sensordata", true);
xhttp.send();
}
</script>
</body>
</html>
And this is how the handlefunction get triggered:
ethernetServer.on("/sensordata", HTTP_GET, handleRGBRead);
And the handlefunction:
void handleRGBRead(){
// Send the response to the client
String response;
File file = LittleFS.open("/sensordata.html", "r");
if (file) {
response += file.readString();
file.close();
tit1 = getToolInfo(0);
tit2 = getToolInfo(1);
tit3 = getToolInfo(2);
tit4 = getToolInfo(3);
// Inject sensor data into the HTML table
response.replace("<span id=\"is1\"></span>", String(tit1.state.bits.occupied));
response.replace("<span id=\"r1\"></span>", String(tit1.colorcode_red));
response.replace("<span id=\"g1\"></span>", String(tit1.colorcode_green));
response.replace("<span id=\"b1\"></span>", String(tit1.colorcode_blue));
response.replace("<span id=\"is2\"></span>", String(tit2.state.bits.occupied));
response.replace("<span id=\"r2\"></span>", String(tit2.colorcode_red));
response.replace("<span id=\"g2\"></span>", String(tit2.colorcode_green));
response.replace("<span id=\"b2\"></span>", String(tit2.colorcode_blue));
response.replace("<span id=\"is3\"></span>", String(tit3.state.bits.occupied));
response.replace("<span id=\"r3\"></span>", String(tit3.colorcode_red));
response.replace("<span id=\"g3\"></span>", String(tit3.colorcode_green));
response.replace("<span id=\"b3\"></span>", String(tit3.colorcode_blue));
response.replace("<span id=\"is4\"></span>", String(tit4.state.bits.occupied));
response.replace("<span id=\"r4\"></span>", String(tit4.colorcode_red));
response.replace("<span id=\"g4\"></span>", String(tit4.colorcode_green));
response.replace("<span id=\"b4\"></span>", String(tit4.colorcode_blue));
// Repeat this for other sensor values
Serial.println("Inside handleRGBRead()!!!");
// Send the modified HTML as the HTTP response
ethernetServer.send(200, "text/html", response);
} else {
ethernetServer.send(404, "text/plain", "File not found");
}
// response += (htmlclose); //Problem
//ethernetServer.send(200, "text/html", response);handlecontrolLED
}
It hasn't worked.