Jack Hansdampf / Mbed OS WebServerGSOEWorkshop

Dependencies:   LCD_i2c_GSOE ESP8266WebserverGSOE

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 
00021 PortOut diag(PortC,0xFF);
00022 lcd myLCD;
00023 ESP8266Webserver myWebserver;
00024 AnalogIn poti(PA_0);
00025 DigitalIn taste(PA_1);
00026 
00027 
00028 
00029 string getRootPage()
00030 {
00031       string webpage;
00032       webpage="<!DOCTYPE html>\n";
00033       //Javascript
00034       webpage+="<script type=\"text/javascript\">\n";
00035       webpage+="var x;";
00036       webpage+="function z(){location.assign(\"http://"+(string)(myWebserver.gibIP())+"\");}";
00037       webpage+="function sT(){x=setInterval(z,5000);}";
00038       webpage+="function spT(){clearInterval(x);}";
00039       webpage+="onload=sT();";
00040       webpage+="</script>\n";
00041       //HTML
00042       webpage+="<html>\n";
00043       webpage+="<head>\n";
00044       webpage+="<title>STM32 HTTP</title>\n";
00045       webpage+="</head>\n";
00046       webpage+="<body>\n";
00047       webpage+="<h1>WIFI mit STM32 ESP01</h1>\n";
00048       webpage+="<p>Aufrufe:"+to_string(myWebserver.Aufrufe)+"</p>\n"; 
00049       webpage+="<p>Poti:"+to_string(poti)+"</p>\n"; 
00050       webpage+="<p>Taste PA_1:"+to_string(taste)+"</p>\n"; 
00051       //Formular
00052       webpage+="<form>\n";
00053       webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n";
00054       webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n";
00055       webpage+="<label for=\"checkmich\">check mich:</label>\n";
00056       webpage+="<input type=\"checkbox\" id=\"checkmich\" name=\"checkmich\">\n";
00057       webpage+="<button>finden</button>\n";
00058       webpage+="</form>\n";
00059       //Buttons
00060       webpage+="<H2>LED On/Off </H2>\n";
00061       webpage+="<a href=\"ledAn\"><button>ON</button></a>\n";      
00062       webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n";
00063       webpage+="</body>\n";
00064       webpage+="</html>\n";
00065   
00066       return webpage;
00067 
00068 }
00069 
00070 
00071 void testfunc()
00072 {
00073     diag=diag|0x80;
00074     
00075     myWebserver.send(200,"text/html",getRootPage());
00076 }
00077 
00078 void testfunc2()
00079 {
00080     diag=0x40;
00081     myWebserver.send(200,"text/html",getRootPage());
00082 }
00083 void testfunc3()
00084 {
00085     diag=0x20;
00086     myWebserver.send(200,"text/html",getRootPage());
00087 }
00088 
00089 void testfunc4()
00090 {
00091     diag=diag|0x10;
00092     myLCD.clear();
00093     myLCD.cursorpos(0);
00094     myLCD.printf("%s",myWebserver.gibWert("Suchbegriff"));
00095     myLCD.cursorpos(0x40);
00096     myLCD.printf("%s",myWebserver.gibWert("checkmich"));
00097     myWebserver.send(200,"text/html",getRootPage());
00098 }
00099 
00100 int main()
00101 {
00102     taste.mode(PullDown);
00103     
00104     myWebserver.on("Suchbegriff",&testfunc4);
00105     myWebserver.on("ledaus",&testfunc2);
00106     myWebserver.on("ledAn",&testfunc3);
00107     myWebserver.on("/",&testfunc);
00108 
00109     myWebserver.begin();
00110     
00111     myLCD.clear();
00112     myLCD.cursorpos(0);
00113     myLCD.printf("%s",myWebserver.gibIP());
00114     
00115 
00116 
00117     while(1)
00118     {
00119          myWebserver.handleClient();
00120     }
00121     
00122 }