Webserver ESP01 ESP8266 V1_0
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* ATCmdParser usage example 00002 * Copyright (c) 2016 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "ESP8266Webserver.h" 00019 #include "LCD.h" 00020 //#include "string" 00021 00022 00023 //DigitalOut CH_PD(PB_13); 00024 //DigitalOut RST(PB_12); 00025 PortOut diag(PortC,0xFF); 00026 lcd myLCD; 00027 00028 ESP8266Webserver myWebserver; 00029 00030 00031 00032 string getRootPage2() 00033 { 00034 00035 string webpage; 00036 00037 //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); 00038 //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); 00039 00040 00041 00042 webpage="<!DOCTYPE html>\n"; 00043 webpage+="<html>\n"; 00044 webpage+="<head>\n"; 00045 webpage+="<title>STM32 HTTP</title>\n"; 00046 webpage+="</head>\n"; 00047 webpage+="<body>\n"; 00048 webpage+="<h1>WIFI mit STM32 ESP01</h1>\n"; 00049 webpage+="<p>Webpage2</p>\n"; //WebseiteZeile1); 00050 00051 webpage+="<form>\n"; 00052 webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n"; 00053 webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n"; 00054 webpage+="<label for=\"alter\">ueber 18:</label>\n"; 00055 webpage+="<input type=\"checkbox\" id=\"alter\" name=\"alter\">\n"; 00056 webpage+="<button>finden</button>\n"; 00057 webpage+="</form>\n"; 00058 webpage+="<H2>LED On/Off </H2>\n"; 00059 webpage+="<a href=\"ledAn\"><button>ON</button></a>\n"; 00060 webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n"; 00061 webpage+="</body>\n"; 00062 webpage+="</html>\n"; 00063 00064 return webpage; 00065 00066 } 00067 00068 char* getRootPage() //This function contains data to be sent to local server 00069 { 00070 00071 static char webpage[1000]; 00072 00073 //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); 00074 //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); 00075 00076 00077 00078 strcpy(webpage,"<!DOCTYPE html>\r\n"); 00079 strcat(webpage,"<html>\r\n"); 00080 strcat(webpage,"<head>\r\n"); 00081 strcat(webpage,"<title>STM32 HTTP</title>\r\n"); 00082 strcat(webpage,"</head>\r\n"); 00083 strcat(webpage,"<body>\r\n"); 00084 strcat(webpage,"<h1>WIFI mit STM32 ESP01</h1>\r\n"); 00085 strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); //WebseiteZeile1); 00086 00087 strcat(webpage,"<form>\r\n"); 00088 strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n"); 00089 strcat(webpage,"<input id=\"Suchbegriff\" name=\"Suchbegriff\">\r\n"); 00090 strcat(webpage,"<label for=\"alter\">ueber 18:</label>\r\n"); 00091 strcat(webpage,"<input type=\"checkbox\" id=\"alter\" name=\"alter\">\r\n"); 00092 strcat(webpage,"<button>finden</button>\r\n"); 00093 strcat(webpage,"</form>\r\n"); 00094 strcat(webpage,"</body>\r\n"); 00095 strcat(webpage,"</html>\r\n"); 00096 00097 return webpage; 00098 00099 } 00100 00101 void testfunc() 00102 { 00103 diag=diag|0x80; 00104 00105 myWebserver.send(200,"text/html",getRootPage2()); 00106 } 00107 00108 void testfunc2() 00109 { 00110 diag=0x40; 00111 /*myLCD.clear(); 00112 myLCD.cursorpos(0); 00113 myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str()); 00114 myLCD.cursorpos(0x40); 00115 myLCD.printf("%s",myWebserver.gibWert("alter"));*/ 00116 myWebserver.send(200,"text/html",getRootPage2()); 00117 } 00118 void testfunc3() 00119 { 00120 diag=0x20; 00121 /*myLCD.clear(); 00122 myLCD.cursorpos(0); 00123 myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str()); 00124 myLCD.cursorpos(0x40); 00125 myLCD.printf("%s",myWebserver.gibWert("alter"));*/ 00126 myWebserver.send(200,"text/html",getRootPage2()); 00127 } 00128 00129 void testfunc4() 00130 { 00131 diag=diag|0x10; 00132 myLCD.clear(); 00133 myLCD.cursorpos(0); 00134 myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str()); 00135 myLCD.cursorpos(0x40); 00136 myLCD.printf("%s",myWebserver.gibWert("alter")); 00137 myWebserver.send(200,"text/html",getRootPage2()); 00138 } 00139 00140 int main() 00141 {/* 00142 RST=0; 00143 // CH_PD=1; 00144 HAL_Delay(1000); 00145 RST=1;*/ 00146 //myWebserver.debugOn(false); 00147 00148 myWebserver.on("Suchbegriff",&testfunc4); 00149 myWebserver.on("ledaus",&testfunc2); 00150 myWebserver.on("ledAn",&testfunc3); 00151 myWebserver.on("/",&testfunc); 00152 00153 myWebserver.begin(); 00154 00155 myLCD.clear(); 00156 myLCD.cursorpos(0); 00157 myLCD.printf("%s",myWebserver.gibIP()); 00158 00159 00160 00161 while(1) 00162 { 00163 myWebserver.handleClient(); 00164 } 00165 00166 }
Generated on Thu Jul 21 2022 02:08:32 by
1.7.2