0

Hi beautiful community of ESP!

I am trying to send a http request from browser to the esp8266. Currently I have ESP8266WebServer running on the esp and listening to incoming http requests. I have a function which listens to request made by browser and activates a function example: if I type 'http://ipofesp/ledon' the ledon function will be called upon '/ledon' in the url.

The code I am using is:

#include <ESP8266WebServer.h>
ESP8266WebServer server;

void setup(){

server.on("/",[](){server.send(200,"text/plain","Hello World");});
server.on("/ledon",ledon);

server.onNotFound(handleNotFound);

}

void loop() {
server.handleClient();
}

void ledon(){

digitalWrite(D5, LOW)

}

void handleNotFound(){

server.send(200,"text/plain","Wrong input");

}

This works file for me but now I am trying to send a http request from browser to the esp8266 with an http payload. How can I fetch the http payload in esp8266?

is there any built-in function in the server object?

Nobster
  • 11
  • 1
  • `server.send()` is the way to send data back to client. Take a look at [PostServer](https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/examples/PostServer/PostServer.ino) example. – hcheung May 19 '20 at 04:11
  • @hcheung I don't want to send data to client. client is sending http request with payload data. I want to fetch the data in esp8266 – Nobster May 19 '20 at 04:45
  • Is your client another esp8266? or simply a browser? For browser, you need to setup JavaScript [ajax](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX) call from your browser to send the data back. You can take a look at one of my [project](https://www.e-tinkers.com/2019/11/build-an-esp32-web-server-and-ir-remote/) to see how to send data back. – hcheung May 19 '20 at 05:02
  • On the server side, you need to setup the route/endpoint to handle the request and setup the appropriate html/javascript page at `/` route using the same `server.send()`, which is why I suggest to take a look at PostServer example. – hcheung May 19 '20 at 05:04

1 Answers1

0

You want to use a ''HTTP GET request''. For that you also need to define some PHP code to get the information from the webserver.

So you send some command to a PHP script, that command is processed on the webserver with results stored for a HTTP GET request from the ESP8266.

Blobtech
  • 11
  • 1