Signori, avrei la necessità di dover pingare un indirizzo ip con il modulo W5100 su arduino mega 2560.
Con questo sketch di prova:
#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,1,177}; // ip address for ethernet shield
byte gateway[] = { 192, 168, 1, 253 }; //Manual setup only
byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
IPAddress pingAddr(173,194,112,120); // 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, subnet);
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);
}
Non riesco a pingare gli indirizzi esterni (tipo 173.194.112.120) che vanno in timeout. Pingo solo indirizzi interni alla lan, tipo 192.168.1.2.
Ovviamente lo stesso indirizzo ip, dal prompt dei comandi riesco a pingarlo benissimo.
Cosa sbaglio?