#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiServer server(80);
String HTTP_req;
void setup()
{
Serial.begin(9600);
delay(10);
WiFi.mode(WIFI_AP_STA);
WiFi.softAP("ESP8266 Clock");
server.begin();
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
boolean currentLineIsBlank = true;
while(client.connected())
{
yield();
if (client.available())
{
char c = client.read();
HTTP_req += c;
if(c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
//HTTP request for web page
client.println("<!DOCTYPE html>"
"<html>"
"<head>"
"<title>Clock Settings</title>"
"</head>"
"<body>"
"<form method=\"post\">"
"<input type=\"submit\" name=\"clk_action\" value=\"RESET\">"
"</form>"
"</body>"
"</html>");
Serial.println(HTTP_req);
HTTP_req = ""; // finished with request, empty string
break;
}
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
When I press the button, I do get a POST request, but I'm not seeing the data. Here's what I get on the serial window:
POST / HTTP/1.1
Host: 192.168.4.1
Connection: keep-alive
Content-Length: 16
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,image/webp
Content-Type: application/x-www-form-urlencoded
Origin: http://192.168.4.1
Referer: http://192.168.4.1/
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) CriOS/45.0.2454.68 Mobile/12H143 Safari/600.1.4
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
GET /favicon.ico HTTP/1.1
Host: 192.168.4.1
Connection: keep-alive
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) CriOS/45.0.2454.68 Mobile/12H143 Safari/600.1.4
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8