
- Code: Select all
/*
* A simple sketch that uses WiServer to serve a web page
*/
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {10,1,10,115}; // IP address of WiShield
unsigned char gateway_ip[] = {10,1,10,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 = {"testing"}; // max 32 bytes
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"a01b02c03d"}; // 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) {
// 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("<html><head><script language='javascript' src='http://www.website.com/wifi/ra.js'></script>");
WiServer.print("<link href='http://www.website.com/wifi/ra.css' rel='stylesheet' type='text/css'></head><body onLoad='t();'>");
WiServer.print("<table><tr><td colspan=4 align=center><img src='http://www.website.com/images/ra.jpg'></td></tr><tr>");
WiServer.print("<td background='http://www.website.com/images/t1.jpg' align=center><div id=T1 class=style1></div></td>");
WiServer.print("<td background='http://www.website.com/images/t2.jpg' align=center><div id=T2 class=style1></div></td>");
WiServer.print("<td background='http://www.website.com/images/t3.jpg' align=center><div id=T3 class=style1></div></td>");
WiServer.print("<td background='http://www.website.com/images/ph.jpg' align=center><div id=PH class=style1></div></td>");
WiServer.print("</tr><tr><td height='184' colspan=4 align=center><table width='500'><tr><td height='184' background='");
WiServer.print("http://www.website.com/images/panel.jpg'><table width='400' class='style3'><tr class='style2'>");
WiServer.print("<td><div id='l1'></div></td><td><div id='l2'></div></td><td><div id='l3'></div></td><td><div id='l4'></div></td>");
WiServer.print("<td><div id='l5'></div></td><td><div id='l6'></div></td><td><div id='l7'></div></td><td><div id='l8'></div></td>");
WiServer.print("</tr><tr class='style2'>");
WiServer.print("<td><div id='s1'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s1Map'></div></td>");
WiServer.print("<td><div id='s2'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s2Map'></div></td>");
WiServer.print("<td><div id='s3'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s3Map'></div></td>");
WiServer.print("<td><div id='s4'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s4Map'></div></td>");
WiServer.print("<td><div id='s5'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s5Map'></div></td>");
WiServer.print("<td><div id='s6'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s6Map'></div></td>");
WiServer.print("<td><div id='s7'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s7Map'></div></td>");
WiServer.print("<td><div id='s8'><img src='http://www.website.com/images/spacer.gif' width=41 height=85 border='0' usemap='#s8Map'></div></td>");
WiServer.print("</tr></table></td></tr><tr><td><div id='temp'><H1>Please Wait... Loading...</H1></div></td></tr></table></td></tr></table>");
WiServer.print("<map name='s1Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('11');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('10');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('12');\"></map>");
WiServer.print("<map name='s2Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('21');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('20');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('22');\"></map>");
WiServer.print("<map name='s3Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('31');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('30');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('32');\"></map>");
WiServer.print("<map name='s4Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('41');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('40');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('42');\"></map>");
WiServer.print("<map name='s5Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('51');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('50');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('52');\"></map>");
WiServer.print("<map name='s6Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('61');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('60');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('62');\"></map>");
WiServer.print("<map name='s7Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('71');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('70');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('72');\"></map>");
WiServer.print("<map name='s8Map'><area shape='rect' coords='0,0,41,15' href=\"javascript:r('81');\"><area shape='rect' coords='0,33,41,53' ");
WiServer.print("href=\"javascript:r('80');\"><area shape='rect' coords='0,70,41,85' href=\"javascript:r('82');\"></map>");
WiServer.print("</body></html>");
// URL was recognized
return true;
}
// URL not found
return false;
}
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);
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
}