Connect issue with WiFiS3 using IPAddress

I tried to connect Arduino UNO R4 WiFi to my ESP32 IoT server, using its IPAddress. This failed.
My UNO R4 uses firmware 0.3.0.

I tried also the example WiFiWebClient.ino.
This works when using the server name, but not using the IP address:

// 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)
IPAddress server(142,250,203,100);  // numeric IP for Google (no DNS)

I retrieved the updated IP address with:

  if (client.connect(server, 80))
  {
    Serial.println("connected to server");
    IPAddress ip = client.remoteIP();
    Serial.print("server IP Address: ");
    Serial.println(ip);

Has anyone encountered this issue, or any idea to analyze or solve it? Thank you.
-jz-

updated IP address? what's that?

I was not sure if the IP address in the example is correct. So I connected using the name and retrieved the server IP. But using this IP address also failed.

Both addresses fail in browser:
http://74.125.232.128
http://142.250.203.100

I am too tired already to try more options. Maybe I find time tomorrow.

Has anybody successfully used connect with an IPAddress instead of a DNS name?

sorry. what is the server again? an esp32? is it in the same network? does it run a web server?

Yes. Yes. Yes. Yes. These for my initial test to connect to my IoT server.

The usual recommendation would be to use an example from WiFiS3. This is what I did!

Then I took the WiFiWebClient.ino example.
This example should work in two ways, either with a DNS name or with an IP address for www.google.com, according to the commented out line

//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)

Windows Edge doesn't show the IP address, so I can't check if this address is correct.
I have not yet decided to open an issue against this example.

I would appreciate if someone could verify this.

{
  "Status": 0 /* NOERROR */,
  "TC": false,
  "RD": true,
  "RA": true,
  "AD": false,
  "CD": false,
  "Question": [
    {
      "name": "google.com.",
      "type": 1 /* A */
    }
  ],
  "Answer": [
    {
      "name": "google.com.",
      "type": 1 /* A */,
      "TTL": 299,
      "data": "142.250.203.110"
    }
  ]
}

from Query: google.com - Google Public DNS
http://142.250.203.110 works, by redirection.

IPAddress server(142,250,203,110);  // numeric IP for Google (no DNS)

doesn't work.

it is a very old example originally from the Ethernet library. The google infrastructure may have changes so the access over IP address doesn't work.

I still hope someone will test this, the use of IPAddress on connect. Maybe with a different example or with his own one.
-jz-

I had no problems connecting WiFiClient with IP address in my project when I switched it to WiFiS3. there were other problems but not this

@Juraj, thank you for this information! Appreciated.

Could you report which version of the firmware was used?

I had to modify the example slightly to get it to work on ESP32 (Wemos LOLIN32 Lite).

The example works with IPAddress on ESP32, but not on Arduino UNO R4 WiFi (firmware 0.3.0)

/*
  Web client

  This sketch connects to a website (http://www.google.com)
  using the WiFi module.

  This example is written for a network using WPA encryption. For
  WEP or WPA, change the WiFi.begin() call accordingly.

  This example is written for a network using WPA encryption. For
  WEP or WPA, change the WiFi.begin() call accordingly.


  created 13 July 2010
  by dlf (Metodo2 srl)
  modified 31 May 2012
  by Tom Igoe

  Find the full UNO R4 WiFi RTC documentation here:
  https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#wi-fi-web-client
*/


#if defined(ARDUINO_UNOR4_WIFI)
#include "WiFiS3.h"
#else
#include <WiFi.h>
#endif


#include "arduino_secrets.h"

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key index number (needed only for WEP)

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) obsolete
IPAddress server(142,250,203,110);  // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

/* -------------------------------------------------------------------------- */
void setup() {
  /* -------------------------------------------------------------------------- */
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

#if defined(ARDUINO_UNOR4_WIFI)
  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }
#endif

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
    status = WiFi.status(); // needed for ESP32
  }

  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 80))
  {
    Serial.println("connected to server");
    IPAddress ip = client.remoteIP();
    Serial.print("server IP Address: ");
    Serial.println(ip);
    // 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();
  }
}

/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_response() {
  /* -------------------------------------------------------------------------- */
  uint32_t received_data_num = 0;
  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    /* print data to serial port */
    Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if (received_data_num % 80 == 0) {
      Serial.println();
    }
  }
}

/* -------------------------------------------------------------------------- */
void loop() {
  /* -------------------------------------------------------------------------- */
  read_response();

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

/* -------------------------------------------------------------------------- */
void printWifiStatus() {
  /* -------------------------------------------------------------------------- */
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

-jz-

it really has a problem to connect with IP address.

IP as string works, but not IPAddress

1 Like

EDIT: for future readers: the following posts by btoelectronics are off-topic

2 Likes

Firstly, it's generally not a good idea to post your Public IP Address
i suggest you change it

Yes, i have plenty of times

with the WiFiS3 library from renasas core 1.0.4?

btw: that is the IP address of www.google.com

It is in my example.

You don't see my address, do you?

NO, although that's not what he asked,
I got the impression he was asking if anyone had ACTUALLY Successfully connected using I.P. addressing
I didn't go into more detail as it looks like everything i would have told him you already are.

Google actually has many I.P. Addresses and even though i know approx 15 of them
this is not one that i instantly recognized

My first thought was, that he went and posted his Public I.P.
i mean, ... that's a very common thing for a person asking this sort of question to do.

In any case, No problem

I would also suggest that he learn to use cmd.exe and utilize
ping www.google.com
Enter

With WiFiS3? was this error missing in an earlier version?

Initially i assumed it was, and i was being cautious.
as this is a very common mistake of people to make who are asking questions relating
to ESP32 and Using the WiFi capability.
it happens because people want to be as open and transparent as possible

so you can understand how IT COULD HAVE BEEN YOUR I.P. right ?