Hallo,
ich breche mir einen ab und komme mit intensivster Suche nicht mehr weiter :
1.) Der Wert des Sliders ( später noch 2 zusätzlich ) springt jedesmal auf den
voreingestellten Wert. Wie kann ich das verhindern, bzw. letzten Wert merken
wenn client neu verbunden ist.
2.) Einbau submit für Übergabe des Sliders an ESP ??
Wir muss der syntax für den submit-Befehl aussehen ?
Vielen Dank im voraus
Gruss olmuk
#include <ESP8266WiFi.h>
const char* ssid = "";
const char* password = "";
unsigned long ulReqcount;
unsigned long ulReconncount;
boolean Test = 0;
int sumresult = 0;
int z1 = 0;
// Create an instance of the server on Port 80
WiFiServer server(80);
void setup()
{
// setup globals
ulReqcount=0;
ulReconncount=0;
// prepare GPIO2
pinMode(13, OUTPUT);
pinMode(16, OUTPUT);
digitalWrite(13, 0);
digitalWrite(16, 0);
// start serial
Serial.begin(9600);
delay(1);
// inital connect
WiFi.mode(WIFI_STA);
WiFiStart();
}
void WiFiStart()
{
ulReconncount++;
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop()
{
// check if WLAN is connected
if (WiFi.status() != WL_CONNECTED)
{
WiFiStart();
}
// Check if a client has connected
WiFiClient client = server.available();
if (!client)
{
return;
}
// Wait until the client sends some data
Serial.println("new client");
unsigned long ultimeout = millis()+250;
while(!client.available() && (millis()<ultimeout) )
{
delay(1);
}
if(millis()>ultimeout)
{
Serial.println("client connection time-out!");
return;
}
// Read the first line of the request
String sRequest = client.readStringUntil('\r');
//Serial.println(sRequest);
client.flush();
// stop client, if request is empty
if(sRequest=="")
{
Serial.println("empty request! - stopping client");
client.stop();
return;
}
// get path; end of path is either space or ?
// Syntax is e.g. GET /?pin=MOTOR1STOP HTTP/1.1
String sPath="",sParam="", sCmd="";
String sGetstart="GET ";
int iStart,iEndSpace,iEndQuest;
iStart = sRequest.indexOf(sGetstart);
if (iStart>=0)
{
iStart+=+sGetstart.length();
iEndSpace = sRequest.indexOf(" ",iStart);
iEndQuest = sRequest.indexOf("?",iStart);
// are there parameters?
if(iEndSpace>0)
{
if(iEndQuest>0)
{
// there are parameters
sPath = sRequest.substring(iStart,iEndQuest);
sParam = sRequest.substring(iEndQuest,iEndSpace);
}
else
{
// NO parameters
sPath = sRequest.substring(iStart,iEndSpace);
}
}
}
///////////////////////////////////////////////////////////////////////////////
// output parameters to serial, you may connect e.g. an Arduino and react on it
///////////////////////////////////////////////////////////////////////////////
if(sParam.length()>0)
{
int iEqu=sParam.indexOf("=");
if(iEqu>=0)
{
sCmd = sParam.substring(iEqu+1,sParam.length());
Serial.println(sCmd);
}
}
///////////////////////////
// format the html response
///////////////////////////
String sResponse,sHeader;
////////////////////////////
// 404 for non-matching path
////////////////////////////
if(sPath!="/")
{
sResponse="<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>";
sHeader = "HTTP/1.1 404 Not found\r\n";
sHeader += "Content-Length: ";
sHeader += sResponse.length();
sHeader += "\r\n";
sHeader += "Content-Type: text/html\r\n";
sHeader += "Connection: close\r\n";
sHeader += "\r\n";
}
///////////////////////
// format the html page
///////////////////////
else
{
ulReqcount++;
sResponse = "<html><head><title>Gartenlicht</title></head><body>";
sResponse += "<font color=\"#000000\"><body bgcolor=\"#d0d0f0\">";
sResponse += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
sResponse += "<FONT SIZE=+3>";
sResponse += "<h1>Gartenlicht</h1>";
sResponse += "<FONT SIZE=+2>";
sResponse += "<p>Aufgang WiGa <a href=\"?pin=FUNCTION1ON\"><button style=height:60px;width:100px>EIN</button></a> <a href=\"?pin=FUNCTION1OFF\"><button style=height:60px;width:100px>AUS</button></a></p>";
sResponse += "<p>Gartenweg <a href=\"?pin=FUNCTION2ON\"><button style=height:60px;width:100px>EIN</button></a> <a href=\"?pin=FUNCTION2OFF\"><button style=height:60px;width:100px>AUS</button></a></p>";
sResponse += "
";
if(sCmd.indexOf("FUNCTION1ON") >= 0)
sResponse += "<td width='30%' ALIGN=CENTER rowspan='2'><font color='green' size='+2'> Aufgang WiGa an</td>";
else
sResponse += "<td width='30%' ALIGN=CENTER rowspan='2'><font color='red' size='+2'> Aufgang WiGa aus</td>";
sResponse += "
";
sResponse += "
";
if(sCmd.indexOf("FUNCTION2ON") >= 0)
sResponse += "<td width='30%' ALIGN=CENTER rowspan='2'><font color='green' size='+2'> Gartenweg an</td>";
else
sResponse += "<td width='30%' ALIGN=CENTER rowspan='2'><font color='red' size='+2'> Gartenweg aus</td>";
sResponse += "
";
sResponse += "<font color='black'>";
sResponse += "
";
sResponse += "
";
sResponse += "<form oninput=sumresult.value=parseInt(z1.value)>";
sResponse += "<input type=range name=z1>";
sResponse += "The output is: <output name=sumresult></output>";
sResponse += "
";
sResponse += "
";
sResponse += "</form></td>";
//////////////////////
// react on parameters
//////////////////////
if (sCmd.length()>0)
{
// write received command to html page
sResponse += "<font color='black' size='+1'>";
sResponse += "Kommando: " + sCmd + "
";
// switch GPIO13
if(sCmd.indexOf("FUNCTION1ON") >= 0)
{
digitalWrite(13, 1);
Test = 1;
}
else if (sCmd.indexOf("FUNCTION1OFF") >=0)
{
digitalWrite(13, 0);
Test = 0;
}
// switch GPIO16
if(sCmd.indexOf("FUNCTION2ON")>=0)
{
digitalWrite(16, 1);
}
else if(sCmd.indexOf("FUNCTION2OFF")>=0)
{
digitalWrite(16, 0);
}
// if(sCmd.indexOf("3=einschalten") > -1);
Serial.println(Test);
}
sResponse += "</body></html>";
sHeader = "HTTP/1.1 200 OK\r\n";
sHeader += "Content-Length: ";
sHeader += sResponse.length();
sHeader += "\r\n";
sHeader += "Content-Type: text/html\r\n";
sHeader += "Connection: close\r\n";
sHeader += "\r\n";
}
// Send the response to the client
client.print(sHeader);
client.print(sResponse);
Serial.print(sumresult);
Serial.print(z1);
// and stop the client
client.stop();
Serial.println("Client disonnected");
}