WiFi Client Connectivity with a Google search Added

Hi there,
So You forgot to paste it into the code tags " </> " from above so , Here is a basic ping the host start there
you do know you’ll need a Google API key to do a custom search , So there’s that it does work with my own Key no problem.

  // Perform Google search
  googleSearch(searchQuery);
}

void googleSearch(String query) {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "https://www.googleapis.com/customsearch/v1?key=" + apiKey + "&cx=" + searchEngineId + "&q=" + query;
    
    // Make GET request
    http.begin(url);
    int httpCode = http.GET();

    // If the GET request was successful
    if (httpCode > 0) {
      String payload = http.getString();
      Serial.println("Search Result:");
      Serial.println(payload);
    } else {
      Serial.println("Error on HTTP request");
    }

    http.end(); // Free resources
  } else {
    Serial.println("WiFi not connected");
  }
}

Here is the code I’m using currently for testing.

#include <SPI.h>
#include <WiFi.h>

#include <ESP32Ping.h> 

const IPAddress remote_ip(8,8,8,8);
const char* remote_host = "www.google.com";

// Set these to your desired credentials.
const char *ssid = "GlassSurf-2.4";
const char *password = "SEEEDSTUDIO";  //not really

int status = WL_IDLE_STATUS;
IPAddress server(8,8,8,8); // Google
// Specify IP address or hostname
String hostName = "www.google.com";
int pingResult;
// Initialize the client library
WiFiClient client;

void setup() {
Serial.begin(9600);
//Serial.setDebugOutput(true);
Serial.println();
Serial.println();
  Serial.println("Program " __FILE__ " compiled on " __DATE__ " at " __TIME__);
  Serial.println();
  Serial.println("Processor came out of reset.");
  Serial.println();
Serial.println("Attempting to connect to WPA network…");
Serial.print("SSID: ");
Serial.println(ssid);

WiFi.begin(ssid, password);
WiFi.setSleep(false);
while ( WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
// don’t do anything else:
}
Serial.println("");
Serial.print("Connected to wifi");
 Serial.print(WiFi.localIP());

 // Ping Google
Serial.println("");
   Serial.print("Pinging ip ");
  Serial.println(remote_ip);

  if(Ping.ping(remote_ip)) {
    Serial.println("Success!!");
  } else {
    Serial.println("Error :(");
  }
Serial.print("Pinging host ");
  Serial.println(remote_host);

  if(Ping.ping(remote_host)) {
    Serial.println("Success!!");
  } else {
    Serial.println("Error :(");
  }
}

void loop() { }

Serial output.

Success!!


Program D:\Arduino_projects\Sketch_Google_ping\Sketch_Google_ping.ino compiled on Sep 10 2024 at 14:08:15

Processor came out of reset.

Attempting to connect to WPA network…
SSID: GlassSurf-2.4
.
Connected to wifi192.168.1.187
Pinging ip 8.8.8.8
Success!!
Pinging host www.google.com
Success!!

HTH
GL :slight_smile: PJ :v: