Sounds easy right? Not really.
The Arduino Uno requires a shield in order to access a wired Ethernet network, such as the SunFounder clone on Amazon that resembles the genuine Ethernet Shield 2 from Arduino.cc.
First of all, the scripts will write to the serial monitor so that I may see if the icmp pings are successful. Remember to close the serial monitor before you attempt to upload any code, you will receive errors indicating the com port is busy and that access is denied. In other words, the serial monitor and the upload action are using the same COM port to communicate, but only one may be used at a time.
Moving on, I located the Arduino-Ping project, written by Blake Foster and hosted on Github. In order to incorporate his library I must build a new folder within the Arduino project called libraries, within that an additional folder sharing the same name as the .cpp/.h file, in this case ICMPPing.
After loading his example named Ping.ino I was met with many errors of the following variety. Those indicated to me that the methods defined in the Ping library were calling undefined methods in the Ethernet library.
C:\arduino-1.8.8\portable\sketchbook\libraries\icmp_ping\ICMPPing.cpp:184:11: error: 'class W5100Class' has no member named 'send_data_processing' W5100.send_data_processing(_socket, serialized, sizeof(ICMPEcho)); ^ C:\arduino-1.8.8\portable\sketchbook\libraries\icmp_ping\ICMPPing.cpp: In member function 'void ICMPPing::receiveEchoReply(const ICMPEcho&, const IPAddress&, ICMPEchoReply&)': C:\arduino-1.8.8\portable\sketchbook\libraries\icmp_ping\ICMPPing.cpp:207:19: error: 'class W5100Class' has no member named 'getRXReceivedSize' if (W5100.getRXReceivedSize(_socket) < 1)
After a bit of contemplation and searching for answers I learned that the Ethernet library, version 2, broke Blake’s ICMP-Ping library. To my relief, I found a thread on the Wiznet forum which documented that the Arduino Ethernet library versions 1.0.0 through 1.0.4 worked well with Blake’s code.
So, I returned to the Arduino IDE and accessed the menu option Sketch > Include Library > Manage Libraries.
Once in the library manager I search for the Ethernet library from the left pane. In the results observe you can assign what version you would like to use with a project. In my event I switched to 1.0.4, after doing so the code compiled.
But, it was still not working to my satisfaction. The pings were failing and I noticed that the shield was attempting to resolve the IP using ARP. However the ARP requests were asking for a MAC address for the assumed gateway.
Blake’s example includes the IP 192,168.2.177, which is a network with a 24 bit network mask. I knew immediately I would encounter errors until I adjust that.
So, as I continue developing this solution I turn my attention toward configuring a network mask that accurately reflects our network.
Needless to say I found plenty of wrong examples suggesting that the myDns attribute was instead dns. Knowing better, I checked the Arduino Ethernet class reference and there I discovered the right syntax. I had to then modify Brandon’s script in order to initialize the Ethernet object while using the additional myDns and gateway parameters.
As you can see from the image above, these few changes led to a script that worked for us. In the next episode I will present the code used to control relays that will operate a Simplex Grinell 4906-9151 Speaker Strobe.