ICMP Ping Library for Arduino
Author: Blake Foster
Contact: https://blake-foster.com/contact.php
Navigation
History
Release | Date | Changes |
1.0 | 2010-09-30 | Initial Release |
2.0 | 2013-04-17 | API redesigned, minor bug fixes |
Description
ICMP Ping library for the Arduino.
Requirements
This library works with the Arduino Ethernet shield. I have tested it with the Arduino Duemilanove, but it should work with any model that is compatible with the Ethernet shield.
Setup
- Download the zip file or clone the repo
- Copy the icmp_ping directory into the libraries directory of your Arduino folder.
Usage
The basic steps for using this library are:
- Import the heder ICMPPing.h
- Import Ethernet.h
- Start Ethernet
- Create an instance of ICMPPing
- Use one of the two overloaded functional-call operators to send and receive an ICMPEcho.
For documentation of all classes and methods, see ICMPPing.h
Example
/*
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 <Ethernet.h>
#include <ICMPPing.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];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));
void setup()
{
// start Ethernet
Ethernet.begin(mac, ip);
Serial.begin(9600);
}
void loop()
{
ICMPEchoReply 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);
}
Download
Download here:
Contribute
Project in Github