ESP01 STM32 Nucleo statisch Webserver
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE
main.cpp@5:b4ae03006c7d, 2021-07-23 (annotated)
- Committer:
- jack1930
- Date:
- Fri Jul 23 13:09:44 2021 +0000
- Revision:
- 5:b4ae03006c7d
- Parent:
- 4:d19ae06fc0bb
- Child:
- 6:5353c5484d58
Webserver fue Mikrocontrollerworkshop
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 | 5:b4ae03006c7d | 30 | AnalogIn poti(PA_0); |
jack1930 | 5:b4ae03006c7d | 31 | DigitalIn taste(PA_1); |
jack1930 | 0:829bac853c96 | 32 | |
jack1930 | 3:8dba70d37b7d | 33 | string webpage; |
jack1930 | 0:829bac853c96 | 34 | |
jack1930 | 5:b4ae03006c7d | 35 | string getRootPage() |
jack1930 | 0:829bac853c96 | 36 | { |
jack1930 | 0:829bac853c96 | 37 | |
jack1930 | 0:829bac853c96 | 38 | webpage="<!DOCTYPE html>\n"; |
jack1930 | 3:8dba70d37b7d | 39 | //Javascript |
jack1930 | 3:8dba70d37b7d | 40 | webpage+="<script type=\"text/javascript\">"; |
jack1930 | 3:8dba70d37b7d | 41 | webpage+="var x;"; |
jack1930 | 3:8dba70d37b7d | 42 | webpage+="function z(){location.assign(\"http://"; |
jack1930 | 5:b4ae03006c7d | 43 | webpage+=myWebserver.gibIP(); |
jack1930 | 3:8dba70d37b7d | 44 | webpage+="\");}"; |
jack1930 | 4:d19ae06fc0bb | 45 | webpage+="function sT(){x=setInterval(z,5000);}"; |
jack1930 | 3:8dba70d37b7d | 46 | webpage+="function spT(){clearInterval(x);}"; |
jack1930 | 3:8dba70d37b7d | 47 | webpage+="onload=sT();"; |
jack1930 | 3:8dba70d37b7d | 48 | webpage+="</script>\n"; |
jack1930 | 3:8dba70d37b7d | 49 | //HTML |
jack1930 | 0:829bac853c96 | 50 | webpage+="<html>\n"; |
jack1930 | 0:829bac853c96 | 51 | webpage+="<head>\n"; |
jack1930 | 0:829bac853c96 | 52 | webpage+="<title>STM32 HTTP</title>\n"; |
jack1930 | 0:829bac853c96 | 53 | webpage+="</head>\n"; |
jack1930 | 0:829bac853c96 | 54 | webpage+="<body>\n"; |
jack1930 | 0:829bac853c96 | 55 | webpage+="<h1>WIFI mit STM32 ESP01</h1>\n"; |
jack1930 | 3:8dba70d37b7d | 56 | webpage+="<p>Aufrufe:"; |
jack1930 | 3:8dba70d37b7d | 57 | webpage+=to_string(myWebserver.Aufrufe); |
jack1930 | 5:b4ae03006c7d | 58 | webpage+="</p>\n"; |
jack1930 | 5:b4ae03006c7d | 59 | webpage+="<p>Poti:"; |
jack1930 | 5:b4ae03006c7d | 60 | webpage+=to_string(poti); |
jack1930 | 5:b4ae03006c7d | 61 | webpage+="</p>\n"; |
jack1930 | 3:8dba70d37b7d | 62 | |
jack1930 | 5:b4ae03006c7d | 63 | webpage+="<p>Taste PA_1:"; |
jack1930 | 5:b4ae03006c7d | 64 | webpage+=to_string(taste); |
jack1930 | 3:8dba70d37b7d | 65 | webpage+="</p>\n"; |
jack1930 | 0:829bac853c96 | 66 | |
jack1930 | 0:829bac853c96 | 67 | webpage+="<form>\n"; |
jack1930 | 0:829bac853c96 | 68 | webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n"; |
jack1930 | 0:829bac853c96 | 69 | webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n"; |
jack1930 | 5:b4ae03006c7d | 70 | webpage+="<label for=\"checkmich\">check mich:</label>\n"; |
jack1930 | 5:b4ae03006c7d | 71 | webpage+="<input type=\"checkbox\" id=\"checkmich\" name=\"checkmich\">\n"; |
jack1930 | 0:829bac853c96 | 72 | webpage+="<button>finden</button>\n"; |
jack1930 | 0:829bac853c96 | 73 | webpage+="</form>\n"; |
jack1930 | 0:829bac853c96 | 74 | webpage+="<H2>LED On/Off </H2>\n"; |
jack1930 | 0:829bac853c96 | 75 | webpage+="<a href=\"ledAn\"><button>ON</button></a>\n"; |
jack1930 | 0:829bac853c96 | 76 | webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n"; |
jack1930 | 0:829bac853c96 | 77 | webpage+="</body>\n"; |
jack1930 | 0:829bac853c96 | 78 | webpage+="</html>\n"; |
jack1930 | 3:8dba70d37b7d | 79 | |
jack1930 | 0:829bac853c96 | 80 | return webpage; |
jack1930 | 0:829bac853c96 | 81 | |
jack1930 | 0:829bac853c96 | 82 | } |
jack1930 | 0:829bac853c96 | 83 | |
jack1930 | 0:829bac853c96 | 84 | |
jack1930 | 0:829bac853c96 | 85 | void testfunc() |
jack1930 | 0:829bac853c96 | 86 | { |
jack1930 | 0:829bac853c96 | 87 | diag=diag|0x80; |
jack1930 | 0:829bac853c96 | 88 | |
jack1930 | 5:b4ae03006c7d | 89 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 0:829bac853c96 | 90 | } |
jack1930 | 0:829bac853c96 | 91 | |
jack1930 | 0:829bac853c96 | 92 | void testfunc2() |
jack1930 | 0:829bac853c96 | 93 | { |
jack1930 | 0:829bac853c96 | 94 | diag=0x40; |
jack1930 | 5:b4ae03006c7d | 95 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 0:829bac853c96 | 96 | } |
jack1930 | 0:829bac853c96 | 97 | void testfunc3() |
jack1930 | 0:829bac853c96 | 98 | { |
jack1930 | 0:829bac853c96 | 99 | diag=0x20; |
jack1930 | 5:b4ae03006c7d | 100 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 0:829bac853c96 | 101 | } |
jack1930 | 0:829bac853c96 | 102 | |
jack1930 | 0:829bac853c96 | 103 | void testfunc4() |
jack1930 | 0:829bac853c96 | 104 | { |
jack1930 | 0:829bac853c96 | 105 | diag=diag|0x10; |
jack1930 | 0:829bac853c96 | 106 | myLCD.clear(); |
jack1930 | 0:829bac853c96 | 107 | myLCD.cursorpos(0); |
jack1930 | 3:8dba70d37b7d | 108 | myLCD.printf("%s",myWebserver.gibWert("Suchbegriff")); |
jack1930 | 0:829bac853c96 | 109 | myLCD.cursorpos(0x40); |
jack1930 | 5:b4ae03006c7d | 110 | myLCD.printf("%s",myWebserver.gibWert("checkmich")); |
jack1930 | 5:b4ae03006c7d | 111 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 0:829bac853c96 | 112 | } |
jack1930 | 0:829bac853c96 | 113 | |
jack1930 | 0:829bac853c96 | 114 | int main() |
jack1930 | 3:8dba70d37b7d | 115 | { |
jack1930 | 5:b4ae03006c7d | 116 | taste.mode(PullDown); |
jack1930 | 5:b4ae03006c7d | 117 | |
jack1930 | 0:829bac853c96 | 118 | myWebserver.on("Suchbegriff",&testfunc4); |
jack1930 | 0:829bac853c96 | 119 | myWebserver.on("ledaus",&testfunc2); |
jack1930 | 0:829bac853c96 | 120 | myWebserver.on("ledAn",&testfunc3); |
jack1930 | 0:829bac853c96 | 121 | myWebserver.on("/",&testfunc); |
jack1930 | 0:829bac853c96 | 122 | |
jack1930 | 0:829bac853c96 | 123 | myWebserver.begin(); |
jack1930 | 0:829bac853c96 | 124 | |
jack1930 | 2:c25aefe81534 | 125 | myLCD.clear(); |
jack1930 | 2:c25aefe81534 | 126 | myLCD.cursorpos(0); |
jack1930 | 2:c25aefe81534 | 127 | myLCD.printf("%s",myWebserver.gibIP()); |
jack1930 | 2:c25aefe81534 | 128 | |
jack1930 | 0:829bac853c96 | 129 | |
jack1930 | 0:829bac853c96 | 130 | |
jack1930 | 0:829bac853c96 | 131 | while(1) |
jack1930 | 0:829bac853c96 | 132 | { |
jack1930 | 0:829bac853c96 | 133 | myWebserver.handleClient(); |
jack1930 | 0:829bac853c96 | 134 | } |
jack1930 | 0:829bac853c96 | 135 | |
jack1930 | 0:829bac853c96 | 136 | } |