logotype

Would also love to see proper UDP support for this official WiFi shield.I also have a Linksprite WiShield 2.0 (Asynclabs compatible), UDP works fine there, but the library is a complete mess and not fun to work with.

Answering my own questions here in the hope to help others that read this thread.

I noticed that there is a dev_udp branch over at https://github.com/arduino/wifishield which I can confirm works very well with UDP. It will require that you update the firmware on your wifi shield and replace the library ( this includes a new example WifiUdpSendReceiveString ) in your arduino ide installation but nothing overly difficult.

Hope this helps,

Regards,

jfrmilner

timKnapen

I'm glad someone is able to get this to work.I have been trying like mad to get this to work with the udp_dev branch but had no luck. I'm fairly experienced with UDP on OSX and iOS and win but for some reason I can't get the bloody arduino to play nice...

timKnapen

hello All, I have been in contact with mlafauci on Github, who seems to be in charge of fixing the WifiShield firmware and library. He posted an update to the firmware and library that works with UDP!!! Because I struggled so much with this thing I'm going to post a complete write-up of every little step needed to get an UDP example working.

// send a reply, to the IP address and port that sent us the packet we received Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); Udp.write(ReplyBuffer); Udp.endPacket(); } else{// this will show you that the sketch is actually running and not crashing// remove this, it's useless. counter ++; if(counter%2000 == 0){ Serial.println("no packet"); } }}

* upload it to your Arduino UNO * connect the wifiShield if you haven't yet.* open the Serial Monitor to the Arduino, it will tell you the IP of your wifishield when it connects to the network.* open a UDP program and make it send a UDP message to the IP you just got from your Arduino and the port 2390. If you are into C++ you can quickly use this OpenFrameworks example: https://github.com/openframeworks/openFrameworks/tree/master/examples/addons/networkUdpSenderExampleif you are into Obj-C and Cocoa, there's the very nice CocoaAsyncSocket class with ready to compile UDP examples. (I use these for testing) https://github.com/robbiehanson/CocoaAsyncSocket* See the Arduino receive your message in the Serial Monitor.* smile.

jimunkim

IMPORTANT1. do not use/download wrong files wifiHD.elf(50KB) and wifiHD.hex(2,002KB) directly from (https://github.com/mlafauci/Arduino/tree/wifishield-bugfix/hardware/arduino/firmwares/wifishield/wifiHD/Release)

2. Do download a whole Arduino-wifishield-bugfix.zip(230MB) file from (https://github.com/mlafauci/Arduino/tree/wifishield-bugfix), then use those firmware binary files; wifiHD.elf (708KB) and wifiHD.hex(703KB)

Somehow those two files are different within .zip and the github raw code. This is the reason for the parsing error is occurred, every time when I parse the .hex to compile on the AT32UC3A1512 chip, because I used wrong files.

Cheers, Arduino! Cheers, developers!

timKnapen

Why do you think the files on github are different from the ones compiled into the ZIP? I think they are not. If you download the RAW version from the github page and compare then to the ones in the ZIP, you will find they are exactly the same. I just tested them both with FileMerge.

/* Set this to the offset (in seconds) to your local time This example is GMT + 2 */const long timeZoneOffset = 7200L;

/* Syncs to NTP server every 15 seconds for testing, set to 1 hour or more to be reasonable */unsigned int ntpSyncTime = 15;

/* ALTER THESE VARIABLES AT YOUR OWN RISK */// local port to listen for UDP packetsunsigned int localPort = 8888;// NTP time stamp is in the first 48 bytes of the messageconst int NTP_PACKET_SIZE= 48; // Buffer to hold incoming and outgoing packetsbyte packetBuffer[NTP_PACKET_SIZE]; // A UDP instance to let us send and receive packets over UDPWiFiUDP Udp; // Keeps track of how long ago we updated the NTP serverunsigned long ntpLastUpdate = 0; // Check last time clock displayed (Not in Production)time_t prevDisplay = 0;

// This is where all the magic happens...void loop() { // Update the time via NTP server as often as the time you set at the top if(now()-ntpLastUpdate > ntpSyncTime) { int trys=0; while(!getTimeAndDate() && trys<10){ trys++; } if(trys<10){ Serial.println("ntp server update success"); } else{ Serial.println("ntp server update failed"); } }

// Display the time if it has changed by more than a second. if( now() != prevDisplay){ prevDisplay = now(); clockDisplay(); }}

ohhopi

TimKnapen, I do not get any compilation errors ( lucky me ) but the program always prints "NTP server update failed" so I don't really know what's wrong ( the packets I'm sending, the way I'm sending them ...) :/

sketch_apr15a.ino:93: warning: this decimal constant is unsigned only in ISO C90sketch_apr15a:9: error: 'IPAddzress' was not declared in this scopesketch_apr15a:9: error: 'address' was not declared in this scopesketch_apr15a.ino: In function 'int getTimeAndDate()':sketch_apr15a:85: error: 'sendNTPpacket' cannot be used as a functionsketch_apr15a.ino: At global scope:sketch_apr15a:102: error: redefinition of 'long unsigned int sendNTPpacket'sketch_apr15a:9: error: 'long unsigned int sendNTPpacket' previously defined heresketch_apr15a:102: error: 'IPAddzress' was not declared in this scopesketch_apr15a:102: error: 'address' was not declared in this scope

best,tim.

srrichie

Hi Tim and thanks for your awesome work, I've just received my wifi shield today and I'm quite disappointed to find out that all the work done (based on UDP) it's not working Thanks God I've found this thread.Just a quick question: has the UDP packet some kind of size limit?I've followed your instructions, but I'm still not receiving the data I'm expecting....