Help to control LEDs via URL using WiFiRedback

I borrowed most of the following Sketch from Gadgetnate.

I’m a newbie this is my first try at Arduino.
Can someone review the Sketch and suggest why I am unable to control the LEDs
using the URL ( http://192.168.11.110/?RedState=1 ) ? No errors and nothing happens.

From what I can tell the WiServer.h uses the same code as Server.h.

Controlling the LEDs from the web page (http://192.168.11.110) works but not the URL.

/*

  • A simple sketch that uses WiServer to serve a web page to control 3 LEDs.
    */

#include <WiServer.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip = {192,168,11,110}; // IP address of WiShield
unsigned char gateway_ip = {192,168,11,1}; // router or gateway IP address
unsigned char subnet_mask = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid PROGMEM = {“ZuniConnect”}; // 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 ----------------------------------------

int redState = 0;
int whiteState = 0;
int greenState = 0;

int redPin = 4;
int greenPin = 5;
int whitePin = 6;

// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
if (strcmp(URL, “/red”) == 0) redState = !redState;
if (strcmp(URL, “/white”) == 0) whiteState = !whiteState;
if (strcmp(URL, “/green”) == 0) greenState = !greenState;
digitalWrite(redPin, redState);
digitalWrite(whitePin, whiteState);
digitalWrite(greenPin, greenState);

// Check if the requested URL matches “/”
// if (strcmp(URL, “/”) == 0) {
// Use WiServer’s print and println functions to write out the page content
WiServer.print("");
WiServer.print("Light Control

“);
printLightStatus(“red”, redState);
printLightStatus(“white”, whiteState);
printLightStatus(“green”, greenState);
WiServer.print(“The page you requested was: “);
WiServer.print(URL);
WiServer.print(”
The arduino has been running for: “);
WiServer.print(millis());
WiServer.print(” milliseconds
“);
WiServer.print(””);
// URL was recognized
return true;
//}
// URL not found
return false;
}
void printLightStatus( String lightName, int lightState) {
WiServer.print(lightName);
WiServer.print(” Light is “);
if(lightState ==0) {
WiServer.print(” off <a href=/");
WiServer.print(lightName);
WiServer.print(">Turn On
“);
} else {
WiServer.print(” on <a href=/");
WiServer.print(lightName);
WiServer.print(">Turn off
");
}
}

void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
WiServer.init(sendMyPage);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
pinMode(redPin, OUTPUT);
pinMode(whitePin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
}

It looks like your sketch is looking for "/red" and not "/?RedState=1". Perhaps this would work:

if (strcmp(URL, "/?RedState=0") == 0) redState = 0; 
if (strcmp(URL, "/?WhiteState=0") == 0) whiteState = 0; 
if (strcmp(URL, "/?GreenState=0") == 0) greenState = 0; 
if (strcmp(URL, "/?RedState=1") == 0) redState = 1; 
if (strcmp(URL, "/?WhiteState=1") == 0) whiteState = 1; 
if (strcmp(URL, "/?GreenState=1") == 0) greenState = 1;

Thanks!

I tried this: http://192.168.11.110/?red=1

It also does nothing. ?

jerrywolfer: Thanks!

I tried this: http://192.168.11.110/?red=1

It also does nothing. ?

That's because the sketch STILL looks for "/red" and not "/?red=1".

If I send via the URL http://192.168.11.110/red=1 or 0 also does nothing.

Am I missing some code to decode the "/red=1" then ?

Again thanks for the help, I'm just getting started with the "C", "HTTP" and "HTML" coding. Right now I'm trusting the "WiServer" code is all in place to decode a GET and POST. I'll bet I'm wrong on that?

YES, sending a "/red" is a toggle "On" and then "Off" Thanks I just didn't get it. I kept sending a "1" and or "0" with the URL since I thought the sketch was decodeing it via the "?" to provide a positive "ON and "OFF".

Any chance you can guide me to code that will do a positve "ON and "OFF" via the URL ?

Darn am I goofed up.