Cannot set static IP with Arduino WiFi shield

Hey,

I’m trying to use an Arduino WiFi shield to send UDP packets containing EKG data to a computer using a WiFi USB adapter plugged into a desktop PC.

The way I envision this working is that when the Arduino receives a UDP packet from a program on the desktop PC (sent using the WiFi USB adapter), the Arduino program will parse the UDP packet for a remote IP address and port number. Next, the Arduino will send UDP packets to this remote IP Address and port number. I’m doing it this way because I’d like to be able to move this project to any computer, where any computer might have a separate IP address: just plug in the dongle, load the program on the desktop, and go.

However, to get this to work, the program on the desktop computer needs to know the IP address of the WiFi shield on the Arduino. So I thought I could use the WiFi.config() function to set the IP address, but it doesn’t seem to work. When I use the supplied ConnectNoEncryption example program, I get my local IP address to be 192.168.159.2. When using this example program, I tried adding a couple lines to set the IP address to 192.168.159.3, but when running it, it showed up as 192.168.159.2. Its the same for any number in the last octet.

Why would this happen?

This is the USB WiFi adapter I’m using: http://www.airlink101.com/products/awll5099.php

My modified example program is below.

#include <WiFi.h>

char ssid[] = "OPL_EKG";     // the name of your network
int status = WL_IDLE_STATUS;     // the Wifi radio's status
IPAddress arduinoIP(192,168,159,3);

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 
  
 // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to open SSID: ");
    Serial.println(ssid);
    WiFi.config(arduinoIP);
    status = WiFi.begin(ssid);

    // wait 10 seconds for connection:
    delay(5000);
  }
   
  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();
}

void loop() {
  // check the network connection once every 10 seconds:
  delay(10000);
  printCurrentNet();
}

void printWifiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);
  
  // print your MAC address:
  byte mac[6];  
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
  
  // print your subnet mask:
  IPAddress subnet = WiFi.subnetMask();
  Serial.print("NetMask: ");
  Serial.println(subnet);

  // print your gateway address:
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("Gateway: ");
  Serial.println(gateway);
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);    
  Serial.print("BSSID: ");
  Serial.print(bssid[5],HEX);
  Serial.print(":");
  Serial.print(bssid[4],HEX);
  Serial.print(":");
  Serial.print(bssid[3],HEX);
  Serial.print(":");
  Serial.print(bssid[2],HEX);
  Serial.print(":");
  Serial.print(bssid[1],HEX);
  Serial.print(":");
  Serial.println(bssid[0],HEX);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption,HEX);
}

Thank you all for your help!

A few more things I've tried since yesterday:

I tried running the WiFiUdpNtp client example program, but could never get any data returned. Upon closer inspection, the UDP.endPacket() command always returned 0, that is, it always fails, and no data gets sent.

I thought that maybe I needed to try updating the firmware on the shield, and followed the tutorial here: http://arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading. The tutorial says that I need to have the shield by itself when updating the firmware, however, due to the nature of my project, I have the ICSP header soldered to the arduino with wires. So I clipped the VCC wire only, removed the shield from the arduino, and tried to do the update, but upon typing

batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer /Arduino/hardware/arduino/firmware/wifishield/binary/wifi_dnld.elf program verify start reset 0

into the command line, I got an error that said the USB device could not be opened. I checked the device manager, and sure enough, there was no USB device detected.

I reconnected VCC, and ran the command, and then it worked. My concern with this is that because I had to have the ICSP header connected to the arduino, this firmware update might not work. Is this concern valid?

Another concern is when I entered both

batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer /Arduino/hardware/arduino/firmware/wifishield/binary/wifi_dnld.elf program verify start reset 0

and

batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer /Arduino/hardware/arduino/firmware/wifishield/binary/wifiHD.elf program verify start reset 0

, I got a warning that says "The user program and the bootloader overlap" Should I be worried about this?

Thank you for your help

The way I envision this working is that when the Arduino receives a UDP packet from a program on the desktop PC

Some time in the past I think I remember a wifi shield that could not be assigned a static IP address. Not sure if that applies to your shield, but might impact using that shield as a server.

I fixed it!

I ended up cutting all of the wires to the ICSP header, disconnecting the WiFi shield completely before trying to update the firmware. During the firmware update, I had to reset the shield after writing each wifi_dnld.elf and wifiHD.elf file to keep the Atmel USB device present in device manager, but I got it to work