Giter Club home page Giter Club logo

arduino-ping's Introduction

Copyright (c) 2010 by Blake Foster [email protected]

This file is free software; you can redistribute it and/or modify it under the terms of either the GNU General Public License version 2 or the GNU Lesser General Public License version 2.1, both as published by the Free Software Foundation.

Arduino-Ping

ICMP ping library for the Arduino

To use, copy the icmp_ping directory into the libraries directory of your Arduino folder.

e.g. cp ~/Arduino-Ping/icmp_ping /usr/share/arduino/libraries/icmp_ping

Then restart the Arduino software if necessary, and icmp_ping should be available under the libraries dropdown.

See the included sketch for example usage. See the header (ICMP.h) for API documentation.

The master branch currently requires at least version 1.5.5 beta of the Arduino software. For older versions of the Arduino software, use version 2.1. After cloning:

cd Arduino-Ping git checkout version2.1

arduino-ping's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-ping's Issues

Error with member function and error with class W5100Class

i tryed our code example to test first

#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,180,177}; // ip address for ethernet shield
IPAddress pingAddr(74,125,180,130); // 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);
}-----------------------------------------------------------------------------------------------------------------------------------------
but i got this when i try to compiled

\ICMPPing.cpp: In member function 'Status ICMPPing::sendEchoRequest(const IPAddress&, const ICMPEcho&)':
ICMPPing.cpp:184:11: error: 'class W5100Class' has no member named 'send_data_processing'
W5100.send_data_processing(_socket, serialized, sizeof(ICMPEcho));
ICMPPing.cpp: In member function 'void ICMPPing::receiveEchoReply(const ICMPEcho&, const IPAddress&, ICMPEchoReply&)':
ICMPPing.cpp:207:19: error: 'class W5100Class' has no member named 'getRXReceivedSize'
if (W5100.getRXReceivedSize(_socket) < 1)
ICMPPing.cpp:219:9: error: 'class W5100Class' has no member named 'read_data'
W5100.read_data(_socket, (uint16_t) buffer, ipHeader, sizeof(ipHeader));
\ICMPPing.cpp:229:9: error: 'class W5100Class' has no member named 'read_data'
W5100.read_data(_socket, (uint16_t) buffer, serialized, dataLen);

Error in calc icmp crc code

Hi.
If this library is executed on arduino, then an error often occurs in the checksum calculation function( _checksum ).
In this place:
...
sum += *time + *(time + 1);
...
If the sum of two 16-bit numbers is more than the 16-bit number can hold, then the most significant bits of the sum are lost.
This line should be replaced with:

sum += *time;
sum += *(time + 1);

Then the sum of the 32 bit and 16 bit number is stored in a 32 bit number.
Or not use time in the icmp packet constructor:

ICMPEcho :: ICMPEcho (uint8_t type, uint16_t _id, uint16_t _seq, uint8_t * _payload): seq (_seq), id (_id), time (0)

pinging multiple targets - socket problem

Hi folks,
thanks to @BlakeFoster for this library, good work, also thanks to @psychogenic for the async feature. I'd like to use Arduino as a watchdog for multiple targets. When I'm using this library for just one target everything is ok but with more (i.e. 8) I'm loosing too many packets - when I'm pinging Arduino itself but also (and this is bad) I'm getting false timeouts while pinging targets. With async pinging it is little bit stable but still unusable as a watchdog.

I'm doing ping in a cycle, one target by one with a delay between them and some delay after a round, I'm trying to set more retries and various timeouts but still with packet loss. Btw. in the async mode and multiple targets, Arduino is no longer responding to the icmp. I've also tried multiple sockets but in this scenario I have to turn off the async mode (not working with it) and results are still bad. I'm using MegaADK with Eth. Shield and/or Ethernet board rev. 3, both with the same results.

I know that Arduino is very limited hw and tcp/ip stack is not robust but anyway, do you please have some advice for me or do you think that this application is not able to handle it? Maybe if I should empty some buffer after a while, it can work ... In other case I'll try to port this application to the linux side of the Arduino Yun or some RPi. Thank you.

ICMPPing.cpp TTL Value

Hi Blake,

I was browsing through the code as I seem to be getting a lot of false positives (no response). I am wondering why you settled on TTL value as 128? Line 124 of ICMPPing.cpp.

Should the initial value not be 255? as what I am reading here
http://openmaniak.com/ping.php#ping-ttl
A windows system will deduct 128 from the TTL value, probably the reason why I am getting a lot of false positives.

You'll have to forgive me, as your code does exceed my knowledge of C, but I am trying to grasp it.

After I have set TTL to 255, the number of false positives I am experiencing has dropped to almost nothing.

Thanks, Andrew.

runtime error: invalid magic number when using WiFi and Ethernet

Hello, I hope this library is still active

when using the library on ESP32 having a W5500 module (using adapated version here: https://github.com/andrew-susanto/Arduino-Ethernet-Icmp) it works fine.

However, I have a use case when I need to determine at runtime if I use WiFi or Ethernet
The problem is that as soon as I call WiFi.begin() method or any other method like WiFi.mode() the following error is raised:

E (2041) wifi:invalid magic number 7fffffff, call WIFI_INIT_CONFIG_DEFAULT to init config
[ 2019][E][WiFiGeneric.cpp:680] wifiLowLevelInit(): esp_wifi_init 258
[ 2022][E][WiFiSTA.cpp:227] begin(): STA enable failed!

This happens even if there is absolutely no code used from the library, only making the inlcude <EthernetICMP.h> would trigger the issue. It looks like it break the WiFi stck somehow,

Any idea what to do to make this avoiding breaking WiFi ?

Thnaks for your help

not able to add library

whenever I try to add library i get the following error message:

subfolder of your sketchbook is not a valid library
Invalid library found in ~/Documents/Arduino/libraries/Arduino-Ping: ~/Documents/Arduino/libraries/Arduino-Ping

I am using Mac OSx , the instruction given on readme doesnt work on mac, so please help fixing this issue.

No longer compatible with built in ethernet library

I cant compile this library. Upon testing, if I revert the built in ethernet library back to version 1.1.1 then it compiles perfectly. 1.1.2 or the newer 2.0.0 both cause it to fail to compile for some reason. Does anyone know how to update this library to the modern age?

icmp ping and ethernet 2.0 doesn't work

Hi
Unfortunately, this library is not compatible with ethernet 2.0
I scour the whole network for a solution
I really need icmpping and ethernet 2.0
I've already addressed to the arduino forum

I hope there is someone who knows a solution

Many thanks in advance

Error while compiling

Got this error when compiling. I just recently download the master. Thanks

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\ABC\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp: In member function 'Status ICMPPing::sendEchoRequest(const IPAddress&, const ICMPEcho&)':

C:\Users\ABC\Documents\Arduino\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:\Users\ABC\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp: In member function 'void ICMPPing::receiveEchoReply(const ICMPEcho&, const IPAddress&, ICMPEchoReply&)':

C:\Users\ABC\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp:207:19: error: 'class W5100Class' has no member named 'getRXReceivedSize'

         if (W5100.getRXReceivedSize(_socket) < 1)

                   ^

C:\Users\ABC\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp:219:9: error: 'class W5100Class' has no member named 'read_data'

   W5100.read_data(_socket, (uint16_t) buffer, ipHeader, sizeof(ipHeader));

         ^

C:\Users\ABC\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp:229:9: error: 'class W5100Class' has no member named 'read_data'

   W5100.read_data(_socket, (uint16_t) buffer, serialized, dataLen);

         ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Ping from a webserver

Nice work here! Thanks!

My purpose is to build a little webserver in a box. I will put a led outside to indicate the whether network is on (connected). So I ping the gateway eache 5 secs to set the led.

The problem is, as soon as the server starts to receive HTTP requests, it doesn't ping the gateway anymore, I mean does not receive SUCCESS status. Could be a socket issue?

Any thoughts? Thanks in advance.

BTW, a changed pingSocket from 0 to 3 but it didn't work.

Keep up the good work!

Impossible to compile

I'm using the arduino IDE in 1.8.5.
When I'm trying to compile, I get an error from the line 12 in ICMPPing.h

/home/altf4/Arduino/libraries/icmp_ping/ICMPPing.h:12:27: fatal error: utility/w5100.h: No such file or directory
compilation terminated.

How am I supposed to solve that?

error compiling

C:\Users\63976\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp: In member function 'Status ICMPPing::sendEchoRequest(const IPAddress&, const ICMPEcho&)':
C:\Users\63976\Documents\Arduino\libraries\icmp_ping\ICMPPing.cpp:184:11: error: 'class W5100Class' has no member named 'send_data_processing'
184 | W5100.send_data_processing(_socket, serialized, sizeof(ICMPEcho));

problem during compilation util.h no such file or directory

hello
I want to use an arduino uno plus ethernet shied to command a relay to work as a watchdog for an adsl modem . so I intend to ping a known IP and reboot in case of freeze.
the sketch is ๐Ÿ‘

/*
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>

define relaypin 13

int JFP=0;

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);
JFP=0;
  }
  else
  {
++ JFP;
    sprintf(buffer, "Echo request failed; %d", echoReply.status);

if (JFP== 3)
{ 
digitalWrite  (relaypin , HIGH);
delay (2000);
digitalWrite  (relaypin , LOW);
JFP=0;
}
}
  Serial.println(buffer);
  delay(500);
}

it is straight from the example

but i get an error during the compilation

C:\Program Files (x86)\Arduino\libraries\icmp_ping\ICMPPing.cpp:11:18: fatal error: util.h: No such file or directory
#include <util.h>

what dit i wrong ?
where is the util.h ?

thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.