Need help with basic WiShield program

Hi guys, I'm using the Copperhead (CuHead) wifi shield with an Arduino Uno - though as I understand it, it's basically the same as an asynclabs WiShield (the libraries are practically identical).

I've managed to properly execute the WebServer example sketch and my Arduino is connecting to the wifi network successfully. I'm pretty clueless going forward though, and there doesn't seem to be all that much documentation available.

Can someone point me in the right direction on how to blink an LED over wifi? At the moment I can access a 'Hello World' page that the WebServer example sketch sets up:

// This is the webpage that is served up by the webserver
const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><h1>Hello World!! I am WiShield</h1><form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"LED1\"></input></form></center>"};

But I'm not clear on where to go from here.

Also, for my purposes, should I be running the WiShield in client or server mode?

Thanks!

Can someone point me in the right direction on how to blink an LED over wifi?

What does this mean? If the Arduino is a server, it serves up a response to a connect, typically in the form of a web page, if the GET command contains no additional data. If the GET command does contain additional data, the server typically tailors its response.

So, if the Arduino is to respond to "GET / HTTP 1.0" it typically serves up a web page. If the web page contains a form with two submit buttons, labeled and named "On" and "Off", pressing the On button will submit another request to the Arduino - "GET /?On=On HTTP 1.0". The Arduino then needs to discover that this is not an empty request, and perform some action based on the non-empty portion of the request. This involves parsing the request, and understanding what the Arduino should do.

So, exactly what user interface would you expect to see to be able to "blink an LED"? Do you want to be able to toggle it off and on? Or, do you want to be able to start it blinking at a fixed rate, and later stop it? Or, do you want to control how fast the LED blinks?

Also, for my purposes, should I be running the WiShield in client or server mode?

In light of the above, I'd think the answer is pretty obvious.

Thanks for the reply PaulS.

I'd like to keep things as simple as possible initially. I'd happily settle for just turning an led on or off via a web form with a on/off drop down and a submit button.

Anyone?

Pretty please with cherries on top?

Anyone?

Pretty please with cherries on top?

Is this true, or not?

Can someone point me in the right direction on how to blink an LED over wifi? At the moment I can access a 'Hello World' page that the WebServer example sketch sets up

If it is, replace the contents of that page with a form. You do know how to create a form, right?
If not, I'd recommend spending some time at this site:

instead of asking us to do your research for you, cherries or not.

I got this from the asynclabs wishield forum under completed projects... works great,

/*

  • A simple sketch that uses WiServer to serve a web page !! that kim messed with.
    */

#include <WiServer.h>
#include <string.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define ledPin1 5
#define ledPin2 6
#define ledPin3 7

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = { 10,1,1,5}; // IP address of WiShield
unsigned char gateway_ip[] = { 192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = { 255,0,0,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = { "DLINK"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = { "12345678"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;

// End of wireless configuration parameters ----------------------------------------

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;

void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = '\0';
if (test)
{
strcat(returnBuffer, "On");
}
else
{
strcat(returnBuffer, "Off");
}
}

void printStates()
{
for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
boolToString(states[stateCounter], stateBuff);

Serial.print("State of ");
Serial.print(stateCounter);
Serial.print(": ");
Serial.println(stateBuff);
}
}

void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL) {

Serial.println("Page printing begun");

printStates();
writeStates();

//check whether we need to change the led state
if (URL[1] == '?' && URL[2] == 'L' && URL[3] == 'E' && URL[4] == 'D') //url has a leading /
{
ledChange = (int)(URL[5] - 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];
Serial.print("Have changed ");
Serial.println(ledChange);
}
}

//after having change state, return the user to the index page.
WiServer.print("");
return true;
}

if (strcmp(URL, "/") == false) //why is this not true?
{
WiServer.print("Led switch");

WiServer.print("Please select the led state:\n");
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 - 3 rather than 0 - 2
numAsCharBuff[1] = '\0'; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = '\0'; //initialise string
strcat(tmpStrCat, "<a href=?LED"); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = '\0'; //terminate the string properly for later.

strcat(tmpStrCat, ">Led ");
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, ": ");

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, " "); //we now have something in the range of Led 0: Off

WiServer.print(tmpStrCat);
}

WiServer.print(" ");
return true;
}
}

void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);

Serial.begin(9600);
WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
}

void loop(){
// Run WiServer
WiServer.server_task();

delay(10);
}

Thanks for your reply Walter. I managed to get to the "Hello World" website and found the brick wall as Aurduinoaussie did.

I'm just a newbie, and I totally understood what Arduinoaussie was asking.

Just reading through a lot of the posts on this forum, some people need to come down from their pedestals and lend a hand instead of polishing their egos. If I'm understanding this correctly, the Arduino was designed as a learning platform for us guys that didn't choose electronics as a main profession. I could understand harsh criticism if someone was wondering where to stick the usb plug, but come on guys! What's the use of these forums if we can't ask a reasonable question?

I would use the Asynclabs SimpleSketch, similar to what Waltermixxx posted. That is the one that I have used and it works fine.

As far as blinking an LED, not sure exactly what you are trying to do, but I would do something at the end of the if statement "if (strcmp(URL,....", where after your webpage has been output, put your blink code in. That way you could blink an different LED for /index.html, /firstpage.html and so on.

Well, the "Hello World" website (for me at least) had an on/off toggle button for an led. However, it gave no mention of wiring up an led for this purpose, and when I click the button, it goes to the "page not found"...

I've seen a couple of example sketches to experiment with leds, but combining wi/fi code and code for the leds is nothing to "shake a stick at" in the beginning stages.

To be honest, I'm still trying to figure out why my CuHead won't power up when I try to use a battery pack en lieu of the usb plug. Is it a jumper setting? Do I route power to the shields onboard power plug? How much power does it need? I've yet to find any information on it.

I have a Blackwidow board, which sounds similar to the one you are using. I havent tried a battery pack, but I have tried using an AC adapter. No jumper needed, the board automatically selects the right power source.

For your problem I wouldn't use the Hello World program, just use the program that I suggested, then at the end of the /turn_on.html (or whatever) page make led_status=1, /turn_off.html make led_status=0, and then in your loop() code, digitalWrite(pin,led_status)