Go Down

Topic: UDP packets fail to be sent. UDP collisions? (Read 1 time) previous topic - next topic

alexyoung91

I have recent bought an Ethernet Shield for the arduino for use in a renewable energy project. I have written a small test sketch which every 200 milliseconds sends a number which is incremented at the end of each loop. The problem I'm having is that sometimes (seeemly completely random) the packets will not send. I dont just mean missing a few i mean after one reset each one will send fine but then another time the USB cable is plugged in they wont send at all. I was wondering if some collisions or something is taking place. When theyre not sending a green LED marked 'L' on the shield comes on, but this can even happen when the ethernet cable is not plugged in. Is it a code error or a hardware error?

http://i.ebayimg.com/00/s/NjAwWDYwMA==/$(KGrHqN,!qsE88gcHj3HBPTfK+uBcQ~~60_12.JPG

The above link is a photo of the shield I bought its the top LED in the row of four marked 'L' that lights up when the loops fail to send UDP packets

Code: [Select]

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 126);
unsigned int port = 12668;
EthernetUDP Udp;

IPAddress client(192, 168, 1, 9);

int i = 0;

void setup()
{
    pinMode(10, OUTPUT);
   
    Ethernet.begin(mac, ip);
    Udp.begin(port);
    delay(1000);
}

void loop()
{
    char holder[8];
    memset(holder, 0, sizeof(holder));
    itoa(i, holder, 10);
   
    Udp.beginPacket(client, port);
    Udp.write(holder);
    Udp.endPacket();
   
    delay(200);
   
    i++;
}

SurferTim

Do you have a microSD card in the slot? That will cause UDP fails if not disabled or initialized.

pylon

You'd better linked to a datasheet than to just a picture. From what I see on the picture I guess that the 'L' means link detected. This is not switched by software but by the chip itself. In my experience a failing link often means cabling problems. Replace your network cable (take a cat 5 to stay on the save side) and try again. What does the other side of the network cable (probably a switch) mean? Is the link going down there too?

alexyoung91

@SurferTim

I do have an microSD in the slot, if i remove that will that stop the problem? I'll give it a try.

@pylon

'L' is not link on this board, thats at the other side of the RJ45 socket and that lights up fine. The problem even persists when theres no cable plugged in. I noticed on this board there is no collision LED and wondered if that's what the LED represented?

SurferTim

#4
Jun 15, 2012, 04:57 pm Last Edit: Jun 15, 2012, 05:06 pm by SurferTim Reason: 1
Yes, removing it will stop the fail, but I like to get stuff set up correctly the first time. Just disable it for now.
Code: [Select]
void setup()
{
  // disable the microSD card SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // now do your ethernet setup stuff
}


edit: The 'L' led is connected to the SPI clock pin. When you have the microSD card in the slot, that is the SD card stepping all over your w5100/w5200 UDP send. Mine glows dim with the microSD card in the slot and not disabled.

alexyoung91

#5
Jun 15, 2012, 05:08 pm Last Edit: Jun 15, 2012, 05:19 pm by alexyoung91 Reason: 1
I tried removing the SD card and changing the code to the following, but i still do not get UDP packets sent. Is there something else I'm missing?

Code: [Select]

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 126);
unsigned int port = 12668;
EthernetUDP Udp;

IPAddress client(192, 168, 1, 9);

int i = 0;

void setup()
{
   pinMode(4, OUTPUT);
   digitalWrite(4, HIGH);
   
   Ethernet.begin(mac, ip);
   Udp.begin(port);
   delay(1000);
}

void loop()
{
   char holder[8];
   memset(holder, 0, sizeof(holder));
   itoa(i, holder, 10);
   
   Udp.beginPacket(client, port);
   Udp.write(holder);
   Udp.endPacket();
   
   delay(100);
   
   i++;
}


The 'L' LED is still lit up bright green. I understand what you mean by it glowing dim because on the occasion that the packets are sent out, i get the same.

SurferTim

Is the other localnet ip (192.168.1.9) a computer?
If so, can you ping 192.168.1.126 from it?

alexyoung91

I used the command prompt and typed ping 192.168.1.126 and i got the following:

Pinging 192.168.1.126 with 32 bytes of data:
Reply from 192.168.1.126: bytes=32 time=11ms TTL=128
Reply from 192.168.1.126: bytes=32 time=7ms TTL=128
Request timed out.
Reply from 192.168.1.126: bytes=32 time=3ms TTL=128

Ping statistics for 192.168.1.126:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 3ms, Maximum = 11ms, Average = 7ms

Then the green LED went dim and it started working :S I got this ping response:

Pinging 192.168.1.126 with 32 bytes of data:
Reply from 192.168.1.126: bytes=32 time=3ms TTL=128
Reply from 192.168.1.126: bytes=32 time=4ms TTL=128
Reply from 192.168.1.126: bytes=32 time=4ms TTL=128
Reply from 192.168.1.126: bytes=32 time=6ms TTL=128

Ping statistics for 192.168.1.126:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 3ms, Maximum = 6ms, Average = 4ms

alexyoung91

#8
Jun 15, 2012, 06:03 pm Last Edit: Jun 15, 2012, 06:06 pm by alexyoung91 Reason: 1
It can even send UDP data for about 10 minutes and then the 'L' LED comes on again and it will stop sending and vice versa. I wish i had a solution. It's very random when it works and i can't seem to change it. I wonder if its a problem with the shield?

It seems to be fine always receiving UDP packets.

SurferTim

Is it the time or the number of iterations that cause the fail? If you double the time between sends, does the time before fail double also? Or does it fail about the same time?


Go Up