ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By gerardwr
#3798
Sprite_tm wrote:Yes, someone pointed out the size_t bug to me too. I've fixed it in the version I have here, but I'm also trying to make the WiFi logic a bit more sturdy and port the webserver to 0.9.3. Still need some more time to work all that out and then I'll release it again.


Very interesting development, but still a little too complex for me to join the fun here. It inspired me to create my own webserver.

[Shameless advertising mode ON]
In the meantime I created a webserver in Lua with the nodeMcu firmware. It has an added "bonus" that it supports multiple html files, even server-side Lua code (analog to embedded PHP code) in the HTML files. The nodeMcu is closed source BTW, that's a bummer!

Why not have a look in my (longish) topic , for some inspiration:
viewtopic.php?f=19&t=611
[Shameless advertising mode OFF]

Kudo's to sprite_tm for his trendsetting open source developments!
User avatar
By kisesp
#3829 [Off topic start]
I don't like that lua because:
1.closed source (nobody know what inside) I can't add any low level io functions
2.Slow (compared to native code)
So I will not even try that lua until closed.
[Off topic end]

I checked the AT source and find at cwlap(scan):
Code: Select allif(at_wifiMode == SOFTAP_MODE)
   {
   at_backError;
   return;
}

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.

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.
User avatar
By Sprite_tm
#3869
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:
Code: Select all{"/led.tpl", cgiEspFsTemplate, tplLed},


The tplLed function then fills in the %ledstate% in the led.tpl file:
Code: Select all//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.
User avatar
By kisesp
#3893 Ok, thanks for information finally understand why no results for scan, because the modules are shipped with default settings for AP mode, if I upload the empty bin to 0x7E000 stil AP mode.
The fix: you have to pull GPIO0 to ground for reset, that set mode 3(AP+STA) or before flash you have to set AP+STA with at commands and not use the empty bin.

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.

It's ok for 1 variable and 1 page or same variable and multiple page, but how to use multiple vars on single page?

Thanks.