GSOE Webserver ESP01 DHT11

Dependencies:   LCD_i2c_GSOE ESP8266WebserverGSOE

Revision:
3:9fac8ba757be
Parent:
2:85f2573de3e4
Child:
6:410b258da1a4
--- a/main.cpp	Mon Jul 26 12:27:29 2021 +0000
+++ b/main.cpp	Tue Jul 27 09:37:12 2021 +0000
@@ -1,17 +1,17 @@
 
 #include "mbed.h"
 #include "LCD.h"
-
+#include "ESP8266Webserver.h"
 
 
 #define DHTLIB_OK                0
 #define DHTLIB_ERROR_CHECKSUM   -1
 #define DHTLIB_ERROR_TIMEOUT    -2
-
+ESP8266Webserver myWebserver;
 Timer tmr;
 lcd mylcd;
 
-DigitalInOut data_pin(PB_15);  //Anschluss S
+DigitalInOut data_pin(PC_15);  //Anschluss S
 //Anschluss - an GND
 //mittlerer Anschluss an 3,3V
 
@@ -97,15 +97,52 @@
 //########################################
 // End of DHT11 Library
 //########################################
+float poti=0.5;
+string getRootPage()
+{
+      string webpage;
+      webpage="<!DOCTYPE html>";
+      //Javascript
+      webpage+="<script type=\"text/javascript\">";
+      webpage+="var x;";
+      webpage+="function z(){location.assign(\"http://";
+      webpage+=myWebserver.gibIP();
+      webpage+="\");}";
+      webpage+="function sT(){x=setInterval(z,1000);}";
+      webpage+="function spT(){clearInterval(x);}";
+      webpage+="onload=sT();";
+      webpage+="</script>\n";
+      //HTML
+      webpage+="<html>";
+      webpage+="<head>";
+      webpage+="<title>STM32 HTTP</title>";
+      webpage+="</head>";
+      webpage+="<body>";
+      webpage+="<h1>WIFI mit STM32 ESP01</h1>\n";
+      webpage+="<p>Tmp:"+to_string(temperature)+" C</p>\n"; 
+      webpage+="<p>Hum:"+to_string(humidity)+"%</p>\n"; 
+      webpage+="</body>";
+      webpage+="</html>";
+      return webpage;
+}
+
+
+void testfunc()
+{
+    myWebserver.send(200,"text/html",getRootPage());
+}
+
 
 int main(void){
-    
+    myWebserver.on("/",&testfunc);
+    myWebserver.begin();    
     mylcd.clear();
     mylcd.cursorpos(0);
     
     mylcd.printf("Nucleo - DHT11");
     
     for(;;){
+       myWebserver.handleClient();
        int fehler=dht_read();