UDPApp out of the box

Discussion about any of the included sketches (i.e. WebServer), or user-generated applications.

UDPApp out of the box

Postby seanblink » Mon May 24, 2010 7:01 am

Has anyone had success in running the UDPApp sketch on a WLAN right out of the box? I compiled the udp_endp.c example on Ubuntu. The only change to code I made was the destination IP address (192.168.1.111), and I included unistd.h to enable the close(socket) command. On the sketch side, I likewise changed the local_ip[] variable to 192.168.1.111 as well as the IP address in the init function of udpapp.c.

After all this has been done, I am able to ping the board from the udp client computer, but when it sends "Hello", it receives no response from the Yellowjacket.

Short of tracing the problem through all the WiShield code (my task for tonight), can anyone suggest solutions?

Thanks!
seanblink
 
Posts: 10
Joined: Sat May 22, 2010 6:55 pm

Re: UDPApp out of the box

Postby seanblink » Mon May 24, 2010 1:40 pm

Here's a clue: I hooked an LED up to pin 10. It blinks whenever I attempt to send a packet to the board. However, nothing in udpapp.c indicates that I'm receiving anything.
seanblink
 
Posts: 10
Joined: Sat May 22, 2010 6:55 pm

Re: UDPApp out of the box

Postby GregEigsti » Mon May 24, 2010 3:44 pm

The UDP sample sketch as well as the PC sample code works fine for me (have tried the PC side code on Ubuntu and MacOS). Its always helpful to post your code for others to look at and potentially try. ;) There are a bunch of troubleshooting steps but I am thinking that your use of digital pin 10 for the LED is trashing the SPI connection. Does the sample code work for you without the LED attached?

So here we go into assumptions and guesses ;) I took a look at the poorly documented YJ page on the wiki and compared it to the more better documented wiki page for the Wishield 1.0 - my guess/assumption is that the pinouts are the same for the two. If you look at the WiShield 1.0 wiki page you will see that the SPI interface uses digital pins 10-13 (and digital pins 2 OR 8 for the interrupt - and potentially digital pin 9 for the connection LED). Assuming the same is true for the YJ then these pins should not be used for anything else (e.g. an LED connection). If you look at the YJ wiki page "pinout jpg" you will see that pin 13 is marked "SPI" so am thinking that my assumptions are correct - but they may not be...

Please give your setup a try without the LED connected to see if it all works; once you determine that a "baseline" setup works then you can introduce "variables" one at a time (e.g. LED connection) to see where things "go off of the tracks". Once you prove that things are working without the LED then you can try connecting the LED to a pin other than 10-13 and 2/9. FYI the YJ is not switchable between digital pin 2/8 for the interrupt - it is hardwired to use pin 2. I am not sure if the YJ "connection LED" on pin 9 can be "disconnected' to regain the use of pin 9 - disconnecting the connection LED is something that I would do only as a last resort as it is awfully darned handy to be able to look at it for an instant/easy indication of your connection status.

What is your intended use for the LED that you are connecting? To see blinky status when SPI activity is present or as an indicator of some other program state?

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: UDPApp out of the box

Postby seanblink » Mon May 24, 2010 9:08 pm

Greg, thanks for all the great responses.

I'm stumped on this one. Here are the steps I took since your post:
    * Removed LED from the board
    * Reinstalled all Arduino libs.
    * Changed the two *.h files according to the wiki
    * Altered the essid in the UDPApp sketch from "ASYNCLABS" to "dlink" to match my router's name. Everything else is exactly the same. Uploaded this to the board.
    * Ping the board at 192.168.1.2. it works.
    * Altered the sample endpoint app from the wiki by adding #include <unistd.h>. I believe it needs this to compile.
    * Tried a sample UDP client/server suite of applications between a Windows box and a Linux box both on my LAN, to ensure that the router is not blocking anything.
    * Run the UDP endpoint program from an Ubuntu machine. It prints "Hello", but gets no return from the Yellowjacket.


One other things to note: I tried running the sample posted at viewtopic.php?f=15&t=305&p=1816&hilit=iphone#p1816 . In it, neufuture inserts some Serial print statements to print the output of the Yellowjacket board. When I ran this, again, I didn't see the messages I was sending. However, the board was spamming the serial monitor with the letter 'u' whenever I was connected in infrastructure mode and the letter 'w' whenever I was connected in ad-hoc mode.
Last edited by seanblink on Mon May 24, 2010 9:39 pm, edited 1 time in total.
seanblink
 
Posts: 10
Joined: Sat May 22, 2010 6:55 pm

Re: UDPApp out of the box

Postby John_Ryan » Mon May 24, 2010 9:16 pm

seanblink wrote:However, the board was spamming the serial monitor with the letter 'u' whenever I was connected in infrastructure mode and the letter 'w' whenever I was connected in ad-hoc mode.


Perhaps check the baud rate of the monitor is the same as the controller, I'm sure you have but I've missed that one a couple of times myself and wondered what the junk was in the monitor window = )
John_Ryan
 
Posts: 155
Joined: Thu Jun 04, 2009 11:24 pm

Re: UDPApp out of the box

Postby seanblink » Mon May 24, 2010 9:38 pm

Perhaps check the baud rate of the monitor is the same as the controller...


It looks like 'u' and 'w' were just the initial character that was randomly picked up. The code merely repeated that first character over and over. The baud rate is correct.

Somehow, the board is just not receiving new data.
seanblink
 
Posts: 10
Joined: Sat May 22, 2010 6:55 pm

Re: UDPApp out of the box

Postby seanblink » Tue May 25, 2010 9:46 pm

I tried the SocketApp, SimpleServer, and WebServer sketches on the Yellowjacket. They all work fine, with one exception-- the LED toggle button on the WebServer example causes the LED to blink briefly and throws an error on the webpage.

I tried increasing the max UDP connections in uip-conf.h to 10. That didn't work. I don't know what else to try with this. Is it possible my hardware is bunk?
seanblink
 
Posts: 10
Joined: Sat May 22, 2010 6:55 pm

Re: UDPApp out of the box

Postby GregEigsti » Tue May 25, 2010 10:23 pm

I was going to suggest trying the other samples; its a good datapoint. Thanks for trying and sharing the results.
the LED toggle button on the WebServer example causes the LED to blink briefly and throws an error on the webpage.

I think this sample sketch is busted; at least it errored out for me as well (and if you search the forums I think there are others who have complained about the same issue).

If all the other samples (TCP, WiServer, etc.) work then I doubt its a hardware issue - likely a configuration issue. After looking back through this thread it appears that you are sending the UDP data to an address (rather than broadcast) - is this correct?

Gimme a bit and I'll try to pull together a couple bits of sample UDP code for Ubuntu and the WiShield (which work for me).

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: UDPApp out of the box

Postby GregEigsti » Wed May 26, 2010 12:33 am

Ok, here are a couple of UDP sample apps; one a sketch for the Arduino/WiShield/etc. and the other for Ubuntu - the Arduino sketch transmits and the Ubuntu code receives. You'll need to modify the Arduino sketch with your particular IPs, SSID, security settings, etc. I'll leave the modifications necessary to send/receive data in both directions as an exercise for you. ;) Before you start modifying the code, other than the necessary bits to get it working for you, give it a try to see if it works for you...

This code works for me - it might not be the most bestest code ever but I threw it together pretty quickly. :roll:

udpsample.pde sketch
Code: Select all
/*
* UDP endpoint
*
* A simple UDP endpoint example using the WiShield 1.0
*/

extern "C" {
   #include "uip.h"
}
#include <WiShield.h>

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[]       = {192, 168, 1, 20};  // IP address of WiShield
unsigned char gateway_ip[]     = {192, 168, 1, 1};   // router or gateway IP address
unsigned char subnet_mask[]    = {255, 255, 255, 0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"};       // max 32 bytes

unsigned char security_type = 0;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};   // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

void setup()
{
   Serial.begin(57600);
   WiFi.init();
}

void loop()
{
   WiFi.run();
}

extern "C"
{
   void udpapp_init(void)
   {
      uip_ipaddr_t addr;
      struct uip_udp_conn *c;
   
      //address of Ubuntu box (or send to address)
      uip_ipaddr(&addr, 192, 168, 1, 122);
      c = uip_udp_new(&addr, HTONS(1234));
      if(c != NULL) {
         uip_udp_bind(c, HTONS(1234));
      }
   }

   static void send_data(void)
   {
      Serial.println("udpsample: sending data...");
      char str[] = "udpsample: this is some UDP data...";
      memcpy(uip_appdata, str, strlen(str));
      uip_send(uip_appdata, strlen(str));
   }

   void udpapp_appcall(void)
   {
      if(0 != uip_poll()) {
         send_data();
      }
   }   

   void dummy_app_appcall(void)
   {
   }   
}


Ubuntu UDP sample app
Code: Select all
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>

#define PACKET_SIZE 128

int openListener(uint16_t port)
{
   int s;
   struct sockaddr_in server;
   socklen_t namelen = sizeof(server);
   
   s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
   if(-1 == s) {
      printf("ERROR: creating socket\n");
      return 0;
   }
      
   memset(&server, 0, sizeof(server));
   server.sin_family = AF_INET;
   server.sin_addr.s_addr = htonl(INADDR_ANY);
   server.sin_port = htons(port);

      if(-1 == bind(s, (struct sockaddr *)&server, namelen)) {
      printf("ERROR: bind socket\n");
      close(s);
      s = -1;
   }

   return s;
}

void closeListener(int s)
{
   close(s);
}

void readListener(int s)
{
   int count;
   int retval;
   char *ptime;
   time_t ltime;
   unsigned char data[PACKET_SIZE];
   
   count = 0;
   while(1) {
      memset(data, 0 , PACKET_SIZE);

      retval = recv(s, data, PACKET_SIZE, 0); 
      if(-1 == retval) {
         printf("WARNING: recv failed\n");
         continue;
      }
      
      if(0 == retval) {
         printf("WARNING: server closed connection\n");
         continue;
      }

      ltime = time(NULL);
      ptime = asctime(localtime(<ime));
      ptime[strlen(ptime)-1] = '\0';
      printf("%s %d [size %02d]: %s\n", ptime, ++count, retval, data);
   }
}

int main(int argc, const char * argv[])
{
   int s;
   
   printf("udpapp opening port 1234 to receive UDP data\n");
   
   //open the UDP socket on the given port to listen for UDP data
   s = openListener(1234);
   if(-1 == s) {
      printf("ERROR: opening port 1234\n");
      return 1;
   }
   
   //listen for data...
   readListener(s);
   
   //close the UDP listenener socket
   closeListener(s);
   
   return 0;
}


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: UDPApp out of the box

Postby seanblink » Wed May 26, 2010 4:29 pm

That worked!

I don't suppose you have one that tests UDP packets in the other direction?

I can only draw from this data point that UDP sending works. As for potential problems remaining... Perhaps there's something wrong with the latest in WiShield UDP code? The packets to the board are not being routed TO the board correctly? An interesting point to note: my router doesn't list the Yellowjacket as having an IP address. It comes up as 0.0.0.0. Could this be the problem? I am going to try the original example, but I'm going to send the packets to 192.168.1.255.

Thanks,
Sean
seanblink
 
Posts: 10
Joined: Sat May 22, 2010 6:55 pm

Next

Return to Sketches and Applications

Who is online

Users browsing this forum: No registered users and 2 guests

cron