Chat freely about anything...

User avatar
By Jonathancorera
#49945 HI,

I've been working with the ESP8266 module and programming it through the Arduino IDE. Ive worked with a lot of hardware, but am new to transmission protocols and the like. I've been trying to write a program with HTTP POST and GET requests while running the ESP in an accesspoint mode (as a webserver). I am able to configure the ESP as a hotspot and connect to the hotspot via my laptop. I now need to send GET requests and respond to POST requests via the ESP IP address. I am able to print and read strings from the page, but am unable to process HTTP requests. I was also unable to find any example code for this.

Any help with this would be greatly appreciated. I basically need to GET and POST JSON objects (I can create the objects) using the ESP on AP mode to it's default IP.
User avatar
By Vlado93
#49964 In Arduino IDE go to Examples > ESP8266WiFi and take a look at WiFiAccessPoint sketch. This instruction server.on("/", handleRoot); is used to select which function will be called (handleRoot) when certain request is sent to the specified path (<yourDeviceIPAddress>./ in this case). If you want to process only one kind of request, GET request for example, then you could put server.on("/", HTTP_GET, handleRoot);
In handleRoot function you send back the response with server.send instruction.You can obtain type of request with server.method(), or request arguments with server.arg(0), server.arg(1) etc. With server.argName() you can obtain arguments' names and server.args() total number of argument names.
User avatar
By Jonathancorera
#50018 @Vlado93
Thanks so much. With your help I was able to handle get request. I had a couple more questions on this topic though. I'm a little new to the whole web communication protocol thing, so please bear with me if the questions seem silly.

1) Would I be able to pass a JSON object instead of a string as an argument with the ESP8266?
2) Is the "server.send" command the same as a POST command? If so, how would I configure and work with header files?
User avatar
By Vlado93
#50155 1) You can pass json object. I used Postman app to send post requests with a specified json object in body. On the ESP8266 side, you can obtain object with server.arg(0). Then you can use ArduinoJson library to parse the object.
2) It's not the same as POST request, it is a response. You can return to a client HTML code with send command.