Pages: [1]   Go Down
Author Topic: Quick Udp packets sending  (Read 326 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I currently have a arduino due with ethernet shield(w5100 chip) and i am trying to read packets and send acknowledgement packets, however i need this to work at 0.5 ms which i have not been able to do with this set up.

my question is would
http://www.elecrow.com/w5200-ethernet-shield-p-367.html

or http://www.hobbytronics.co.uk/wiznet-wiz820io?utm_source=google&utm_medium=googleshopping&utm_campaign=googlebase&gclid=CM_OyqXrisACFY7KtAodaykAKw

be quick enough  to handle this much data, with the w5200, because i think either the Rx/Tx buffer is not quick enough or the spi limitations is slowing my program down?

or would a netduino be better?

thanks a million

manewc


(my code if your interested),

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

EthernetUDP udp;
EthernetClient client;
byte sentAck[28];
char msg[76];

void setup()
{
  pinMode(4, OUTPUT); //disable sd card
  digitalWrite(4, HIGH);
 
  Serial.begin(57600);
  uint8_t mac[6] = {0x90,0xA2,0xDA,0x00,0xFA,0x7D};

  Ethernet.begin(mac);
  udp.begin(18005);//listener port

  Serial.print("localIP: ");
  Serial.println(Ethernet.localIP());
}

void loop()
{
  //check for new udp-packet:
  int size = udp.parsePacket();
  if (size > 0 )
  {
    udp.read(msg, size);
    udp.beginPacket(IPAddress(MY IP), 18006);   
    udp.write(sentAck, 28);   
    udp.endPacket();
  }
  udp.beginPacket(IPAddress(MY IP), 18008);
  udp.write(sentAck, 28);
  udp.endPacket();
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can always try to speed up the SPI bus. That might help. The standard speed is 4 MHz, and I think the w5100 can handle 12MHz. The Due should be able to handle the extra speed.
http://arduino.cc/en/Reference/SPISetClockDivider
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I should have mentioned i am already running the spi at 14MHz, which the library suggest it can handle.

which at 1ms still misses a few packets (20 or something, which unfortunately isn't good enough for what i want it to do)

hence i think my only option is to upgrade my hardware.

thanks for the help once again tho Surfer Tim, much appreciated.

manewc
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good luck with that project. Let us know if you can send faster than 1ms per packet, and what hardware you needed.

What device is on the receiving end? Anything else on the network that would cause enough traffic to block the UDP packet send? Wireshark might help with that determination.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The plan is for all of this to be on local network, so packet loss should be minimal

the device on the end is a raspberry pi, but atm to test i am sending packets to my computer.

In all of these test i have wireshark open (lifesaver program) to compare numbers with packets sent and packets wireshark has seen.


thanks

manewc
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you aware that UDP.endPacket() call returns a value? You might want to evaluate the return value to see if the RPi is rejecting the packet. It returns 1 if the packet was accepted, and 0 if rejected.

It isn't in the reference, but it is documented in EthernetUdp.h.

Just a thought...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

aye  another problem i am having which u have helped me with on another topic is the packets freezing after quite a few have been sent it seems the udp.write function write the function happens and udp.endpacket either doesnt get called, or it gets stuck in the while loop in the library because when it freeze it doesnt return anything it just seems to stop.

http://forum.arduino.cc/index.php?topic=259011.0

if the raspberrypi misses the packets, this is not an issue i just need to be able to send/acknowledge them quick enough. I am also not using a raspberry pi just yet, currently sending them to my computer.

thanks

manewc

here is code i used to debug
Code:
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>

EthernetUDP udp;
EthernetClient client;
byte sentAck[28];
char msg[76];

void setup()
{
  pinMode(4, OUTPUT); //disable sd card
  digitalWrite(4, HIGH);
 
  Serial.begin(57600);
  uint8_t mac[6] = {0x90,0xA2,0xDA,0x00,0xFA,0x7D};

  Ethernet.begin(mac);
  udp.begin(18005);//listener port

  Serial.print("localIP: ");
  Serial.println(Ethernet.localIP());
}

void loop()
{
  //check for new udp-packet:
  int size = udp.parsePacket();
  if (size > 0 )
  {
    udp.read(msg, size);
    udp.beginPacket(IPAddress(10, 234, 188, 254), 18006);   
    Serial.println(udp.write(sentAck, 28));   
    Serial.println(udp.endPacket());
    Serial.println(2);
  }
  udp.beginPacket(IPAddress(10, 234, 188, 254), 18007);
  Serial.println(udp.write(sentAck, 28));
  Serial.println(udp.endPacket());
  Serial.println(4);
}
Logged

Pages: [1]   Go Up
Jump to: