It Works
-If you see this, it means the tiny li'l website in your ESP8266 does actually work. +If you see this, it means the tiny li'l website in your ESP8266 does actually work. Fyi, this page has +been loaded %counter% times.
- If you haven't connected this device to your WLAN network now, you can do so.
- You can also control the LED. diff --git a/user/cgi.c b/user/cgi.c index 70ba86e..384bde4 100644 --- a/user/cgi.c +++ b/user/cgi.c @@ -62,7 +62,19 @@ void ICACHE_FLASH_ATTR tplLed(HttpdConnData *connData, char *token, void **arg) espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff)); } +static long hitCounter=0; +//Template code for the counter on the index page. +void ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) { + char buff[128]; + if (token==NULL) return; + + if (os_strcmp(token, "counter")==0) { + hitCounter++; + os_sprintf(buff, "%ld", hitCounter); + } + espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff)); +} //Cgi that reads the SPI flash. Assumes 512KByte flash. diff --git a/user/cgi.h b/user/cgi.h index 07431a6..6dbf923 100644 --- a/user/cgi.h +++ b/user/cgi.h @@ -6,5 +6,6 @@ int cgiLed(HttpdConnData *connData); void tplLed(HttpdConnData *connData, char *token, void **arg); int cgiReadFlash(HttpdConnData *connData); +void tplCounter(HttpdConnData *connData, char *token, void **arg); #endif \ No newline at end of file diff --git a/user/cgiwifi.c b/user/cgiwifi.c index 36529b6..a6bba43 100644 --- a/user/cgiwifi.c +++ b/user/cgiwifi.c @@ -184,10 +184,13 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { //Schedule disconnect/connect os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, reassTimerCb, NULL); +#if 0 os_timer_arm(&reassTimer, 1000, 0); httpdRedirect(connData, "connecting.html"); - +#else + httpdRedirect(connData, "/wifi"); +#endif return HTTPD_CGI_DONE; } diff --git a/user/espfs.c b/user/espfs.c index 08f1d1e..59f8643 100644 --- a/user/espfs.c +++ b/user/espfs.c @@ -125,8 +125,8 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { //Grab the name of the file. p+=sizeof(EspFsHeader); os_memcpy(namebuf, p, sizeof(namebuf)); - os_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n", - namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags); +// os_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n", +// namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags); if (os_strcmp(namebuf, fileName)==0) { //Yay, this is the file we need! p+=h.nameLen; //Skip to content. @@ -174,7 +174,7 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) { int toRead; toRead=flen-(fh->posComp-fh->posStart); if (len>toRead) len=toRead; - os_printf("Reading %d bytes from %x\n", len, (unsigned int)fh->posComp); +// os_printf("Reading %d bytes from %x\n", len, (unsigned int)fh->posComp); memcpyAligned(buff, fh->posComp, len); fh->posDecomp+=len; fh->posComp+=len; diff --git a/user/httpd.c b/user/httpd.c index 2a29f66..49545ec 100644 --- a/user/httpd.c +++ b/user/httpd.c @@ -199,7 +199,7 @@ int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) { static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) { int r; HttpdConnData *conn=httpdFindConnData(arg); - os_printf("Sent callback on conn %p\n", conn); +// os_printf("Sent callback on conn %p\n", conn); if (conn==NULL) return; if (conn->cgi==NULL) { //Marked for destruction? os_printf("Conn %p is done. Closing.\n", conn->conn); @@ -243,7 +243,7 @@ static void ICACHE_FLASH_ATTR httpdSendResp(HttpdConnData *conn) { static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) { int i; - os_printf("Got header %s\n", h); +// os_printf("Got header %s\n", h); if (os_strncmp(h, "GET ", 4)==0 || os_strncmp(h, "POST ", 5)==0) { char *e; diff --git a/user/user_main.c b/user/user_main.c index be273ff..abb9476 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -21,9 +21,10 @@ #include "stdout.h" HttpdBuiltInUrl builtInUrls[]={ - {"/", cgiRedirect, "/index.html"}, + {"/", cgiRedirect, "/index.tpl"}, {"/flash.bin", cgiReadFlash, NULL}, {"/led.tpl", cgiEspFsTemplate, tplLed}, + {"/index.tpl", cgiEspFsTemplate, tplCounter}, {"/led.cgi", cgiLed, NULL}, //Routines to make the /wifi URL and everything beneath it work.