ESP01 STM32 Nucleo statisch Webserver
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE
main.cpp@4:d19ae06fc0bb, 2021-06-22 (annotated)
- Committer:
- jack1930
- Date:
- Tue Jun 22 09:58:43 2021 +0000
- Revision:
- 4:d19ae06fc0bb
- Parent:
- 3:8dba70d37b7d
- Child:
- 5:b4ae03006c7d
kleinere Bugs
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 | 3:8dba70d37b7d | 22 | #include <string> |
jack1930 | 0:829bac853c96 | 23 | |
jack1930 | 3:8dba70d37b7d | 24 | |
jack1930 | 3:8dba70d37b7d | 25 | |
jack1930 | 3:8dba70d37b7d | 26 | |
jack1930 | 0:829bac853c96 | 27 | PortOut diag(PortC,0xFF); |
jack1930 | 0:829bac853c96 | 28 | lcd myLCD; |
jack1930 | 1:1f13f5f1fdbc | 29 | ESP8266Webserver myWebserver; |
jack1930 | 0:829bac853c96 | 30 | |
jack1930 | 0:829bac853c96 | 31 | |
jack1930 | 3:8dba70d37b7d | 32 | string webpage; |
jack1930 | 0:829bac853c96 | 33 | |
jack1930 | 0:829bac853c96 | 34 | string getRootPage2() |
jack1930 | 0:829bac853c96 | 35 | { |
jack1930 | 0:829bac853c96 | 36 | |
jack1930 | 0:829bac853c96 | 37 | webpage="<!DOCTYPE html>\n"; |
jack1930 | 3:8dba70d37b7d | 38 | //Javascript |
jack1930 | 3:8dba70d37b7d | 39 | webpage+="<script type=\"text/javascript\">"; |
jack1930 | 3:8dba70d37b7d | 40 | webpage+="var x;"; |
jack1930 | 3:8dba70d37b7d | 41 | webpage+="function z(){location.assign(\"http://"; |
jack1930 | 3:8dba70d37b7d | 42 | webpage+=myWebserver.gibIP();//"192.168.1.117"; |
jack1930 | 3:8dba70d37b7d | 43 | webpage+="\");}"; |
jack1930 | 4:d19ae06fc0bb | 44 | webpage+="function sT(){x=setInterval(z,5000);}"; |
jack1930 | 3:8dba70d37b7d | 45 | webpage+="function spT(){clearInterval(x);}"; |
jack1930 | 3:8dba70d37b7d | 46 | webpage+="onload=sT();"; |
jack1930 | 3:8dba70d37b7d | 47 | webpage+="</script>\n"; |
jack1930 | 3:8dba70d37b7d | 48 | //HTML |
jack1930 | 0:829bac853c96 | 49 | webpage+="<html>\n"; |
jack1930 | 0:829bac853c96 | 50 | webpage+="<head>\n"; |
jack1930 | 0:829bac853c96 | 51 | webpage+="<title>STM32 HTTP</title>\n"; |
jack1930 | 0:829bac853c96 | 52 | webpage+="</head>\n"; |
jack1930 | 0:829bac853c96 | 53 | webpage+="<body>\n"; |
jack1930 | 0:829bac853c96 | 54 | webpage+="<h1>WIFI mit STM32 ESP01</h1>\n"; |
jack1930 | 3:8dba70d37b7d | 55 | webpage+="<p>Aufrufe:"; |
jack1930 | 3:8dba70d37b7d | 56 | webpage+=to_string(myWebserver.Aufrufe); |
jack1930 | 3:8dba70d37b7d | 57 | |
jack1930 | 3:8dba70d37b7d | 58 | webpage+="</p>\n"; |
jack1930 | 0:829bac853c96 | 59 | |
jack1930 | 0:829bac853c96 | 60 | webpage+="<form>\n"; |
jack1930 | 0:829bac853c96 | 61 | webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n"; |
jack1930 | 0:829bac853c96 | 62 | webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n"; |
jack1930 | 0:829bac853c96 | 63 | webpage+="<label for=\"alter\">ueber 18:</label>\n"; |
jack1930 | 0:829bac853c96 | 64 | webpage+="<input type=\"checkbox\" id=\"alter\" name=\"alter\">\n"; |
jack1930 | 0:829bac853c96 | 65 | webpage+="<button>finden</button>\n"; |
jack1930 | 0:829bac853c96 | 66 | webpage+="</form>\n"; |
jack1930 | 0:829bac853c96 | 67 | webpage+="<H2>LED On/Off </H2>\n"; |
jack1930 | 0:829bac853c96 | 68 | webpage+="<a href=\"ledAn\"><button>ON</button></a>\n"; |
jack1930 | 0:829bac853c96 | 69 | webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n"; |
jack1930 | 0:829bac853c96 | 70 | webpage+="</body>\n"; |
jack1930 | 0:829bac853c96 | 71 | webpage+="</html>\n"; |
jack1930 | 3:8dba70d37b7d | 72 | |
jack1930 | 0:829bac853c96 | 73 | return webpage; |
jack1930 | 0:829bac853c96 | 74 | |
jack1930 | 0:829bac853c96 | 75 | } |
jack1930 | 0:829bac853c96 | 76 | |
jack1930 | 3:8dba70d37b7d | 77 | //Alternativ mit char* statt string |
jack1930 | 3:8dba70d37b7d | 78 | |
jack1930 | 3:8dba70d37b7d | 79 | char* getRootPage() |
jack1930 | 0:829bac853c96 | 80 | { |
jack1930 | 0:829bac853c96 | 81 | |
jack1930 | 0:829bac853c96 | 82 | static char webpage[1000]; |
jack1930 | 0:829bac853c96 | 83 | |
jack1930 | 0:829bac853c96 | 84 | strcpy(webpage,"<!DOCTYPE html>\r\n"); |
jack1930 | 0:829bac853c96 | 85 | strcat(webpage,"<html>\r\n"); |
jack1930 | 0:829bac853c96 | 86 | strcat(webpage,"<head>\r\n"); |
jack1930 | 0:829bac853c96 | 87 | strcat(webpage,"<title>STM32 HTTP</title>\r\n"); |
jack1930 | 0:829bac853c96 | 88 | strcat(webpage,"</head>\r\n"); |
jack1930 | 0:829bac853c96 | 89 | strcat(webpage,"<body>\r\n"); |
jack1930 | 0:829bac853c96 | 90 | strcat(webpage,"<h1>WIFI mit STM32 ESP01</h1>\r\n"); |
jack1930 | 3:8dba70d37b7d | 91 | strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); |
jack1930 | 0:829bac853c96 | 92 | |
jack1930 | 0:829bac853c96 | 93 | strcat(webpage,"<form>\r\n"); |
jack1930 | 0:829bac853c96 | 94 | strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n"); |
jack1930 | 0:829bac853c96 | 95 | strcat(webpage,"<input id=\"Suchbegriff\" name=\"Suchbegriff\">\r\n"); |
jack1930 | 0:829bac853c96 | 96 | strcat(webpage,"<label for=\"alter\">ueber 18:</label>\r\n"); |
jack1930 | 0:829bac853c96 | 97 | strcat(webpage,"<input type=\"checkbox\" id=\"alter\" name=\"alter\">\r\n"); |
jack1930 | 0:829bac853c96 | 98 | strcat(webpage,"<button>finden</button>\r\n"); |
jack1930 | 0:829bac853c96 | 99 | strcat(webpage,"</form>\r\n"); |
jack1930 | 3:8dba70d37b7d | 100 | |
jack1930 | 3:8dba70d37b7d | 101 | strcat(webpage,"<H2>LED On/Off </H2>\n"); |
jack1930 | 3:8dba70d37b7d | 102 | strcat(webpage,"<a href=\"ledAn\"><button>ON</button></a>\n"); |
jack1930 | 3:8dba70d37b7d | 103 | strcat(webpage,"<a href=\"ledaus\"><button>OFF</button></a>\n"); |
jack1930 | 0:829bac853c96 | 104 | strcat(webpage,"</body>\r\n"); |
jack1930 | 0:829bac853c96 | 105 | strcat(webpage,"</html>\r\n"); |
jack1930 | 0:829bac853c96 | 106 | |
jack1930 | 0:829bac853c96 | 107 | return webpage; |
jack1930 | 0:829bac853c96 | 108 | |
jack1930 | 0:829bac853c96 | 109 | } |
jack1930 | 0:829bac853c96 | 110 | |
jack1930 | 0:829bac853c96 | 111 | void testfunc() |
jack1930 | 0:829bac853c96 | 112 | { |
jack1930 | 0:829bac853c96 | 113 | diag=diag|0x80; |
jack1930 | 0:829bac853c96 | 114 | |
jack1930 | 0:829bac853c96 | 115 | myWebserver.send(200,"text/html",getRootPage2()); |
jack1930 | 0:829bac853c96 | 116 | } |
jack1930 | 0:829bac853c96 | 117 | |
jack1930 | 0:829bac853c96 | 118 | void testfunc2() |
jack1930 | 0:829bac853c96 | 119 | { |
jack1930 | 0:829bac853c96 | 120 | diag=0x40; |
jack1930 | 0:829bac853c96 | 121 | myWebserver.send(200,"text/html",getRootPage2()); |
jack1930 | 0:829bac853c96 | 122 | } |
jack1930 | 0:829bac853c96 | 123 | void testfunc3() |
jack1930 | 0:829bac853c96 | 124 | { |
jack1930 | 0:829bac853c96 | 125 | diag=0x20; |
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 | 3:8dba70d37b7d | 134 | myLCD.printf("%s",myWebserver.gibWert("Suchbegriff")); |
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 | 3:8dba70d37b7d | 141 | { |
jack1930 | 0:829bac853c96 | 142 | |
jack1930 | 0:829bac853c96 | 143 | myWebserver.on("Suchbegriff",&testfunc4); |
jack1930 | 0:829bac853c96 | 144 | myWebserver.on("ledaus",&testfunc2); |
jack1930 | 0:829bac853c96 | 145 | myWebserver.on("ledAn",&testfunc3); |
jack1930 | 0:829bac853c96 | 146 | myWebserver.on("/",&testfunc); |
jack1930 | 0:829bac853c96 | 147 | |
jack1930 | 0:829bac853c96 | 148 | myWebserver.begin(); |
jack1930 | 0:829bac853c96 | 149 | |
jack1930 | 2:c25aefe81534 | 150 | myLCD.clear(); |
jack1930 | 2:c25aefe81534 | 151 | myLCD.cursorpos(0); |
jack1930 | 2:c25aefe81534 | 152 | myLCD.printf("%s",myWebserver.gibIP()); |
jack1930 | 2:c25aefe81534 | 153 | |
jack1930 | 0:829bac853c96 | 154 | |
jack1930 | 0:829bac853c96 | 155 | |
jack1930 | 0:829bac853c96 | 156 | while(1) |
jack1930 | 0:829bac853c96 | 157 | { |
jack1930 | 0:829bac853c96 | 158 | myWebserver.handleClient(); |
jack1930 | 0:829bac853c96 | 159 | } |
jack1930 | 0:829bac853c96 | 160 | |
jack1930 | 0:829bac853c96 | 161 | } |