UDP initialization

Questions specifically related to the TCP/IP stack that interfaces with the driver.

Re: UDP initialization

Postby GregEigsti » Sun Oct 25, 2009 10:33 am

Ok, I have a potential workaround. Its not perfect IMO but it works for me. IMO the UDP stuff in the uIP stack is pretty weird - but I'm probably not understanding.

So in the udpapp_init() function you call uip_udp_new() and provide it with the remote client's address. This means that your Arduino/WiShield must know beforehand the IP address of the single machine/device that will connect to it via UDP. Thats pretty limiting and will break in a DHCP environment where the connecting client's IP address could change.

The workaround is to use an IP address of 255.255.255.255 in the call to uip_udp_new(). This allows, or should allow, any client device/machine to connect to the Arduino/WiShield regardless of its IP address and allows the UDP sample sketch + PC code to work (on the first time and every time as far as I saw). The unintended side effect here is that your Arduino/WiShield is now sending broadcast UDP packets (I think this addr sets broadcast). Maybe not a problem unless you have some other device on your network sitting out there listening on that port for broadcast UDP packets. WireShark tells me that port 12345, which the Arduino/WiShield is broadcasting on in my setup, is a known port for "italk" (italk appears to be a chat service). So use at your own risk (or find some unused ports!)

I chased this down through the WiServer and uIP code and stopped when I got into the ZeroG driver code. WiServer/uIP code appear to be working correctly but the send seems to be getting dropped somewhere in the ZeroG driver. I don't really know, this is just a guess based upon some simple debugging...

Original udpapp_init() from the UDPApp sample
Code: Select all
void udpapp_init(void)
{
   uip_ipaddr_t addr;
   struct uip_udp_conn *c;

   uip_ipaddr(&addr, 192,168,1,100);
   c = uip_udp_new(&addr, HTONS(0));
   if(c != NULL) {
      uip_udp_bind(c, HTONS(12344));
   }

   s.state = STATE_INIT;

   PT_INIT(&s.pt);
}


Updated udpapp_init() that seems to work (but broadcasts)
Code: Select all
void udpapp_init(void)
{
   uip_ipaddr_t addr;
   struct uip_udp_conn *c;

   //uip_ipaddr(&addr, 192,168,1,100);
   uip_ipaddr(&addr, 255,255,255,255);
   c = uip_udp_new(&addr, HTONS(0));
   if(c != NULL) {
      uip_udp_bind(c, HTONS(12344));
   }

   s.state = STATE_INIT;

   PT_INIT(&s.pt);
}


IMO one of the only reasons to use UDP is for broadcast (as well as fast connectionless unack'ed packets). Maybe TCP sockets would work for you as they seem a little more usable/stable?

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: UDP initialization

Postby emblem » Sun Oct 25, 2009 4:49 pm

Thanks for the suggestions, I will try this and let you know how it works. I actually am using UDP for the broadcast ability, so this change is basically the next step for me anyway.
emblem
 
Posts: 7
Joined: Sat Oct 24, 2009 6:31 pm

Previous

Return to TCP/IP Stack

Who is online

Users browsing this forum: No registered users and 1 guest