From 83322b0e3c2666f6fa634d26a333f384281c5b93 Mon Sep 17 00:00:00 2001 From: Marcus Date: Mon, 15 Apr 2024 01:53:54 +0200 Subject: [PATCH] firmware WIP - html css stuff :) --- Arduino/CanGrow/CanGrow.ino | 126 +++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 30 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 367cc7d..9a63cac 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -147,9 +147,17 @@ const char HTMLheader[] PROGMEM = R"EOF( CanGrow - + + + )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 += "

unconfigured!

\n"; body += "

WiFi config

\n"; body += "

Select your wifi network from the SSID list.
To use DHCP leave IP, Subnet, Gateway and DNS fields blank!

"; body += "
\n"; @@ -796,7 +848,16 @@ void WEBroot() { webserver.send(200, "text/html", body); } + +void WEBrootUnconfigured() { + String body = FPSTR(HTMLheader); + body += "

CanGrow

"; + body += "

CanGrow is actually unconfigured. Configure WiFi

"; + 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 += "

WiFi Config

"; + body += "

WiFi settings successfully saved. Please restart the device.

"; + body += FPSTR(HTMLfooter); + + webserver.send(200, "text/html", body); }