kisesp wrote:So probably the esp can't scan if in softap mode.Two options remaining 1.scan before start the server (at user main) and list that on scan.cgi 2. when scancgi start switch to sta mode then scan and switch back and return the results.
I think the 1. option the good choice because if somebody want to use always in softap mode no reason to check the AP-s list, if need the sta mode it's need only once, when do config-s.
Well, scanning actually seems to work when in AP+STA mode. I'm thinking of switching to that by default. It has some other interesting issues tho'.
kisesp wrote:How variable parse work? I not really understand %counter% and cgi callback.
I want to add variable parse inside html like %led1% but in any html, I think something global struct variable with name and options, then if found %var% then search at struct and replace with value, or trigger a function to execute and return the value.
Thanks.
Not gonna work. You actually need to connect the .tpl-file to a function that 'fills in the blanks'. For eg the led page (the bit that shows if the led is on or off; the action of turning it on or off is handled by a cgi) the hooking up is done in user-main.c:
{"/led.tpl", cgiEspFsTemplate, tplLed},
The tplLed function then fills in the %ledstate% in the led.tpl file:
//Template code for the led page.
void ICACHE_FLASH_ATTR tplLed(HttpdConnData *connData, char *token, void **arg) {
char buff[128];
if (token==NULL) return;
os_strcpy(buff, "Unknown");
if (os_strcmp(token, "ledstate")==0) {
if (currLedState) {
os_strcpy(buff, "on");
} else {
os_strcpy(buff, "off");
}
}
espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
}
So basically, if you want to use the same %something% thing in multiple pages, you'll have to repeat the hooking up line of code in user-main.c multiple times, but you can use the same function to do the replacement.