[SOLVED] Set Static IP Address - Arduino Uno WiFi Shield

I am trying to set a static IP address for my Adruino Uno R3 using the WiFi Shield R3 using the following code:

#include <SPI.h>
#include <WiFi.h>

// the IP address for the shield:
IPAddress ip(192, 168, 0, 177);    

char ssid[] = "NETGEAR06";    // your network SSID (name) 
char pass[] = "quickcarrot586"; // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

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"); 
    while(true);  // don't continue
  } 

  WiFi.config(ip);

  // 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);
  }

  // print your WiFi shield's IP address:
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP()); 
}

void loop () {}

I found that code here, so it should work. I started with WiFi Shield Firmware 1.0.0 and IDE 1.0.6. I got the error

sketch_nov18a.ino: In function 'void setup()':
sketch_nov18a:26: error: 'class WiFiClass' has no member named 'config'

I saw this post and updated the firmware on the WiFi shield to 1.1.0. It was successful, but I am still getting the same error.

Any ideas on what is causing my problem, or how I can fix it? Thank you for your help.

I loaded your code and it compiled ok. It did not throw that error here.

edit: Updating the firmware would not cause that error. Any errors caused by the firmware would show up at runtime, not during the compile.

Any idea what I can do to fix my problem? Or, any alternative ways to set a static IP address?

EDIT: Also, is there a way to revert the firmware back to 1.0.0? I am running into another issue that came about after updating the firmware.

Maybe try a reinstall of the IDE?

If you revert the firmware to v1.0.0, you must use IDE v1.0.3 or earlier.

Well, that is what I am finding weird, and I believe I have talked with you in another on of my posts about this, but the WiFi Shield seems to work better for me with Firmware 1.0.0 and IDE 1.0.6.

Will I be able to set up a static IP in v1.0.3, and do you know how/where I can find the v1.0.0 firmware?

Firmware v1.0.0 uses a different return value for connecting to a server. Have you been able to connect to a web server using firmware v1.0.0 and IDE v1.0.6?

I have. It worked great. After I upgraded the firmware to v1.1.0, I could no longer connect to the web server. I typed in the IP address in my browser, and I get "page not found" or something similar. The Console just waits for a signal from the server.

You have something wrong then. The firmware returns a different value for connected to a server than firmware v1.0.0. They are not compatible.

If you have firmware version 1.0.0, you must use a wifi library from IDE v1.0.3 or earlier.
If you have firmware version 1.1.0, you must use a wifi library from IDE v1.0.4 or later.

I have IDE v1.0.6 and firmware v1.1.0. I just checked both my client and server sketches, and they work ok as long as there is only one client accessing the server code.

edit: You are using an old wifi library. That is why your sketch works with firmware v1.0.0 and you get the error about WiFi.config(). There is no WiFi.config() function in any IDE version wifi library before 1.0.5.

Ok. I just uninstalled and re-installed IDE 1.0.6. I tried the code that I showed above, and I am still getting the same error. Shouldn't 1.0.6 come with the newest libraries?

It should, but I don't know anything about what you have done to your setup. I only know if you get an error that there is no WiFi.config function, and firmware v1.0.0 works, you are using a wifi version older than v1.0.4.

Have you imported another wifi library? Check in the folder where your sketches are stored. Look in a directory called libraries and see if there is a wifi library there. I don't know if those imported libraries override the libraries in the Arduino IDE.

A long time back I think it was said that the official arduino wifi shield would not accept a static IP address assignment.

zoomkat:
A long time back I think it was said that the official arduino wifi shield would not accept a static IP address assignment.

That was correct. The static IP assignment with WiFi.config() started with IDE v1.0.5. I checked mine yesterday and it will accept a static ip.

I installed 1.0.6 on my laptop, and I was able to get it to work, so it seems the libraries on my desktop are not right. I will re-install it on here and try again. Thank you all for the help.

I have three questions about this. On the project I am working on I found that the user must be connected through the same modem to pick up the ip address on the server code.

  1. If I use a static ip address, could the user connect to the ip address without being restricted to being connected through the same modem?

  2. Is this the code to set up the static ip address?

IPAddress ip(192, 168, 0, 177);

If so, it isn't clear to me what the difference is. Will someone explain?

  1. I don't know anything about security or hacking yet, but is it a terrible idea to post this combination of information?

char ssid[] = "NETGEAR06"; // your network SSID (name)
char pass[] = "quickcarrot586"; // your network password (use for WPA, or use as key for WEP)

If you want to access the IP from a different network, you can route the public IP on the WAN interface of the router to the private IP of the Arduino, or you can create a Virtual Private Network (VPN).

I don't think there is a big problem with that security. Considering there are millions of wireless networks worldwide, the odds of being within range of that network are slim to none.

I've found several videos on Youtube explain what VPN is, and why it was designed, etc. But i haven't found any tutorials on how to make a VPN that works with arduino. Is there example code anywhere? or any sort of tutorial?

My VPN works with my arduino. It isn't something that depends on the Arduino setup. My Arduino doesn't even know it is using a VPN.

A VPN tutorial would depend on the make and model of your routers.

Thanks, I'm looking into how to set it up. 2008 Virtual Private Network (VPN) Server (2008 Version) - YouTube is pretty neat

Can you answer my question on WiFi UDP Send and Receive String Library Bug (need guidance) - Programming Questions - Arduino Forum regarding if I need to set it up so each arduino is a client and a server that communicates to each other?