I'm using the wishield with the UNO and I have some code written to create a webpage displaying a button that will turn an led on for 5 seconds by going to the webpage 192.168.1.2/0?0=Led and once the led sequence has ran through there is a line of code to refresh back to the original page been served 192.168.1.2 to display the button again to be pressed.
This all works well some of the time but other times it will run through the sequence twice before returning to the original page.Is there any thing I can do to fix this or is there another type of button I can generate on the page so it will do what i want to do?
Here is the copy of my code:
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define LED 3
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,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 = {"arduini"}; // 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 ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL)
{
Serial.println("SendMyPage_URL=");
Serial.println(URL);
Serial.println("SendMyPage_URL");
if (strcmp(URL, "/") == 0) // Check if the requested URL matches "/"
{
Serial.println("!!!!! Default request. !!!!!!");
Links ();
return true; // URL was recognized
}
else if (strcmp(URL, "/0?0=Led") == 0)
{
Serial.println("Led");
digitalWrite(LED,HIGH); //Turn on the LED
delay(5000); //Wait for 2 seconds
digitalWrite(LED,LOW); //Turn off LED
WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
return true; // URL was recognized
}
return false; // URL not found
}
void Links ()
{
WiServer.print("<html>");
WiServer.print("<html><center>
<form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"Led\"></input></form></center>
");
WiServer.print("</html>");
}
void setup()
{
// Initialize WiServer and have it use the sendMyPage function to serve pages
WiServer.init(sendMyPage);
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
}
void loop()
{
// Run WiServer
WiServer.server_task();
delay(10);
}
Any help would be much appreciated.
Thank You
Emmet