Go Down

Topic: how to use WifiWebClient Sketch with Google IP address? (Read 447 times) previous topic - next topic

maker99

The sketch WIFI101 / WifiWebClient runs great (with Winc1500 breakout board).

It contains a google URL example but also says you can use google's IP address:

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)


So I tried

char server[] = "(74,125,232,128)";

but it didn't work. Having searched the internet found this example from the Ethernet library in which the syntax seems the same but curly brackets are used:

https://www.arduino.cc/en/Reference/ClientConnect

So tried:

char server[] = "{74,125,232,128}";

but that didn't work either.

Also tried a number of other things (eg leaving off the brackets...) but no luck.

Anyone know how to make this sketch work with google's IP address instead of domain name?

pert

Arduino has a special type called IPAddress that makes it easy to work with IP addresses. That is one of the allowed argument types of the WiFi101 library's connect function.

Change the line:
Code: [Select]
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
to:
Code: [Select]
IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)

Change the line:
Code: [Select]
char server[] = "www.google.com";    // name address for Google (using DNS)
to:
Code: [Select]
//char server[] = "www.google.com";    // name address for Google (using DNS)

maker99


maker99

Incidentally, further down the script the domain "google.com" comes up once again:

  if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  }

What is the role of the following line? Is it optional?

 client.println("Host: www.google.com");



Go Up