Added webcounter to initial page
This commit is contained in:
@@ -6,7 +6,8 @@
|
|||||||
<div id="main">
|
<div id="main">
|
||||||
<h1>It Works</h1>
|
<h1>It Works</h1>
|
||||||
<p>
|
<p>
|
||||||
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 <b>%counter%</b> times.
|
||||||
<ul>
|
<ul>
|
||||||
<li>If you haven't connected this device to your WLAN network now, you can <a href="/wifi">do so.</a></li>
|
<li>If you haven't connected this device to your WLAN network now, you can <a href="/wifi">do so.</a></li>
|
||||||
<li>You can also control the <a href="led.tpl">LED</a>.</li>
|
<li>You can also control the <a href="led.tpl">LED</a>.</li>
|
||||||
+12
@@ -62,7 +62,19 @@ void ICACHE_FLASH_ATTR tplLed(HttpdConnData *connData, char *token, void **arg)
|
|||||||
espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
|
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.
|
//Cgi that reads the SPI flash. Assumes 512KByte flash.
|
||||||
|
|||||||
@@ -6,5 +6,6 @@
|
|||||||
int cgiLed(HttpdConnData *connData);
|
int cgiLed(HttpdConnData *connData);
|
||||||
void tplLed(HttpdConnData *connData, char *token, void **arg);
|
void tplLed(HttpdConnData *connData, char *token, void **arg);
|
||||||
int cgiReadFlash(HttpdConnData *connData);
|
int cgiReadFlash(HttpdConnData *connData);
|
||||||
|
void tplCounter(HttpdConnData *connData, char *token, void **arg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+4
-1
@@ -184,10 +184,13 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
|
|||||||
//Schedule disconnect/connect
|
//Schedule disconnect/connect
|
||||||
os_timer_disarm(&reassTimer);
|
os_timer_disarm(&reassTimer);
|
||||||
os_timer_setfn(&reassTimer, reassTimerCb, NULL);
|
os_timer_setfn(&reassTimer, reassTimerCb, NULL);
|
||||||
|
#if 0
|
||||||
os_timer_arm(&reassTimer, 1000, 0);
|
os_timer_arm(&reassTimer, 1000, 0);
|
||||||
|
|
||||||
httpdRedirect(connData, "connecting.html");
|
httpdRedirect(connData, "connecting.html");
|
||||||
|
#else
|
||||||
|
httpdRedirect(connData, "/wifi");
|
||||||
|
#endif
|
||||||
return HTTPD_CGI_DONE;
|
return HTTPD_CGI_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -125,8 +125,8 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
|
|||||||
//Grab the name of the file.
|
//Grab the name of the file.
|
||||||
p+=sizeof(EspFsHeader);
|
p+=sizeof(EspFsHeader);
|
||||||
os_memcpy(namebuf, p, sizeof(namebuf));
|
os_memcpy(namebuf, p, sizeof(namebuf));
|
||||||
os_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n",
|
// 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);
|
// namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags);
|
||||||
if (os_strcmp(namebuf, fileName)==0) {
|
if (os_strcmp(namebuf, fileName)==0) {
|
||||||
//Yay, this is the file we need!
|
//Yay, this is the file we need!
|
||||||
p+=h.nameLen; //Skip to content.
|
p+=h.nameLen; //Skip to content.
|
||||||
@@ -174,7 +174,7 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) {
|
|||||||
int toRead;
|
int toRead;
|
||||||
toRead=flen-(fh->posComp-fh->posStart);
|
toRead=flen-(fh->posComp-fh->posStart);
|
||||||
if (len>toRead) len=toRead;
|
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);
|
memcpyAligned(buff, fh->posComp, len);
|
||||||
fh->posDecomp+=len;
|
fh->posDecomp+=len;
|
||||||
fh->posComp+=len;
|
fh->posComp+=len;
|
||||||
|
|||||||
+2
-2
@@ -199,7 +199,7 @@ int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
|
|||||||
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
|
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
|
||||||
int r;
|
int r;
|
||||||
HttpdConnData *conn=httpdFindConnData(arg);
|
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==NULL) return;
|
||||||
if (conn->cgi==NULL) { //Marked for destruction?
|
if (conn->cgi==NULL) { //Marked for destruction?
|
||||||
os_printf("Conn %p is done. Closing.\n", conn->conn);
|
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) {
|
static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
|
||||||
int i;
|
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) {
|
if (os_strncmp(h, "GET ", 4)==0 || os_strncmp(h, "POST ", 5)==0) {
|
||||||
char *e;
|
char *e;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -21,9 +21,10 @@
|
|||||||
#include "stdout.h"
|
#include "stdout.h"
|
||||||
|
|
||||||
HttpdBuiltInUrl builtInUrls[]={
|
HttpdBuiltInUrl builtInUrls[]={
|
||||||
{"/", cgiRedirect, "/index.html"},
|
{"/", cgiRedirect, "/index.tpl"},
|
||||||
{"/flash.bin", cgiReadFlash, NULL},
|
{"/flash.bin", cgiReadFlash, NULL},
|
||||||
{"/led.tpl", cgiEspFsTemplate, tplLed},
|
{"/led.tpl", cgiEspFsTemplate, tplLed},
|
||||||
|
{"/index.tpl", cgiEspFsTemplate, tplCounter},
|
||||||
{"/led.cgi", cgiLed, NULL},
|
{"/led.cgi", cgiLed, NULL},
|
||||||
|
|
||||||
//Routines to make the /wifi URL and everything beneath it work.
|
//Routines to make the /wifi URL and everything beneath it work.
|
||||||
|
|||||||
Reference in New Issue
Block a user