Jack Hansdampf / Mbed OS ATCmdParserTest_V1_0_F103

Dependencies:   ESP8266WebserverF103 LCD_i2c_GSOE

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 //#include "string"
00021 
00022 #include <string>
00023 
00024 
00025 
00026 
00027 PortOut diag(PortC,0xFF);
00028 lcd myLCD;
00029 ESP8266Webserver myWebserver;
00030 
00031 
00032 string webpage;
00033 
00034 string getRootPage2()
00035 {
00036 
00037       webpage="<!DOCTYPE html>\n";
00038       //Javascript
00039       webpage+="<script type=\"text/javascript\">";
00040       webpage+="var x;";
00041       webpage+="function z(){location.assign(\"http://";
00042       webpage+=myWebserver.gibIP();//"192.168.1.117";
00043       webpage+="\");}";
00044       webpage+="function sT(){x=setInterval(z,5000);}";
00045       webpage+="function spT(){clearInterval(x);}";
00046       webpage+="onload=sT();";
00047       webpage+="</script>\n";
00048       //HTML
00049       webpage+="<html>\n";
00050       webpage+="<head>\n";
00051       webpage+="<title>STM32 HTTP</title>\n";
00052       webpage+="</head>\n";
00053       webpage+="<body>\n";
00054       webpage+="<h1>WIFI mit STM32 ESP01</h1>\n";
00055       webpage+="<p>Aufrufe:";
00056       webpage+=to_string(myWebserver.Aufrufe);
00057       
00058       webpage+="</p>\n"; 
00059       
00060       webpage+="<form>\n";
00061       webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n";
00062       webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n";
00063       webpage+="<label for=\"alter\">ueber 18:</label>\n";
00064       webpage+="<input type=\"checkbox\" id=\"alter\" name=\"alter\">\n";
00065       webpage+="<button>finden</button>\n";
00066       webpage+="</form>\n";
00067       webpage+="<H2>LED On/Off </H2>\n";
00068       webpage+="<a href=\"ledAn\"><button>ON</button></a>\n";      
00069       webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n";
00070       webpage+="</body>\n";
00071       webpage+="</html>\n";
00072   
00073       return webpage;
00074 
00075 }
00076 
00077 //Alternativ mit char* statt string
00078 
00079 char* getRootPage()                                       
00080 {
00081 
00082     static char webpage[1000];
00083 
00084       strcpy(webpage,"<!DOCTYPE html>\r\n");
00085       strcat(webpage,"<html>\r\n");
00086       strcat(webpage,"<head>\r\n");
00087       strcat(webpage,"<title>STM32 HTTP</title>\r\n");
00088       strcat(webpage,"</head>\r\n");
00089       strcat(webpage,"<body>\r\n");
00090       strcat(webpage,"<h1>WIFI mit STM32 ESP01</h1>\r\n");
00091       strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); 
00092       
00093       strcat(webpage,"<form>\r\n");
00094       strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n");
00095       strcat(webpage,"<input id=\"Suchbegriff\" name=\"Suchbegriff\">\r\n");
00096       strcat(webpage,"<label for=\"alter\">ueber 18:</label>\r\n");
00097       strcat(webpage,"<input type=\"checkbox\" id=\"alter\" name=\"alter\">\r\n");
00098       strcat(webpage,"<button>finden</button>\r\n");
00099       strcat(webpage,"</form>\r\n");
00100       
00101       strcat(webpage,"<H2>LED On/Off </H2>\n");
00102       strcat(webpage,"<a href=\"ledAn\"><button>ON</button></a>\n");      
00103       strcat(webpage,"<a href=\"ledaus\"><button>OFF</button></a>\n");
00104       strcat(webpage,"</body>\r\n");
00105       strcat(webpage,"</html>\r\n");
00106       
00107       return webpage;
00108 
00109 }
00110 
00111 void testfunc()
00112 {
00113     diag=diag|0x80;
00114     
00115     myWebserver.send(200,"text/html",getRootPage2());
00116 }
00117 
00118 void testfunc2()
00119 {
00120     diag=0x40;
00121     myWebserver.send(200,"text/html",getRootPage2());
00122 }
00123 void testfunc3()
00124 {
00125     diag=0x20;
00126     myWebserver.send(200,"text/html",getRootPage2());
00127 }
00128 
00129 void testfunc4()
00130 {
00131     diag=diag|0x10;
00132     myLCD.clear();
00133     myLCD.cursorpos(0);
00134     myLCD.printf("%s",myWebserver.gibWert("Suchbegriff"));
00135     myLCD.cursorpos(0x40);
00136     myLCD.printf("%s",myWebserver.gibWert("alter"));
00137     myWebserver.send(200,"text/html",getRootPage2());
00138 }
00139 
00140 int main()
00141 {
00142 
00143     myWebserver.on("Suchbegriff",&testfunc4);
00144     myWebserver.on("ledaus",&testfunc2);
00145     myWebserver.on("ledAn",&testfunc3);
00146     myWebserver.on("/",&testfunc);
00147 
00148     myWebserver.begin();
00149     
00150     myLCD.clear();
00151     myLCD.cursorpos(0);
00152     myLCD.printf("%s",myWebserver.gibIP());
00153     
00154 
00155 
00156     while(1)
00157     {
00158          myWebserver.handleClient();
00159     }
00160     
00161 }