1

I have an Arduino Uno and an ESP8266 and I want to send a HTTP get request to google.com and print the response. Please help me thanks.

Michel Keijzers
  • 12,954
  • 7
  • 40
  • 56
alireza
  • 45
  • 1
  • 6
  • 1
    if you have AT firmware in esp8266, use AT commands or WiFiEsp library. the library has examples. for AT commands you can google may examples. – Juraj Dec 18 '18 at 13:22

1 Answers1

2

You can use ESP8266Wifi Arduino Library.

Here an example:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "yourNetworkName";
const char* password = "yourNetworkPassword";

void setup () {

  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

    delay(1000);
    Serial.print("Connecting..");

  }

}

void loop() {

  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

    HTTPClient http;  //Declare an object of class HTTPClient

    http.begin("http://www.google.com");  //Specify request destination
    int httpCode = http.GET();     //Send the request                                                           

    if (httpCode > 0) { //Check the returning code

      String payload = http.getString();   //Get the request response payload
      Serial.println(payload);                     //Print the response payload

    }

    http.end();   //Close connection

  }

  delay(30000);    //Send a request every 30 seconds

}
leoc7
  • 603
  • 4
  • 12
  • but this is for coding directly on esp8266 I want to upload the code to arduino uno – alireza Dec 18 '18 at 13:18
  • Ok, do you want to use AT commands? See this post: https://arduino.stackexchange.com/questions/32567/get-data-from-website-with-esp8266-using-at-commands – leoc7 Dec 18 '18 at 13:22