ESP01 STM32 Nucleo statisch Webserver
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE
Diff: main.cpp
- Revision:
- 5:b4ae03006c7d
- Parent:
- 4:d19ae06fc0bb
- Child:
- 6:5353c5484d58
diff -r d19ae06fc0bb -r b4ae03006c7d main.cpp --- a/main.cpp Tue Jun 22 09:58:43 2021 +0000 +++ b/main.cpp Fri Jul 23 13:09:44 2021 +0000 @@ -27,11 +27,12 @@ PortOut diag(PortC,0xFF); lcd myLCD; ESP8266Webserver myWebserver; - +AnalogIn poti(PA_0); +DigitalIn taste(PA_1); string webpage; -string getRootPage2() +string getRootPage() { webpage="<!DOCTYPE html>\n"; @@ -39,7 +40,7 @@ webpage+="<script type=\"text/javascript\">"; webpage+="var x;"; webpage+="function z(){location.assign(\"http://"; - webpage+=myWebserver.gibIP();//"192.168.1.117"; + webpage+=myWebserver.gibIP(); webpage+="\");}"; webpage+="function sT(){x=setInterval(z,5000);}"; webpage+="function spT(){clearInterval(x);}"; @@ -54,14 +55,20 @@ webpage+="<h1>WIFI mit STM32 ESP01</h1>\n"; webpage+="<p>Aufrufe:"; webpage+=to_string(myWebserver.Aufrufe); + webpage+="</p>\n"; + webpage+="<p>Poti:"; + webpage+=to_string(poti); + webpage+="</p>\n"; + webpage+="<p>Taste PA_1:"; + webpage+=to_string(taste); webpage+="</p>\n"; webpage+="<form>\n"; webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n"; webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n"; - webpage+="<label for=\"alter\">ueber 18:</label>\n"; - webpage+="<input type=\"checkbox\" id=\"alter\" name=\"alter\">\n"; + webpage+="<label for=\"checkmich\">check mich:</label>\n"; + webpage+="<input type=\"checkbox\" id=\"checkmich\" name=\"checkmich\">\n"; webpage+="<button>finden</button>\n"; webpage+="</form>\n"; webpage+="<H2>LED On/Off </H2>\n"; @@ -74,56 +81,23 @@ } -//Alternativ mit char* statt string - -char* getRootPage() -{ - - static char webpage[1000]; - - strcpy(webpage,"<!DOCTYPE html>\r\n"); - strcat(webpage,"<html>\r\n"); - strcat(webpage,"<head>\r\n"); - strcat(webpage,"<title>STM32 HTTP</title>\r\n"); - strcat(webpage,"</head>\r\n"); - strcat(webpage,"<body>\r\n"); - strcat(webpage,"<h1>WIFI mit STM32 ESP01</h1>\r\n"); - strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); - - strcat(webpage,"<form>\r\n"); - strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n"); - strcat(webpage,"<input id=\"Suchbegriff\" name=\"Suchbegriff\">\r\n"); - strcat(webpage,"<label for=\"alter\">ueber 18:</label>\r\n"); - strcat(webpage,"<input type=\"checkbox\" id=\"alter\" name=\"alter\">\r\n"); - strcat(webpage,"<button>finden</button>\r\n"); - strcat(webpage,"</form>\r\n"); - - strcat(webpage,"<H2>LED On/Off </H2>\n"); - strcat(webpage,"<a href=\"ledAn\"><button>ON</button></a>\n"); - strcat(webpage,"<a href=\"ledaus\"><button>OFF</button></a>\n"); - strcat(webpage,"</body>\r\n"); - strcat(webpage,"</html>\r\n"); - - return webpage; - -} void testfunc() { diag=diag|0x80; - myWebserver.send(200,"text/html",getRootPage2()); + myWebserver.send(200,"text/html",getRootPage()); } void testfunc2() { diag=0x40; - myWebserver.send(200,"text/html",getRootPage2()); + myWebserver.send(200,"text/html",getRootPage()); } void testfunc3() { diag=0x20; - myWebserver.send(200,"text/html",getRootPage2()); + myWebserver.send(200,"text/html",getRootPage()); } void testfunc4() @@ -133,13 +107,14 @@ myLCD.cursorpos(0); myLCD.printf("%s",myWebserver.gibWert("Suchbegriff")); myLCD.cursorpos(0x40); - myLCD.printf("%s",myWebserver.gibWert("alter")); - myWebserver.send(200,"text/html",getRootPage2()); + myLCD.printf("%s",myWebserver.gibWert("checkmich")); + myWebserver.send(200,"text/html",getRootPage()); } int main() { - + taste.mode(PullDown); + myWebserver.on("Suchbegriff",&testfunc4); myWebserver.on("ledaus",&testfunc2); myWebserver.on("ledAn",&testfunc3);