Compatibility between ICMPPING.h and Ethernet2.h

Hi all,
I'm trying to code a sketch that continuosly ping some IP addresses on the LAN and posts the results on a Web Server in case one of the IP is not reachable.
I made (with some suggestions) a working sketch that makes the ping tasks.
I also have the code for the web server (simply the "Web Server" example)

I'm trying to make them work together, but I have some issues: it seams that if I put the instruction

ICMPEchoReply echoReply = ping(pingAddr, 4);

anywhere in the loop of the web server example, the web server stops working. I suppose that the problem is due to a multiple call of some functions, but I can't find wich one.
Could someone help me?
I'm working on Arduino UNO and Etherneth shield2.
Due to the shield model (W5500 chipset) I had to use a custom Ethernet library, that integrates some ICMP functions too.
Here the "ping" code:

#include <SPI.h>         
#include <Ethernet.h>
#include <ICMPPing.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE1}; // max address for ethernet shield
byte ip[] = {172, 19, 63, 37}; // ip address for ethernet shield
byte DefaultRouter[] =     { 172, 19, 62, 104 };
byte DomainNameServer[] =     { 192, 168, 0, 3 };
byte SubnetMask[] = { 255, 255, 240, 0} ;
IPAddress pingAddr(172, 19, 69, 77); // ip address to ping

SOCKET pingSocket = 0;

char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));

void setup() 
{
  // start Ethernet
  Ethernet.begin(mac, ip, DefaultRouter, DomainNameServer, SubnetMask );
  Serial.begin(9600);
}

void loop()
{
  ICMPEchoReply echoReply = ping(pingAddr, 4);
  if (echoReply.status == SUCCESS)
  {
    Serial.println("success");
  }
  else
  {
    Serial.println("failed");
  }
  
 delay(500);
}

Thank you!

Just to be more clear, this is the complete code. It compiles, but it doesn't enter the

if (client) {

of the web server.

#include <SPI.h>         
#include <Ethernet2.h>
#include <ICMPPing.h>
const int sirena = 14;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE1}; // max address for ethernet shield
byte ip[] = {172, 19, 63, 37}; // ip address for ethernet shield
byte DefaultRouter[] =     { 172, 19, 63, 254 };
byte DomainNameServer[] =     { 192, 168, 0, 3 };
byte SubnetMask[] = { 255, 255, 240, 0} ;
IPAddress pingAddr(172, 19, 62, 104); // ip address to ping  


SOCKET pingSocket = 0;
int failedCounter = 0;
char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));
EthernetServer server(80);

void setup() 
{
  // start Ethernet
  Ethernet.begin(mac, ip, DefaultRouter, DomainNameServer, SubnetMask);
  Serial.begin(9600);
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  pinMode(sirena, OUTPUT);
}

void loop()
{
  Serial.println("inizioil loop");
   EthernetClient client = server.available();
  
   if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(failedCounter);     //number of ping lost - I just need this on the web server
          client.println("<br />");
          client.println("</html>");

          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
    
  }
  ICMPEchoReply echoReply = ping(pingAddr, 4);      // this is the instruction that makes the server crash
  if (echoReply.status == SUCCESS)
  {
    Serial.println("success");
    failedCounter = 0;
  }
  else
  {
    //Serial.println("failed");
    failedCounter ++;
  }

  if (failedCounter > 4)
  {
    Serial.print("Ping consecutivi falliti: ");
    Serial.println (failedCounter);
    digitalWrite(sirena, HIGH);                    //phisical output for ping loss detection

  }
  else
  {
    //Serial.println("spengo relè");
    digitalWrite(sirena, LOW);
  } 
  delay(1000); 

}

Any suggestions? :frowning:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.