Chat freely about anything...

User avatar
By ulko
#8340 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:
Code: Select allint 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
User avatar
By alonewolfx2
#8342 I am using webbase (by pvvx) and i can send example for your need if you use webbase.
User avatar
By ulko
#8347
alonewolfx2 wrote:I am using webbase (by pvvx) and i can send example for your need if you use webbase.

I don't use webbase. Thanks
User avatar
By Sprite_tm
#8437 Hi,

First of all, you shouldn't need to modify httpd.c ever (unless you're fixing a bug in the httpd code). See builtInUrls in user_main.c for an example how to make the webserver call CGIs.

If what you want to return is small (<1K or so, like a status) you can just do something like this:

Code: Select allint x=1;
char buff[1024];

//...rest of CGI code

sprintf(buff, "Value of x is %d", x);
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;