I've found posts explaining how to get client IP by modifying the W5100 Ethernet library and the Adafruit CC3000 library but not the Ethernet2 lib for W5500 chip, which is different enough that the W5100 mod won't work. I suspect the TCP Socket struct will contain it, but haven't been able to find its declaration anywhere to confirm this so I can modify the library to make it accessible.
2 Answers
Use the new update of the 'old' Ethernet library. It is version 2.00 and you can install or update it in the Library Manager in IDE. Note, it is not Ethernet2 library. The new Ethernet library supports W5500 and has client.remoteIP()
.
if (client.connect(server, 80)) {
Serial.print("connected to ");
Serial.println(client.remoteIP());
New features in version 2.0.0 Auto-detection of W5100, W5200, and W5500 Ethernet hardware.
-
The version cited here is for the W5100 chip and won't work with the W5500, as mentioned on the Arduino reference page for the Ethernet library - "Ethernet library (Ethernet.h) manages the W5100 chip, while Ethernet2 library (Ethernet2.h) manages the W5500 chip; all the functions remain the same." Commented Aug 25, 2018 at 21:15
-
-
Thanks, the link was helpful. As I thought, I already had it installed in my Arduino IDE. When I looked at the source file names I saw W5100.cpp and thought nothing had changed. Looking at the code, though, I see additions to handle W5200 and W5500. Commented Aug 27, 2018 at 20:04
This solution works: http://forum.arduino.cc/index.php/topic,82416.0.html if "W5100.readSnDIPR(_sock, remoteIP);" is replaced with "w5500.readSnDIPR(_sock, remoteIP);" [note the lower case 'w']. I didn't think it would because I can't find readSnDIPR() in the Ethernet2 library source, but after reviewing the Wiznet 5500 data sheet (https://www.mouser.com/pdfdocs/w5500_ds_v100e.PDF) I realized it was probably a read of the "Socket n Destination IP Address" register and decided to try it and see if it linked. It did, and successfully returns the remote IP after connecting.
-
and why do you use an outdated library? Ethernet2 is now obsolete– Juraj ♦Commented Aug 22, 2018 at 20:08
-
From Arduino reference page for Ethernet library: "Ethernet library (Ethernet.h) manages the W5100 chip, while Ethernet2 library (Ethernet2.h) manages the W5500 chip; all the functions remain the same." The current version of Ethernet2 is V2, btw, and it does not have a remoteIP method in its client class. Commented Aug 23, 2018 at 15:03
-
the new version is less then a month old. the docs are not updated– Juraj ♦Commented Aug 23, 2018 at 15:19
-
I have the latest version available via the Arduino IDE. Perhaps you should post a link here to the later version for the benefit of others. Commented Aug 24, 2018 at 19:01