Next:
SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get
es.ES_make_tcp_ack_with_data(buf,plen); // send data
}
}
}
}
// The returned value is stored in the global var strbuf
uint8_t find_key_val(char *str,char *key)
{
uint8_t found=0;
uint8_t i=0;
char *kp;
kp=key;
while(*str && *str!=' ' && found==0){
if (*str == *kp){
kp++;
if (*kp == '\0'){
str++;
kp=key;
if (*str == '='){
found=1;
}
}
}else{
kp=key;
}
str++;
}
if (found==1){
// copy the value to a buffer and terminate it with '\0'
while(*str && *str!=' ' && *str!='&' && i<STR_BUFFER_SIZE){
strbuf[i]=*str;
i++;
str++;
}
strbuf[i]='\0';
}
return(found);
}
int8_t analyse_cmd(char *str)
{
int8_t r=-1;
if (find_key_val(str,"cmd")){
if (*strbuf < 0x3a && *strbuf > 0x2f){
// is a ASCII number, return it
r=(*strbuf-0x30);
}
}
return r;
}
uint16_t print_webpage(uint8_t *buf, byte on_off1, byte on_off2, byte on_off3)
{
int i=0;
uint16_t plen;
plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<left>Arduino web server test</LEFT> "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<body bgcolor=\"#000000\"> "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<font color=\"#FFFFFF\"><FONT FACE=\"arial\"><RIGHT><I><FONT SIZE=1>BTCAD.<U> V1.0 beta</U></h1></FONT></FONT></I> </RIGHT> "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<FONT SIZE=3> <font color=\"#00FF00\"></h1><a href=\"http://192.168.1.1\">192.168.1.1<a></FONT></FONT>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr>
<form METHOD=get action=\""));
plen=es.ES_fill_tcp_data(buf,plen,baseurl);
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h2><font color=\"#FFFFFF\"> selection </h2> "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h1><font color=\"#FFFFFF\"> "));
if(on_off1)
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<img src=\"http://i915.photobucket.com/albums/ac357/mistermpss/test2on.gif\" >"));
else
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<img src=\"http://i915.photobucket.com/albums/ac357/mistermpss/test2off-1.gif\" >"));
if(on_off1){
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=3>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\" #1 ON \"></form>"));
}
else {
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=2>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\" #1 OFF\"></form>"));
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
<form METHOD=get action=\""));
plen=es.ES_fill_tcp_data(buf,plen,baseurl);
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
if(on_off2)
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<img src=\"http://i915.photobucket.com/albums/ac357/mistermpss/test2on.gif\" >"));
else
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<img src=\"http://i915.photobucket.com/albums/ac357/mistermpss/test2off-1.gif\" >"));
if(on_off2){
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=5>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\" #2 ON\"></form>"));
}
else {
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=4>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\" #2 OFF\"></form>"));
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
<form METHOD=get action=\""));
plen=es.ES_fill_tcp_data(buf,plen,baseurl);
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
if(on_off3)
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<img src=\"http://i915.photobucket.com/albums/ac357/mistermpss/test2on.gif\" >"));
else
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<img src=\"http://i915.photobucket.com/albums/ac357/mistermpss/test2off-1.gif\" >"));
if(on_off3){
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=7>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\" #3 ON\"></form>"));
}
else {
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=6>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\" #3 OFF \"></form>"));
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR(" </font></h1>
") );
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</CENTER><hr><hr><FONT FACE=\"arial\"><FONT SIZE=1>link:</font><FONT SIZE=5> <p> Testing <a href=\"http://www.google.com\">www.google.com<a></font></FONT>"));
return(plen);
}