Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An ICMP Ping example #2

Open
johnjces opened this issue Jan 14, 2022 · 1 comment
Open

An ICMP Ping example #2

johnjces opened this issue Jan 14, 2022 · 1 comment

Comments

@johnjces
Copy link

I am not the sharpest tool in the shed, but I need a basic ICMP ping in one of my projects. I could never get the Blake Foster ICMPPing library to compile with the 2.0 Ethernet library and after googling my issue came upon this Ethernet library fork that had his ping library built in. Problem is I simply cannot change the original ping example to work.. or for that matter figure out exactly how this ICMPPing is implemted.

Could someone please provide an example ino?

Thanks so much!!

John

@xsertunc
Copy link

this works for me;

`
/*
Ping Example

This example sends an ICMP pings every 500 milliseconds, sends the human-readable
result over the serial port.
Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13

created 30 Sep 2010
by Blake Foster

*/

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // max address for ethernet shield
byte ip[] = {192,168,2,177}; // ip address for ethernet shield
IPAddress pingAddr(74,125,26,147); // ip address to ping

SOCKET pingSocket = 0;

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

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

void loop()
{
EthernetICMPEchoReply echoReply = ping(pingAddr, 4);
if (echoReply.status == SUCCESS)
{
sprintf(buffer,
"Reply[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d",
echoReply.data.seq,
echoReply.addr[0],
echoReply.addr[1],
echoReply.addr[2],
echoReply.addr[3],
REQ_DATASIZE,
millis() - echoReply.data.time,
echoReply.ttl);
}
else
{
sprintf(buffer, "Echo request failed; %d", echoReply.status);
}
Serial.println(buffer);
delay(500);
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants