A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By hartnerk
#87504 I currently have a page which on submission is posting the below to httpsbin.com. I am looking to program my esp8266 in softap mode to accept this post information from my phone. I have posted my esp8266 code and am struggling with how to refer to the posted data in the ESP8266WebServer class and hot to use that in the handle_Working() method?

Any help or direction you can provide is much appreciated.

'''''
args: {}
data: ""
files: {}
form: {key1: "1", key2: "1", key3: "1", key4: "E2F779", key5: "E2F779", key6: "E2F779"}
key1: "1"
key2: "1"
key3: "1"
key4: "E2F779"
key5: "E2F779"
key6: "E2F779"
headers: {Accept: "*/*", Accept-Encoding: "gzip, deflate, br", Accept-Language: "en-US,en;q=0.9",…}
Accept: "*/*"
Accept-Encoding: "gzip, deflate, br"
Accept-Language: "en-US,en;q=0.9"
Content-Length: "611"
Content-Type: "multipart/form-data; boundary=----WebKitFormBoundaryZXr1FwR2WZUkGP5K"
Dnt: "1"
Host: "httpbin.org"
Origin: "null"
Sec-Fetch-Dest: "empty"
Sec-Fetch-Mode: "cors"
Sec-Fetch-Site: "cross-site"
User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
X-Amzn-Trace-Id: "Root=1-5edc178b-c7483f0e6a08673015e11968"
json: null
origin: "xxx.xx.xxx.xx"
url: "https://httpbin.org/post"
''''''''
''''''''
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <Adafruit_NeoPixel.h>

#include <FS.h> //Include File System Headers

/* Put your SSID & Password */
const char* ssid = "CoastAwhileIOT"; // Enter SSID here
const char* password = "tempPass"; //Enter Password here

const char INDEX_HTML[] ="/BoatLight.html";

/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(80);

uint8_t LED1pin = 0;
bool LED1status = LOW;

uint8_t LED2pin = 1;
bool LED2status = LOW;

uint8_t LED3pin = 3;
bool LED2status = LOW;

void setup() {
Serial.begin(115200);
pinMode(LED1pin, OUTPUT);
pinMode(LED2pin, OUTPUT);
pinMode(LED3pin, OUTPUT);

WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(100);

server.on("/html", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html", INDEX_HTML);
});
server.on("/", handle_OnConnect);
server.on("/", HTTP_POST, handle_Working);
server.onNotFound(handle_NotFound);

server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}

void handle_OnConnect() {
LED1status = LOW;
LED2status = LOW;
LED3status = LOW;
Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF");
server.send(200, "text/html", INDEX_HTML);

}

void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}

void handle_Working(){
if( ! server.hasArg("key1") || ! server.hasArg("key2") || ! server.hasArg("key3") || server.arg("key1") == NULL || server.arg("key2") == NULL || server.arg("key3") == NULL{ // If the POST request doesn't have username and password data
server.send(400, "text/plain", "400: Invalid Request"); // The request is invalid, so send HTTP status 400
return;
}else if(server.hasArg("key4") || ! server.hasArg("key5") || ! server.hasArg("key6"){
//set NEOPIXEL Ring to ON with Yellow light
server.send(200, "text/html", "<p>Lights successful</p>");

}else{
//set NEOPIXEL Ring to Key3 Color
server.send(200, "text/html", "<p>Lights successful</p>");
}
}
'''''''''''