Display ping results to a webpage

Hi,

I’m trying to build a project that will remotely start and stop my computer using a relay. I’m using an Arduino UNO R3; a W5100 ethernet shield and an ultrasonic sensor, which will act like a gesture power switch (whenever the distance is less than a certain amount it will trigger the relay.
I put all the components together with an LED instead of relay for testing purposes and so far everything works.
However, I would also like to send a ping from arduino to my computer and display a message in my webpage based on the ping result.

So far I have the below code:

//Initial setup for shield

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address 
byte ip[] = { 192, 168, 100, 150 }; // IP address in LAN – need to change according to your Network address 
byte gateway[] = { 192, 168, 100, 1 }; // internet access via router 
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask 
EthernetServer server(80); //server port
String readString; 

//Initial setup for ultrasonic sensor

const int ledPin = 3; // The pin of your LED
const int trigPin = 4; // The pin to which the TRIG is connected
const int echoPin = 5; // The pin to which the ECHO is connected
const int ledOnTime = 1000; // The time that the LED stays on, after detecting the motion (in milliseconds, 1000ms = 1s)
const int trigDistance = 10; // The distance (and lower than it) at which the sensor is triggered (in centimeters)
 
int duration;
int distance;

void setup(){

    pinMode(ledPin, OUTPUT); //pin selected to control 
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    //start Ethernet 
    Ethernet.begin(mac, ip, gateway, subnet); 
    server.begin(); 
}

void loop(){ 

//Loop part for ultrasonic

  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  delay(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
 
  if (distance <= trigDistance) {
    digitalWrite(ledPin, HIGH);
  }
  if (distance > trigDistance) { 
    digitalWrite(ledPin, LOW);
  }
  delay(100);

//Loop part for ethernet shield
  
    // Create a client connection 
    EthernetClient client = server.available(); 
    if (client) { 
        while (client.connected()) { 
            if (client.available()) { 
                char c = client.read();

                //read char by char HTTP request 
                if (readString.length() < 100) {

                    //store characters to string 
                    readString += c; 
                }

                //if HTTP request has ended– 0x0D is Carriage Return \n ASCII 
                if (c == 0x0D) { 
                    client.println("HTTP/1.1 200 OK"); //send new page 
                    client.println("Content-Type: text/html"); 
                    client.println();

                    client.println("<HTML>"); 
                    client.println("<HEAD>"); 
                    client.println("<TITLE> ARDUINO ETHERNET SHIELD</TITLE>"); 
                    client.println("</HEAD>"); 
                    client.println("<BODY>"); 
                    client.println("<hr>"); 
                    client.println("<hr>"); 
                    client.println("
"); 
                    client.println("<H1 style=\"color:green;\">ARDUINO ETHERNET SHIELD & LED ON/OFF FROM WEBPAGE</H1>"); 
                    client.println("<hr>"); 
                    client.println("
");

                    client.println("<H2><a href=\"/?LEDON3\"\">Turn On LED 3 sec</a>
</H2>"); 
                    client.println("<H2><a href=\"/?LEDON5\"\">Turn On LED 5 sec</a>
</H2>");

                    client.println("</BODY>"); 
                    client.println("</HTML>");

                    delay(10); 
                    //stopping client 
                    client.stop();

                    // control arduino pin 
                    if(readString.indexOf("?LEDON3") > -1) //checks for LEDON3 
                    { 
                        digitalWrite(ledPin, HIGH); // set pin high
                        delay(3000); 
                    } 
                    else{ 
                        if(readString.indexOf("?LEDON5") > -1) //checks for LEDON5 
                        { 
                            digitalWrite(ledPin, HIGH); // set pin high 
                            delay(5000); 
                        } 
                    } 
                    //clearing string for next read 
                    readString="";

                } 
            } 
        } 
    } 
}

I have tried to merge this code with the ping example from here: https://playground.arduino.cc/Code/ICMPPing

Unfortunately, it will fail no matter what I try. The code compiles fine but the webpage will not function anymore.
Can someone point me in the right direction or give me a similar example of how ping result could be displayed in a webpage?

Thank you!

Cheers!

whenever the distance is less than a certain amount it will trigger the relay.

Is? Or becomes? Why would you want to keep turning the relay on over and over?

  if (distance <= trigDistance) {
    digitalWrite(ledPin, HIGH);
  }
  if (distance > trigDistance) {

When if statements are mutually exclusive, the second one should be an else. There is no point in testing a condition that must be true, if the preceding one was not.

I have tried to merge this code with the ping example from here: https://playground.arduino.cc/Code/ICMPPing

There is NOTHING in the code you posted that makes a ping request. There is NO place in your html data where you (would) display the result of the ping request that was (not) made.