-->
Page 1 of 2

How to make something happen with GET

PostPosted: Mon Feb 01, 2016 6:56 am
by Eddiie
Hi,
Is it possible to turn the GPIO on by sending a URL?
For example - http://192.168.4.1/led.tpl?led=1

Where ?led=1 is the argument being passed to led.tpl ??

Thanks Sprite, appreciate all the help.

Re: How to make something happen with GET

PostPosted: Mon Feb 01, 2016 3:13 pm
by Eddiie
I see from the terminal output:

GET Args = led=2

Looking in the code, httpd.c , it uses something I am not familiar with, conn->getArgs
What is this? conn->getArgs a pointer? Shifting something into a variable? is this available anywhere in the program, like cgi.c?

Any hints on where to put the case / if statement?

Re: How to make something happen with GET

PostPosted: Mon Feb 01, 2016 3:19 pm
by Eddiie
I see in cgi.c a hint for POST..

//Cgi that turns the LED on or off according to the 'led' param in the POST data
int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) {
int len;
char buff[1024];

if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}

len=httpdFindArg(connData->post->buff, "led", buff, sizeof(buff));
if (len!=0) {
currLedState=atoi(buff);
ioLed(currLedState);
}

httpdRedirect(connData, "led.tpl");
return HTTPD_CGI_DONE;
}


Thinking...

Re: How to make something happen with GET

PostPosted: Mon Feb 01, 2016 4:18 pm
by Eddiie
http://192.168.4.1/led.cgi?led=1

Output
URL = /led.cgi
Mallocced buffer for 4 + 1 bytes of post data.
Is url index 0
Is url index 5
findArg: ?led
Finding led in ?led: Not found :/


It cannot find led in ?led

it is right there...