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.
Here goes:
Getting the WifiShield to work with UDP.
My setup:
Mac OSX 10.8.3
Arduino UNO
Arduino 1.0.4
WifiShield R3 with HDG104 chip and 32UC3
These are the step:
1. Download and put everything in it's right place.
WIFI_FW_PATH="/hardware/arduino/firmwares/wifi-shield/"
to
WIFI_FW_PATH="/hardware/arduino/firmwares/wifishield/"
2. Update the shield
- remove the WifiShield from the Arduino.
- connect the jumper.
- connect the WifiShield with the mini USB connector to your computer
- open Terminal.app and type
sudo sh /Applications/Arduino_104_UDP.app/Contents/Resources/Java/hardware/arduino/firmwares/wifishield/scripts/ArduinoWifiShield_upgrade.sh -a"/Applications/Arduino_104_UDP.app/Contents/Resources/Java" -f shield
it will ask for your password.
type it and press enter.
This will appear:
Arduino WiFi Shield upgrade
=========================================
Instructions:
To access to the USB devices correctly, the dfu-programmer needs to have the root permissions.
You can upgrade the firmware of the antenna togheter with the shield firmware or only the shield firmware
if there aren't changes on the antenna firmware.
Use the '-h' parameter for help
=========================================
./avr-objcopy: '/Applications/Arduino_104_UDP.app/Contents/Resources/Java/hardware/arduino/firmwares/wifishield/wifi_dnld.elf': No such file
****Upgrade WiFi Shield firmware****
Validating...
261594 bytes used (103.01%)
Done. Remove the J3 jumper and press the RESET button on the shield.
Thank you!
- Remove the J3 jumper and press RESET.
- close terminal, you're done here.
3. Testing and keeping your fingers crossed.
*Open the Arduino_104_UDP.app and copy paste this code in a fresh sketch:
(do not forget to change the code for your network settings)
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
int status = WL_IDLE_STATUS;
char ssid[] = "NETWORKNAME"; // your network SSID (name) Your network name here, case sensitive!
char pass[] = "PASSWORD"; // if your network doesn't use WPA or WEP, change the line below that says "status = WiFi.begin(ssid, pass);"
unsigned int localPort = 2390; // local port to listen on
char packetBuffer[255]; //buffer to hold incoming packet
char ReplyBuffer[] = "acknowledged"; // a string to send back
WiFiUDP Udp;
int counter = 0;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
Serial.println("WifiUdpSendReceiveString");
// make a little light show on the WifiShield
pinMode(9, OUTPUT);
for(int i = 0; i < 50; i++){
digitalWrite(9, HIGH);
delay(i);
digitalWrite(9, LOW);
delay(i);
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
Serial.println("Wifi Shield present");
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
int len = Udp.read(packetBuffer,255);
if (len >0) packetBuffer[len]=0;
Serial.println("Contents:");
Serial.println(packetBuffer);
// 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");
}
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}