ESP01 STM32 Nucleo statisch Webserver

Dependencies:   LCD_i2c_GSOE ESP8266WebserverGSOE

Revision:
3:8dba70d37b7d
Parent:
2:c25aefe81534
Child:
4:d19ae06fc0bb
--- a/main.cpp	Fri Jun 18 15:33:38 2021 +0000
+++ b/main.cpp	Tue Jun 22 07:49:04 2021 +0000
@@ -19,34 +19,43 @@
 #include "LCD.h"
 //#include "string"
 
+#include <string>
 
-//DigitalOut CH_PD(PB_13);
-//DigitalOut RST(PB_12);
+
+
+
 PortOut diag(PortC,0xFF);
 lcd myLCD;
-
 ESP8266Webserver myWebserver;
 
 
+string webpage;
 
 string getRootPage2()
 {
 
-   string webpage;
-
-      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);
-      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);
-
-
-
       webpage="<!DOCTYPE html>\n";
+      //Javascript
+      webpage+="<script type=\"text/javascript\">";
+      webpage+="var x;";
+      webpage+="function z(){location.assign(\"http://";
+      webpage+=myWebserver.gibIP();//"192.168.1.117";
+      webpage+="\");}";
+      webpage+="function sT(){x=setInterval(z,1000);}";
+      webpage+="function spT(){clearInterval(x);}";
+      webpage+="onload=sT();";
+      webpage+="</script>\n";
+      //HTML
       webpage+="<html>\n";
       webpage+="<head>\n";
       webpage+="<title>STM32 HTTP</title>\n";
       webpage+="</head>\n";
       webpage+="<body>\n";
       webpage+="<h1>WIFI mit STM32 ESP01</h1>\n";
-      webpage+="<p>Webpage2</p>\n"; //WebseiteZeile1);
+      webpage+="<p>Aufrufe:";
+      webpage+=to_string(myWebserver.Aufrufe);
+      
+      webpage+="</p>\n"; 
       
       webpage+="<form>\n";
       webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n";
@@ -60,21 +69,18 @@
       webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n";
       webpage+="</body>\n";
       webpage+="</html>\n";
-      
+  
       return webpage;
 
 }
 
-char* getRootPage()                                        //This function contains data to be sent to local server
+//Alternativ mit char* statt string
+
+char* getRootPage()                                       
 {
 
     static char webpage[1000];
 
-      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);
-      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);
-
-
-
       strcpy(webpage,"<!DOCTYPE html>\r\n");
       strcat(webpage,"<html>\r\n");
       strcat(webpage,"<head>\r\n");
@@ -82,7 +88,7 @@
       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"); //WebseiteZeile1);
+      strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); 
       
       strcat(webpage,"<form>\r\n");
       strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n");
@@ -91,6 +97,10 @@
       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");
       
@@ -108,21 +118,11 @@
 void testfunc2()
 {
     diag=0x40;
-        /*myLCD.clear();
-    myLCD.cursorpos(0);
-    myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str());
-    myLCD.cursorpos(0x40);
-    myLCD.printf("%s",myWebserver.gibWert("alter"));*/
     myWebserver.send(200,"text/html",getRootPage2());
 }
 void testfunc3()
 {
     diag=0x20;
-        /*myLCD.clear();
-    myLCD.cursorpos(0);
-    myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str());
-    myLCD.cursorpos(0x40);
-    myLCD.printf("%s",myWebserver.gibWert("alter"));*/
     myWebserver.send(200,"text/html",getRootPage2());
 }
 
@@ -131,19 +131,14 @@
     diag=diag|0x10;
     myLCD.clear();
     myLCD.cursorpos(0);
-    myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str());
+    myLCD.printf("%s",myWebserver.gibWert("Suchbegriff"));
     myLCD.cursorpos(0x40);
     myLCD.printf("%s",myWebserver.gibWert("alter"));
     myWebserver.send(200,"text/html",getRootPage2());
 }
 
 int main()
-{/*
-    RST=0;
- //   CH_PD=1;
-    HAL_Delay(1000);
-    RST=1;*/
-    //myWebserver.debugOn(false);
+{
 
     myWebserver.on("Suchbegriff",&testfunc4);
     myWebserver.on("ledaus",&testfunc2);