ICMPPing versus EthernetUdp

Hello

My system : Arduino Ethernet.
My IDE version : 1:1.0.5+dfsg2-2

The problem:

My program:

I have removed all unnecessary lines.

LOOP
Get the time from a timeserver.
Do it a second time.
Then ping a other server.

After the ping routine I get a SUCCES back. That works.
Continue the program it stops on the line:

Serial.println(" end write “);
** Udp.endPacket();**
Serial.println(” sendNTPpacket return");
The printlines are for debug reason.

My output on the monitor:

QUOTE
LOOP
counter = 1
enter sendNTPpacket 132.163.4.101
start NTP: write packetBuffer,NTP_PACKET_SIZE
end write
sendNTPpacket return
time server return
Udp
The UTC time is 1427644102
LOOP
counter = 2
enter sendNTPpacket 132.163.4.101
start NTP: write packetBuffer,NTP_PACKET_SIZE
end write
sendNTPpacket return
time server return
Udp
The UTC time is 1427644113
LOOP
counter = 3
ICMPEchoReply = 192.168.178.200
ICMPEchoReply = SUCCESS
wait 10 sec
go on
enter sendNTPpacket 132.163.4.101
start NTP: write packetBuffer,NTP_PACKET_SIZE
end write
UNQUOTE

After the line “end write” nothing happens anymore.

So, What went wrong. How to solve it.

Many thanks for your time.
Have a nice day

NTP_Ping_test.ino.txt (4.61 KB)

I have never used the ICMPPing library. You may have a conflict between the udp sends. Add this function to your sketch and call this before and after the ping. Insure all is ok with your sockets.

#include <utility/w5100.h>

byte socketStat[MAX_SOCK_NUM];

void ShowSockStatus()
{
  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    Serial.print(F("Socket#"));
    Serial.print(i);
    uint8_t s = W5100.readSnSR(i);
    socketStat[i] = s;
    Serial.print(F(":0x"));
    Serial.print(s,16);
    Serial.print(F(" "));
    Serial.print(W5100.readSnPORT(i));
    Serial.print(F(" D:"));
    uint8_t dip[4];
    W5100.readSnDIPR(i, dip);
    for (int j=0; j<4; j++) {
      Serial.print(dip[j],10);
      if (j<3) Serial.print(".");
    }
    Serial.print(F("("));
    Serial.print(W5100.readSnDPORT(i));
    Serial.println(F(")"));
  }
}

The status codes:
0x0 = available
0x14 = tcp socket waiting for a connection
0x17 = tcp socket connected
0x1C = tcp socket connected waiting for close
0x22 = udp

Hallo Tim.

Thanks for the reply.
I made thwe change, results:

QUOTE
counter = 1
enter sendNTPpacket 132.163.4.101
start NTP: write packetBuffer,NTP_PACKET_SIZE
end write
sendNTPpacket return
time server return
Udp
The UTC time is 1427725721
LOOP
counter = 2
SockStatus 1
Socket#0:0x22 8888 D:132.163.4.101(123)
Socket#1:0x0 0 D:0.0.0.0(0)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
SockStatus 2
Socket#0:0x0 0 D:192.168.178.200(0)
Socket#1:0x0 0 D:0.0.0.0(0)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
ICMPEchoReply = 192.168.178.200
ICMPEchoReply = SUCCESS
wait 10 sec
go on
enter sendNTPpacket 132.163.4.101
start NTP: write packetBuffer,NTP_PACKET_SIZE
end write

UNQUOTE

I think I solved it.

The UDP routine uses socket 0.

The ping routine uses also socket 0.

I changed the line 14(SOCKET pingSocket = 0;)
into
SOCKET pingSocket = 2;

Now it loops.
Now testing the compleet program

Manny thanks for your help.

Henk

That seems odd that the code doesn't check that socket 0 is being used. It should pick an unused socket. Just a thought, but what if you had a web server running on socket 0? I wonder if it would stop the server?

edit: Where did you get the ICMPPing library? I would like to test it.