esphttpd called by NETIO-App
Posted: Tue Jan 27, 2015 11:48 am
Hi,
Example esphttpd works really fine with browser.
Now I also want to communicate with ESP with the App NETIO from David Eickhoff.
Like 192.168.1.191/?led1=1 This already lets LED1 go ON.
Therefore I added in httpd_parse_header in file httpd.c:
if (conn->getArgs!=0) {
*conn->getArgs=0;
conn->getArgs++;
os_printf("GET args = %s\n", conn->getArgs);
cgiGetBef(conn);
In this new function in cgi.c the LED’s are handled like in cgiLed:
This already makes LED's go on and off with NETIO.
But the solution I think is not good.
There comes a GET-request from NETIO and I don't know how to send a correct response. In case of LED it should be only ON or OFF.
In case of DHT22 the 1.requst would be 192.168.1.191/?temp. Response: 20.5
2. request would be 192.168.1.191/?humid. Response:50.34
Because I’m not very familiar with TCP/IP things and cgi my question:
Could you give me any help to send a response from ESP? I don’t know how to edit this in httpd.c.
Kind regards
ulko
Example esphttpd works really fine with browser.
Now I also want to communicate with ESP with the App NETIO from David Eickhoff.
Like 192.168.1.191/?led1=1 This already lets LED1 go ON.
Therefore I added in httpd_parse_header in file httpd.c:
if (conn->getArgs!=0) {
*conn->getArgs=0;
conn->getArgs++;
os_printf("GET args = %s\n", conn->getArgs);
cgiGetBef(conn);
In this new function in cgi.c the LED’s are handled like in cgiLed:
Code: Select all
int ICACHE_FLASH_ATTR cgiGetBef(HttpdConnData *connData) {
int len1,len2,len3;
char buff[1024];
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
len1=httpdFindArg(connData->getArgs, "led1", buff, sizeof(buff));
len2=httpdFindArg(connData->getArgs, "led2", buff, sizeof(buff));
len3=httpdFindArg(connData->getArgs, "led3", buff, sizeof(buff));
if (len1>0) {
currLedState1=atoi(buff);
ioLed(LEDGPIO1,currLedState1);
}
else if (len2>0) {
currLedState2=atoi(buff);
ioLed(LEDGPIO2,currLedState2);
}
else if (len3>0) {
currLedState3=atoi(buff);
ioLed(LEDGPIO3,currLedState3);
}
}
This already makes LED's go on and off with NETIO.
But the solution I think is not good.
There comes a GET-request from NETIO and I don't know how to send a correct response. In case of LED it should be only ON or OFF.
In case of DHT22 the 1.requst would be 192.168.1.191/?temp. Response: 20.5
2. request would be 192.168.1.191/?humid. Response:50.34
Because I’m not very familiar with TCP/IP things and cgi my question:
Could you give me any help to send a response from ESP? I don’t know how to edit this in httpd.c.
Kind regards
ulko