codigo 2/2
// 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 < 0x4f && *strbuf > 0x40){ //PACO antes era: if (*strbuf < 0x3a && *strbuf > 0x2f) ahora permito de la 'A' a la 'N'
// is a ASCII number, return it
r=*strbuf; // PACO antes era: r=(*strbuf-0x30); ahora esto 40 A->0 ; B -> 1 ; ....
}
}
return r;
}
uint16_t print_webpage(uint8_t *buf, byte on_off1, byte on_off2, byte on_off3, byte on_off4, byte on_off5, byte on_off6)
{ 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("<FONT FACE=\"arial\"><center><p><A HREF=\"/\"><b>SERVIDOR DOMOTICO</b></A></p>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<table bgcolor=\"#f7f7f7\"><tr><td align=center>"));
switch (on_off1) {
case 1:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 1: <font color=\"#00FF00\">On</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=B>")); // B apaga; A enciende
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
break;
case 0:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 1: <font color=\"#CC0000\">Off</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=A>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
break;
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td><td align=center>"));
switch (on_off2) {
case 1:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 2: <font color=\"#00FF00\">On</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=D>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
break;
case 0:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 2: <font color=\"#CC0000\">Off</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=C>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
break;
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td></tr><tr><td align=center>"));
switch (on_off3) {
case 1:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 3: <font color=\"#00FF00\">On</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=F>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
break;
case 0:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 3: <font color=\"#CC0000\">Off</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=E>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
break;
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td><td align=center>"));
switch (on_off4) {
case 1:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 4: <font color=\"#00FF00\">On</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=H>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
break;
case 0:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 4: <font color=\"#CC0000\">Off</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=G>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
break;
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td></tr><tr><td align=center>"));
switch (on_off5) {
case 1:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 5: <font color=\"#00FF00\">On</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=J>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
break;
case 0:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 5: <font color=\"#CC0000\">Off</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=I>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
break;
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td><td align=center>"));
switch (on_off6) {
case 1:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 6: <font color=\"#00FF00\">On</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=L>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
break;
case 0:
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 6: <font color=\"#CC0000\">Off</font>
"));
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("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=K>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
break;
}
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td></tr></table></center><hr>Ethernet Shield Arduino 1.0"));
return(plen);
}