by dukeofdoom » Sun Sep 05, 2010 11:58 am
Well I got it working. It "ain't" pretty or elegant but it works.
My C skills are rusty I am more of a KSH/perl kinda guy.
My goal was simple I have a relay off a garage door that controls a switch I wanted that switch to control a digital pin on the Arduino. Then simply display a 1 or a 0 for each door. I have a Linux node that picks up the door states and does the heavy lifting. So the page on the Arduino needed to be basic at best. It works but I will be cleaning it up as my skills increase.
I do appeal to async labs though to make a starting webpage that does this sort of function and also makes the form that they had supplied work, doing this would help newbies like me get a better jump start.
I used the standard webserver sketch and made the following edits.
IN the PDE file after IP setup:
//---------------------------------------------------------------------------
void setup()
{
// Serial.begin(9600);
pinMode(6, INPUT); // ADDED this to initialize pin 6 as input, as a note many pins are unusable for I/O due to the WISHIELD using the pins.
WiFi.init();
}
// This is the webpage that is served up by the webserver
//{"HTTP/1.1 200 OK\r\n Content-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>"}; //original supplied line.
const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\n Content-Type: text/html\r\n\r\n<br> VAR1 AAAA <BR> VAR2 BBBB"}; //this is what the webpage will look like, the variables don’t get added here this is just used to determine a character length of the webpage to be display. That length is used later.
void loop()
{
out1 = digitalRead(6); //set variable out1 to hold reading of pin 1.
delay(100); //added a delay
WiFi.run();
}
.C file:
I only made changes to the fill_buf function.
unsigned short fill_buf(void* blk)
{
unsigned short webpage_len;
webpage_len = (strlen_P(webpage)>uip_mss())?uip_mss():strlen_P(webpage);
memcpy_P(uip_appdata, webpage, webpage_len);
int jag = sprintf( uip_appdata, "HTTP/1.1 200 OK\r\n Content-Type: text/html\r\n\r\nn<br> VAR1 %d <BR> VAR2 BBBB", out1 ); //uip_appdata is the var that holds the webpage. Due to the weird way PROGMEM works and my C incompetence I bypassed it all together. This is where I add the variables (so far just one) to the page. Yes its double work but hey it works. It important that this HTTP line doesn’t have more characters then the HTTP line in the webpage variable.
return webpage_len;
}
I tested and the webpage updates the VAR1 field with a 1 or 0 as the garage door is either up or down.