ESP01 Webserver STM32 Steuerung
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE
main.cpp@10:54b312c82e18, 2021-07-26 (annotated)
- Committer:
- jack1930
- Date:
- Mon Jul 26 12:03:27 2021 +0000
- Revision:
- 10:54b312c82e18
- Parent:
- 7:40e19bb6820a
Steuerung
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 | |
jack1930 | 0:829bac853c96 | 21 | lcd myLCD; |
jack1930 | 1:1f13f5f1fdbc | 22 | ESP8266Webserver myWebserver; |
jack1930 | 7:40e19bb6820a | 23 | AnalogIn poti(PA_0); |
jack1930 | 10:54b312c82e18 | 24 | DigitalOut myled(PC_0); |
jack1930 | 5:b4ae03006c7d | 25 | string getRootPage() |
jack1930 | 0:829bac853c96 | 26 | { |
jack1930 | 6:5353c5484d58 | 27 | string webpage; |
jack1930 | 7:40e19bb6820a | 28 | webpage="<!DOCTYPE html>"; |
jack1930 | 3:8dba70d37b7d | 29 | //HTML |
jack1930 | 7:40e19bb6820a | 30 | webpage+="<html>"; |
jack1930 | 7:40e19bb6820a | 31 | webpage+="<head>"; |
jack1930 | 7:40e19bb6820a | 32 | webpage+="<title>STM32 HTTP</title>"; |
jack1930 | 7:40e19bb6820a | 33 | webpage+="</head>"; |
jack1930 | 7:40e19bb6820a | 34 | webpage+="<body>"; |
jack1930 | 0:829bac853c96 | 35 | webpage+="<h1>WIFI mit STM32 ESP01</h1>\n"; |
jack1930 | 7:40e19bb6820a | 36 | webpage+="<p>Poti:"+to_string(poti)+"</p>\n"; |
jack1930 | 10:54b312c82e18 | 37 | webpage+="<a href=\"ledAn\"><button>ON</button></a>\n"; |
jack1930 | 10:54b312c82e18 | 38 | webpage+="<a href=\"ledAus\"><button>OFF</button></a>\n"; |
jack1930 | 7:40e19bb6820a | 39 | webpage+="</body>"; |
jack1930 | 7:40e19bb6820a | 40 | webpage+="</html>"; |
jack1930 | 0:829bac853c96 | 41 | return webpage; |
jack1930 | 0:829bac853c96 | 42 | } |
jack1930 | 0:829bac853c96 | 43 | |
jack1930 | 0:829bac853c96 | 44 | |
jack1930 | 0:829bac853c96 | 45 | void testfunc() |
jack1930 | 0:829bac853c96 | 46 | { |
jack1930 | 5:b4ae03006c7d | 47 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 0:829bac853c96 | 48 | } |
jack1930 | 0:829bac853c96 | 49 | |
jack1930 | 10:54b312c82e18 | 50 | void testfunc2() |
jack1930 | 10:54b312c82e18 | 51 | { |
jack1930 | 10:54b312c82e18 | 52 | myled=0; |
jack1930 | 10:54b312c82e18 | 53 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 10:54b312c82e18 | 54 | } |
jack1930 | 10:54b312c82e18 | 55 | |
jack1930 | 10:54b312c82e18 | 56 | void testfunc3() |
jack1930 | 10:54b312c82e18 | 57 | { |
jack1930 | 10:54b312c82e18 | 58 | myled=1; |
jack1930 | 10:54b312c82e18 | 59 | myWebserver.send(200,"text/html",getRootPage()); |
jack1930 | 10:54b312c82e18 | 60 | } |
jack1930 | 0:829bac853c96 | 61 | |
jack1930 | 7:40e19bb6820a | 62 | int main() { |
jack1930 | 10:54b312c82e18 | 63 | myWebserver.on("ledAus",&testfunc2); |
jack1930 | 10:54b312c82e18 | 64 | myWebserver.on("ledAn",&testfunc3); |
jack1930 | 0:829bac853c96 | 65 | myWebserver.on("/",&testfunc); |
jack1930 | 7:40e19bb6820a | 66 | myWebserver.begin(); |
jack1930 | 2:c25aefe81534 | 67 | myLCD.clear(); |
jack1930 | 2:c25aefe81534 | 68 | myLCD.cursorpos(0); |
jack1930 | 2:c25aefe81534 | 69 | myLCD.printf("%s",myWebserver.gibIP()); |
jack1930 | 7:40e19bb6820a | 70 | while(1) { |
jack1930 | 0:829bac853c96 | 71 | myWebserver.handleClient(); |
jack1930 | 0:829bac853c96 | 72 | } |
jack1930 | 0:829bac853c96 | 73 | } |