firmware WIP - html css stuff :)

This commit is contained in:
Marcus 2024-04-15 01:53:54 +02:00
parent f3fcd32785
commit 83322b0e3c
1 changed files with 96 additions and 30 deletions

View File

@ -147,9 +147,17 @@ const char HTMLheader[] PROGMEM = R"EOF(
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CanGrow</title>
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="/style.css">
</head>
<body>
<ul class="nav">
<li><a href="/">Home</a></li>
<li><a href="/wifiConfig">WiFi Config</a></li>
<li><a href="#">Menu item 2</a></li>
<li><a href="#">Menu item 3</a></li>
<li><a href="#">Menu item 4</a></li>
</ul>
)EOF";
const char HTMLfooter[] PROGMEM = R"EOF(
@ -159,20 +167,51 @@ const char HTMLfooter[] PROGMEM = R"EOF(
const char HTMLstyleCSS[] PROGMEM = R"EOF(
body {
color: #cae0d0;
background-color: #1d211e;
font-family: helvetica;
background-color: #cccccc;
}
a:link, a:visited {
color: #33ff33;
color: #04AA6D;
}
a:hover {
color: #ffff00;
color: #64AA6D;
}
a:active {
color: #da7a0a;
color: #04AA6D;
}
/* from https://gist.github.com/iamhelenliu/5755179 - thank you! */
.nav {
background: #333;
margin:0;
padding: 0;
position: relative;
}
.nav li {
display: inline-block;
list-style: none;
margin:0;
}
.nav li a {
color: #ddd;
display: block;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:0.8em;
padding: 10px 20px;
text-decoration: none;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5);
}
.nav li a:hover {
background: #04AA6D;
color: #fff;
}
.nav li a:active {
color: #cae0d0;
}
)EOF";
@ -526,8 +565,6 @@ bool loadEEPROM() {
Serial.println(":: EEPROM loaded ::");
Serial.print("WIFIssid: ");
Serial.println(WIFIssid);
Serial.print("WIFIpassword: ");
Serial.println(WIFIpassword);
Serial.print("Use DHCP: ");
Serial.println(WIFIuseDHCP);
}
@ -591,7 +628,7 @@ void setup() {
pinMode(PINsoilmoisture, OUTPUT);
pinMode(PINled, OUTPUT);
pinMode(PINpump, OUTPUT);
pinMode(PIN_WIPE, INPUT);
// set all OUTPUT to low
digitalWrite(PINfan, LOW);
@ -644,11 +681,12 @@ void setup() {
}
delay(333);
}
// set back to HIGH because thats the default
digitalWrite(PIN_WIPE, HIGH);
//delay(2000);
pinMode(PIN_WIPE, INPUT);
// read status from PIN_WIPE to WIPE
// when PIN_WIPE is set to LOW, wipe EEPROM
if(digitalRead(PIN_WIPE) == LOW) {
// wipe EEPROM
@ -681,23 +719,8 @@ void setup() {
// use webhandler for unconfigured state
WebHandler_unconfigured();
}
/*
* Webserver handlers
* here are the generic webserver handlers like 404 not found
* wificonfig save, ...
*
* if you are looking for the single webpages handler, have a look to
*
* WebHandler_unconfigured() and WebHandler_configured()
*/
// generic handler
webserver.on("/wifiConfig/save", HTTP_POST, POSTwifiConfig);
webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// 404 handling
webserver.onNotFound(WEB404);
// general webHandler for wifiConfig, 404, ...
WebHandler_general();
// start webserver
webserver.begin();
@ -716,6 +739,32 @@ void loop() {
webserver.handleClient();
}
/*
* Web Handler
*/
void WebHandler_general() {
/*
* Webserver handlers
* here are the generic webserver handlers like 404 not found
* wifiConfig, ...
*
* if you are looking for the single webpages handler, have a look to
*
* WebHandler_unconfigured() and WebHandler_configured()
*/
// generic handler
// WiFi Stuff
webserver.on("/wifiConfig", HTTP_GET, WEBwifiConfig);
webserver.on("/wifiConfig/save", HTTP_POST, POSTwifiConfig);
webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// 404 handling
webserver.onNotFound(WEB404);
}
void WebHandler_unconfigured() {
/*
* WebHandler_unconfigured()
@ -753,10 +802,13 @@ void WEB404() {
}
void WEBrootUnconfigured() {
/*
* Config pages
*/
void WEBwifiConfig() {
byte ssidsAvail = WiFi.scanNetworks();
String body = FPSTR(HTMLheader);
body += "<h1>unconfigured!</h1>\n";
body += "<h1>WiFi config</h1>\n";
body += "<p>Select your wifi network from the SSID list.<br>To use DHCP leave IP, Subnet, Gateway and DNS fields blank!</p>";
body += "<form method='post' action='/wifiConfig/save'>\n";
@ -796,7 +848,16 @@ void WEBroot() {
webserver.send(200, "text/html", body);
}
void WEBrootUnconfigured() {
String body = FPSTR(HTMLheader);
body += "<h1>CanGrow</h1>";
body += "<p>CanGrow is actually unconfigured. <a href='./wifiConfig'>Configure WiFi</a></p>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
}
/*
*
@ -862,7 +923,12 @@ void POSTwifiConfig() {
Serial.print("configured: ");
Serial.println(configured);
webserver.send(200, "text/html", "wifiConfig saved, please restart");
String body = FPSTR(HTMLheader);
body += "<h1>WiFi Config</h1>";
body += "<p>WiFi settings successfully saved. Please restart the device.</p>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
}