ESP01 STM32 Nucleo statisch Webserver
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE
main.cpp@0:829bac853c96, 2021-06-07 (annotated)
- Committer:
- jack1930
- Date:
- Mon Jun 07 18:33:29 2021 +0000
- Revision:
- 0:829bac853c96
- Child:
- 1:1f13f5f1fdbc
Webserver ESP01 ESP8266 V1_0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jack1930 | 0:829bac853c96 | 1 | /* ATCmdParser usage example |
jack1930 | 0:829bac853c96 | 2 | * Copyright (c) 2016 ARM Limited |
jack1930 | 0:829bac853c96 | 3 | * |
jack1930 | 0:829bac853c96 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jack1930 | 0:829bac853c96 | 5 | * you may not use this file except in compliance with the License. |
jack1930 | 0:829bac853c96 | 6 | * You may obtain a copy of the License at |
jack1930 | 0:829bac853c96 | 7 | * |
jack1930 | 0:829bac853c96 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jack1930 | 0:829bac853c96 | 9 | * |
jack1930 | 0:829bac853c96 | 10 | * Unless required by applicable law or agreed to in writing, software |
jack1930 | 0:829bac853c96 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jack1930 | 0:829bac853c96 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jack1930 | 0:829bac853c96 | 13 | * See the License for the specific language governing permissions and |
jack1930 | 0:829bac853c96 | 14 | * limitations under the License. |
jack1930 | 0:829bac853c96 | 15 | */ |
jack1930 | 0:829bac853c96 | 16 | |
jack1930 | 0:829bac853c96 | 17 | #include "mbed.h" |
jack1930 | 0:829bac853c96 | 18 | #include "ESP8266Webserver.h" |
jack1930 | 0:829bac853c96 | 19 | #include "LCD.h" |
jack1930 | 0:829bac853c96 | 20 | //#include "string" |
jack1930 | 0:829bac853c96 | 21 | |
jack1930 | 0:829bac853c96 | 22 | |
jack1930 | 0:829bac853c96 | 23 | //DigitalOut CH_PD(PB_13); |
jack1930 | 0:829bac853c96 | 24 | //DigitalOut RST(PB_12); |
jack1930 | 0:829bac853c96 | 25 | PortOut diag(PortC,0xFF); |
jack1930 | 0:829bac853c96 | 26 | lcd myLCD; |
jack1930 | 0:829bac853c96 | 27 | |
jack1930 | 0:829bac853c96 | 28 | ESP8266Webserver myWebserver(80); |
jack1930 | 0:829bac853c96 | 29 | |
jack1930 | 0:829bac853c96 | 30 | |
jack1930 | 0:829bac853c96 | 31 | |
jack1930 | 0:829bac853c96 | 32 | string getRootPage2() |
jack1930 | 0:829bac853c96 | 33 | { |
jack1930 | 0:829bac853c96 | 34 | |
jack1930 | 0:829bac853c96 | 35 | string webpage; |
jack1930 | 0:829bac853c96 | 36 | |
jack1930 | 0:829bac853c96 | 37 | //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); |
jack1930 | 0:829bac853c96 | 38 | //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); |
jack1930 | 0:829bac853c96 | 39 | |
jack1930 | 0:829bac853c96 | 40 | |
jack1930 | 0:829bac853c96 | 41 | |
jack1930 | 0:829bac853c96 | 42 | webpage="<!DOCTYPE html>\n"; |
jack1930 | 0:829bac853c96 | 43 | webpage+="<html>\n"; |
jack1930 | 0:829bac853c96 | 44 | webpage+="<head>\n"; |
jack1930 | 0:829bac853c96 | 45 | webpage+="<title>STM32 HTTP</title>\n"; |
jack1930 | 0:829bac853c96 | 46 | webpage+="</head>\n"; |
jack1930 | 0:829bac853c96 | 47 | webpage+="<body>\n"; |
jack1930 | 0:829bac853c96 | 48 | webpage+="<h1>WIFI mit STM32 ESP01</h1>\n"; |
jack1930 | 0:829bac853c96 | 49 | webpage+="<p>Webpage2</p>\n"; //WebseiteZeile1); |
jack1930 | 0:829bac853c96 | 50 | |
jack1930 | 0:829bac853c96 | 51 | webpage+="<form>\n"; |
jack1930 | 0:829bac853c96 | 52 | webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n"; |
jack1930 | 0:829bac853c96 | 53 | webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n"; |
jack1930 | 0:829bac853c96 | 54 | webpage+="<label for=\"alter\">ueber 18:</label>\n"; |
jack1930 | 0:829bac853c96 | 55 | webpage+="<input type=\"checkbox\" id=\"alter\" name=\"alter\">\n"; |
jack1930 | 0:829bac853c96 | 56 | webpage+="<button>finden</button>\n"; |
jack1930 | 0:829bac853c96 | 57 | webpage+="</form>\n"; |
jack1930 | 0:829bac853c96 | 58 | webpage+="<H2>LED On/Off </H2>\n"; |
jack1930 | 0:829bac853c96 | 59 | webpage+="<a href=\"ledAn\"><button>ON</button></a>\n"; |
jack1930 | 0:829bac853c96 | 60 | webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n"; |
jack1930 | 0:829bac853c96 | 61 | webpage+="</body>\n"; |
jack1930 | 0:829bac853c96 | 62 | webpage+="</html>\n"; |
jack1930 | 0:829bac853c96 | 63 | |
jack1930 | 0:829bac853c96 | 64 | return webpage; |
jack1930 | 0:829bac853c96 | 65 | |
jack1930 | 0:829bac853c96 | 66 | } |
jack1930 | 0:829bac853c96 | 67 | |
jack1930 | 0:829bac853c96 | 68 | char* getRootPage() //This function contains data to be sent to local server |
jack1930 | 0:829bac853c96 | 69 | { |
jack1930 | 0:829bac853c96 | 70 | |
jack1930 | 0:829bac853c96 | 71 | static char webpage[1000]; |
jack1930 | 0:829bac853c96 | 72 | |
jack1930 | 0:829bac853c96 | 73 | //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); |
jack1930 | 0:829bac853c96 | 74 | //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); |
jack1930 | 0:829bac853c96 | 75 | |
jack1930 | 0:829bac853c96 | 76 | |
jack1930 | 0:829bac853c96 | 77 | |
jack1930 | 0:829bac853c96 | 78 | strcpy(webpage,"<!DOCTYPE html>\r\n"); |
jack1930 | 0:829bac853c96 | 79 | strcat(webpage,"<html>\r\n"); |
jack1930 | 0:829bac853c96 | 80 | strcat(webpage,"<head>\r\n"); |
jack1930 | 0:829bac853c96 | 81 | strcat(webpage,"<title>STM32 HTTP</title>\r\n"); |
jack1930 | 0:829bac853c96 | 82 | strcat(webpage,"</head>\r\n"); |
jack1930 | 0:829bac853c96 | 83 | strcat(webpage,"<body>\r\n"); |
jack1930 | 0:829bac853c96 | 84 | strcat(webpage,"<h1>WIFI mit STM32 ESP01</h1>\r\n"); |
jack1930 | 0:829bac853c96 | 85 | strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); //WebseiteZeile1); |
jack1930 | 0:829bac853c96 | 86 | |
jack1930 | 0:829bac853c96 | 87 | strcat(webpage,"<form>\r\n"); |
jack1930 | 0:829bac853c96 | 88 | strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n"); |
jack1930 | 0:829bac853c96 | 89 | strcat(webpage,"<input id=\"Suchbegriff\" name=\"Suchbegriff\">\r\n"); |
jack1930 | 0:829bac853c96 | 90 | strcat(webpage,"<label for=\"alter\">ueber 18:</label>\r\n"); |
jack1930 | 0:829bac853c96 | 91 | strcat(webpage,"<input type=\"checkbox\" id=\"alter\" name=\"alter\">\r\n"); |
jack1930 | 0:829bac853c96 | 92 | strcat(webpage,"<button>finden</button>\r\n"); |
jack1930 | 0:829bac853c96 | 93 | strcat(webpage,"</form>\r\n"); |
jack1930 | 0:829bac853c96 | 94 | strcat(webpage,"</body>\r\n"); |
jack1930 | 0:829bac853c96 | 95 | strcat(webpage,"</html>\r\n"); |
jack1930 | 0:829bac853c96 | 96 | |
jack1930 | 0:829bac853c96 | 97 | return webpage; |
jack1930 | 0:829bac853c96 | 98 | |
jack1930 | 0:829bac853c96 | 99 | } |
jack1930 | 0:829bac853c96 | 100 | |
jack1930 | 0:829bac853c96 | 101 | void testfunc() |
jack1930 | 0:829bac853c96 | 102 | { |
jack1930 | 0:829bac853c96 | 103 | diag=diag|0x80; |
jack1930 | 0:829bac853c96 | 104 | |
jack1930 | 0:829bac853c96 | 105 | myWebserver.send(200,"text/html",getRootPage2()); |
jack1930 | 0:829bac853c96 | 106 | } |
jack1930 | 0:829bac853c96 | 107 | |
jack1930 | 0:829bac853c96 | 108 | void testfunc2() |
jack1930 | 0:829bac853c96 | 109 | { |
jack1930 | 0:829bac853c96 | 110 | diag=0x40; |
jack1930 | 0:829bac853c96 | 111 | /*myLCD.clear(); |
jack1930 | 0:829bac853c96 | 112 | myLCD.cursorpos(0); |
jack1930 | 0:829bac853c96 | 113 | myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str()); |
jack1930 | 0:829bac853c96 | 114 | myLCD.cursorpos(0x40); |
jack1930 | 0:829bac853c96 | 115 | myLCD.printf("%s",myWebserver.gibWert("alter"));*/ |
jack1930 | 0:829bac853c96 | 116 | myWebserver.send(200,"text/html",getRootPage2()); |
jack1930 | 0:829bac853c96 | 117 | } |
jack1930 | 0:829bac853c96 | 118 | void testfunc3() |
jack1930 | 0:829bac853c96 | 119 | { |
jack1930 | 0:829bac853c96 | 120 | diag=0x20; |
jack1930 | 0:829bac853c96 | 121 | /*myLCD.clear(); |
jack1930 | 0:829bac853c96 | 122 | myLCD.cursorpos(0); |
jack1930 | 0:829bac853c96 | 123 | myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str()); |
jack1930 | 0:829bac853c96 | 124 | myLCD.cursorpos(0x40); |
jack1930 | 0:829bac853c96 | 125 | myLCD.printf("%s",myWebserver.gibWert("alter"));*/ |
jack1930 | 0:829bac853c96 | 126 | myWebserver.send(200,"text/html",getRootPage2()); |
jack1930 | 0:829bac853c96 | 127 | } |
jack1930 | 0:829bac853c96 | 128 | |
jack1930 | 0:829bac853c96 | 129 | void testfunc4() |
jack1930 | 0:829bac853c96 | 130 | { |
jack1930 | 0:829bac853c96 | 131 | diag=diag|0x10; |
jack1930 | 0:829bac853c96 | 132 | myLCD.clear(); |
jack1930 | 0:829bac853c96 | 133 | myLCD.cursorpos(0); |
jack1930 | 0:829bac853c96 | 134 | myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str()); |
jack1930 | 0:829bac853c96 | 135 | myLCD.cursorpos(0x40); |
jack1930 | 0:829bac853c96 | 136 | myLCD.printf("%s",myWebserver.gibWert("alter")); |
jack1930 | 0:829bac853c96 | 137 | myWebserver.send(200,"text/html",getRootPage2()); |
jack1930 | 0:829bac853c96 | 138 | } |
jack1930 | 0:829bac853c96 | 139 | |
jack1930 | 0:829bac853c96 | 140 | int main() |
jack1930 | 0:829bac853c96 | 141 | {/* |
jack1930 | 0:829bac853c96 | 142 | RST=0; |
jack1930 | 0:829bac853c96 | 143 | // CH_PD=1; |
jack1930 | 0:829bac853c96 | 144 | HAL_Delay(1000); |
jack1930 | 0:829bac853c96 | 145 | RST=1;*/ |
jack1930 | 0:829bac853c96 | 146 | //myWebserver.debugOn(false); |
jack1930 | 0:829bac853c96 | 147 | |
jack1930 | 0:829bac853c96 | 148 | myWebserver.on("Suchbegriff",&testfunc4); |
jack1930 | 0:829bac853c96 | 149 | myWebserver.on("ledaus",&testfunc2); |
jack1930 | 0:829bac853c96 | 150 | myWebserver.on("ledAn",&testfunc3); |
jack1930 | 0:829bac853c96 | 151 | myWebserver.on("/",&testfunc); |
jack1930 | 0:829bac853c96 | 152 | |
jack1930 | 0:829bac853c96 | 153 | myWebserver.begin(); |
jack1930 | 0:829bac853c96 | 154 | |
jack1930 | 0:829bac853c96 | 155 | |
jack1930 | 0:829bac853c96 | 156 | |
jack1930 | 0:829bac853c96 | 157 | |
jack1930 | 0:829bac853c96 | 158 | while(1) |
jack1930 | 0:829bac853c96 | 159 | { |
jack1930 | 0:829bac853c96 | 160 | myWebserver.handleClient(); |
jack1930 | 0:829bac853c96 | 161 | } |
jack1930 | 0:829bac853c96 | 162 | |
jack1930 | 0:829bac853c96 | 163 | } |