Here is a copy of my code below of the UNO serving up a webpage with a button to turn on the led.
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define LED 8
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,3}; // 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 = {"********"}; // 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");
WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
digitalWrite(LED,HIGH); //Turn on the LED
delay(10000);
digitalWrite(LED,LOW); //Turn off the LED
delay(5000);
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("<title>LED Switch</title>");
WiServer.print("<center>Press button to turn on LED.</center>");
WiServer.print("<html><center>
<form method=\"get\" action=\"0\">Toggle Switch:<input type=\"submit\" name=\"0\" value=\"LED\"></input></form></center>
");
WiServer.print("<center>By Emmet Fealy</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); //Turn LED off
// 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);
}
What way do you think I will be able to get the other arduino connected to this page too?
Also in this code what happens is I press the button on the webpage and it redirects to a new page so to turn on the LED once and then is refreshed back to the original page.This works perfectly sometimes and other times it will turn on the LED twice
before returning to the original page. I dont kno why this is happening.
Thank you for your help,
Emmet