ESP01 Webserver STM32 Steuerung

Dependencies:   LCD_i2c_GSOE ESP8266WebserverGSOE

main.cpp

Committer:
jack1930
Date:
2021-06-10
Revision:
1:1f13f5f1fdbc
Parent:
0:829bac853c96
Child:
2:c25aefe81534

File content as of revision 1:1f13f5f1fdbc:

/* ATCmdParser usage example
 * Copyright (c) 2016 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "mbed.h"
#include "ESP8266Webserver.h"
#include "LCD.h"
//#include "string"


//DigitalOut CH_PD(PB_13);
//DigitalOut RST(PB_12);
PortOut diag(PortC,0xFF);
lcd myLCD;

ESP8266Webserver myWebserver;



string getRootPage2()
{

   string webpage;

      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);
      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);



      webpage="<!DOCTYPE html>\n";
      webpage+="<html>\n";
      webpage+="<head>\n";
      webpage+="<title>STM32 HTTP</title>\n";
      webpage+="</head>\n";
      webpage+="<body>\n";
      webpage+="<h1>WIFI mit STM32 ESP01</h1>\n";
      webpage+="<p>Webpage2</p>\n"; //WebseiteZeile1);
      
      webpage+="<form>\n";
      webpage+="<label for=\"Suchbegriff\">Suchbegriff</label>\n";
      webpage+="<input id=\"Suchbegriff\" name=\"Suchbegriff\">\n";
      webpage+="<label for=\"alter\">ueber 18:</label>\n";
      webpage+="<input type=\"checkbox\" id=\"alter\" name=\"alter\">\n";
      webpage+="<button>finden</button>\n";
      webpage+="</form>\n";
      webpage+="<H2>LED On/Off </H2>\n";
      webpage+="<a href=\"ledAn\"><button>ON</button></a>\n";      
      webpage+="<a href=\"ledaus\"><button>OFF</button></a>\n";
      webpage+="</body>\n";
      webpage+="</html>\n";
      
      return webpage;

}

char* getRootPage()                                        //This function contains data to be sent to local server
{

    static char webpage[1000];

      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);
      //sprintf(webpage,"<script type=\"text/javascript\">var x; function z(){location.assign(\"http://%s\");}  function sT(){x=setInterval(z,10000);} function spT(){clearInterval(x);} onload=sT(); </script> <html> <h1>GSOE WIFI ESP01<hr> </h1>  <hr> Aufrufe = %d <hr> Poti= %d <hr> <a href=\"http://%s/r\"</a>Reset</A> </html>",IP,Aufrufe,Ain0(),IP);



      strcpy(webpage,"<!DOCTYPE html>\r\n");
      strcat(webpage,"<html>\r\n");
      strcat(webpage,"<head>\r\n");
      strcat(webpage,"<title>STM32 HTTP</title>\r\n");
      strcat(webpage,"</head>\r\n");
      strcat(webpage,"<body>\r\n");
      strcat(webpage,"<h1>WIFI mit STM32 ESP01</h1>\r\n");
      strcat(webpage,"<p>WebseiteZeiletest</p>\r\n"); //WebseiteZeile1);
      
      strcat(webpage,"<form>\r\n");
      strcat(webpage,"<label for=\"Suchbegriff\">Suchbegriff</label>\r\n");
      strcat(webpage,"<input id=\"Suchbegriff\" name=\"Suchbegriff\">\r\n");
      strcat(webpage,"<label for=\"alter\">ueber 18:</label>\r\n");
      strcat(webpage,"<input type=\"checkbox\" id=\"alter\" name=\"alter\">\r\n");
      strcat(webpage,"<button>finden</button>\r\n");
      strcat(webpage,"</form>\r\n");
      strcat(webpage,"</body>\r\n");
      strcat(webpage,"</html>\r\n");
      
      return webpage;

}

void testfunc()
{
    diag=diag|0x80;
    
    myWebserver.send(200,"text/html",getRootPage2());
}

void testfunc2()
{
    diag=0x40;
        /*myLCD.clear();
    myLCD.cursorpos(0);
    myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str());
    myLCD.cursorpos(0x40);
    myLCD.printf("%s",myWebserver.gibWert("alter"));*/
    myWebserver.send(200,"text/html",getRootPage2());
}
void testfunc3()
{
    diag=0x20;
        /*myLCD.clear();
    myLCD.cursorpos(0);
    myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str());
    myLCD.cursorpos(0x40);
    myLCD.printf("%s",myWebserver.gibWert("alter"));*/
    myWebserver.send(200,"text/html",getRootPage2());
}

void testfunc4()
{
    diag=diag|0x10;
    myLCD.clear();
    myLCD.cursorpos(0);
    myLCD.printf("%s",myWebserver.gibWertString("Suchbegriff").c_str());
    myLCD.cursorpos(0x40);
    myLCD.printf("%s",myWebserver.gibWert("alter"));
    myWebserver.send(200,"text/html",getRootPage2());
}

int main()
{/*
    RST=0;
 //   CH_PD=1;
    HAL_Delay(1000);
    RST=1;*/
    //myWebserver.debugOn(false);

    myWebserver.on("Suchbegriff",&testfunc4);
    myWebserver.on("ledaus",&testfunc2);
    myWebserver.on("ledAn",&testfunc3);
    myWebserver.on("/",&testfunc);

    myWebserver.begin();
    



    while(1)
    {
         myWebserver.handleClient();
    }
    
}