Hardware Reference
In-Depth Information
The first
thing
you need to do is take the network
info as described above and put it into
variables so you can connect. You'll still
need the server and lineLength global
variables from the previous RGB server
sketch as well.
Configure It (WPA)
/*
WiFi RGB Web Server
Context: Arduino
*/
8 Change these to
match your own network.
#include <SPI.h>
#include <WiFi.h>
char ssid[] = " myNetwork "; // the name of your network
char password[] = " secretpassword "; // the password you're using to connect
int status = WL_IDLE_STATUS; // the WiFi radio's status
Server server(80);
int lineLength = 0; // length of the incoming text line
Configure It (WEP)
If you're
using
WPA encryption, your configuration
variables will look more like the code at
right (changes are shown in blue).
char ssid[] = "myNetwork"; // the name of your network
char keyIndex = 0 ; // WEP networks can have multiple keys.
// the 128-bit WEP key you're using to connect:
char key[] = “ FACEDEEDDADA01234567890ABC ”;
int status = WL_IDLE_STATUS; // the WiFi radio's status
8 Change these to
match your own network.
If your router has values
for more than one key
index, use key index 0.
8
The setup() looks different from
the previous sketch because you're
setting up a WiFi connection instead
of a wired Ethernet connection. If you
get a connection, print out the network
name. If you don't, stop the program
right there. The WiFi shield uses DHCP
by default, so you don't need to do
anything in your code to get an address
via DHCP.
void setup() {
// initialize serial:
Serial.begin(9600);
Serial.println("Attempting to connect to network...");
// attempt to connect using WPA encryption:
status = WiFi.begin(ssid, password);
// or use this to attempt to connect using WEP 128-bit encryption:
// status = WiFi.begin(ssid, keyIndex, key);
The remainder of the sketch is identical
to the sketch in Project 6. You can
copy the rest of the code from there.
Because WiFi is also Ethernet, the
Client and Server library interfaces are
the same, so you can change between
Ethernet and WiFi easily.
Serial.print("SSID: ");
Serial.println(ssid);
// if you're not connected, stop here:
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a WiFi connection");
while(true);
}
}
 
Search WWH ::




Custom Search