Jack Hansdampf / Mbed OS WebServerGSOEWorkshopJalousie

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 
00022 #define Runterfahren 0b10
00023 #define Hochfahren 0b01
00024 #define Steht 0b00
00025 
00026 PortOut zustand(PortC,0b11);
00027 
00028 lcd myLCD;
00029 ESP8266Webserver myWebserver;
00030 AnalogIn windstaerke(PA_0);
00031 InterruptIn TO(PA_1);
00032 InterruptIn TU(PA_6);
00033 
00034 string getRootPage()
00035 {
00036       string webpage;
00037       webpage="<!DOCTYPE html>";
00038       //HTML
00039       webpage+="<html>";
00040       webpage+="<head>";
00041       webpage+="<title>STM32 HTTP</title>";
00042       webpage+="</head>";
00043       webpage+="<body>";
00044       webpage+="<h1>WIFI mit STM32 ESP01</h1>\n";
00045       webpage+="<table>";
00046       webpage+="<tr><td><a href=\"Hoch\"><button>Hoch</button></a></td><td><a href=\"Runter\"><button>Runter</button></a></td></tr>";
00047       webpage+="<tr><td>";
00048       webpage+="Windst&auml;rke:"+to_string(windstaerke); 
00049       webpage+="</td> <td>";
00050       webpage+="<a href=\"anzeigen\"><button>Anzeigen</button></a>\n";      
00051       webpage+="</td></tr></table>";
00052       webpage+="</body>";
00053       webpage+="</html>";
00054       return webpage;
00055 }
00056 
00057 void endschalterOben()
00058 {
00059     switch (zustand)
00060     {
00061         case Hochfahren: zustand=Steht;
00062             break;
00063     }
00064 }
00065 
00066 void endschalterUnten()
00067 {
00068     switch (zustand)
00069     {
00070         case Runterfahren: zustand=Steht;
00071             break;
00072     }
00073 }
00074 
00075 void anzeigen()
00076 {
00077     myWebserver.send(200,"text/html",getRootPage());
00078 }
00079 
00080 void hoch()
00081 {
00082     switch (zustand)
00083     {
00084         case Steht: 
00085             if (TO==0) 
00086             {
00087                 zustand=Hochfahren;
00088             }
00089             break;
00090     }
00091     myWebserver.send(200,"text/html",getRootPage());
00092 }
00093 
00094 void runter()
00095 {
00096     switch (zustand)
00097     {
00098         case Steht: 
00099             if (TU==0 && windstaerke<=0.87) 
00100             {
00101                 zustand=Runterfahren;
00102             }
00103             break;
00104     }
00105     myWebserver.send(200,"text/html",getRootPage());
00106 }
00107 
00108 void init()
00109 {
00110     zustand=Steht;
00111     TO.mode(PullDown);
00112     TO.rise(&endschalterOben);
00113     TO.enable_irq();
00114     TU.mode(PullDown);
00115     TU.rise(&endschalterUnten);
00116     TU.enable_irq();
00117     __enable_irq();
00118     
00119     myWebserver.on("/Hoch",&hoch);
00120     myWebserver.on("/Runter",&runter);
00121     myWebserver.on("/Anzeigen",&anzeigen);
00122     myWebserver.on("/",&anzeigen);
00123     myWebserver.begin();    
00124     myLCD.clear();
00125     myLCD.cursorpos(0);
00126     myLCD.printf("%s",myWebserver.gibIP());
00127 }
00128 
00129 
00130 
00131 
00132 int main() {  
00133     init();
00134 
00135     while(1)  {
00136          myWebserver.handleClient();
00137          switch (zustand)
00138          {
00139              case Steht: 
00140                 if (windstaerke>0.87 && TO==0)
00141                 {
00142                     zustand=Hochfahren;
00143                 }
00144                 break;
00145          }
00146     }
00147 }