I am using an esp8266 01 module with the Arduino Uno to establish a communication between the Arduino and my web site. I actually don't know how to send Rest HTTP requests from the Arduino to get data from my web site. I have done research but all I got is codes using nodemcu so I was wondering will the code of nodeMCU work fine on the Arduino using ESP01 and if not then how can I send get and post request from the Arduino using esp01
this the code that I found
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "SERVER NAME";
const char* password = "SERVER PASSWORD";
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println("Connecting...");
}
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http; //Object of class HTTPClient
http.begin("http://jsonplaceholder.typicode.com/users/1");
int httpCode = http.GET();
if (httpCode > 0)
{
const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject& root = jsonBuffer.parseObject(http.getString());
int id = root["id"];
const char* name = root["name"];
const char* username = root["username"];
const char* email = root["email"];
Serial.print("Name:");
Serial.println(name);
Serial.print("Username:");
Serial.println(username);
Serial.print("Email:");
Serial.println(email);
}
http.end(); //Close connection
}
delay(60000);
}