Added webcounter to initial page

This commit is contained in:
Jeroen Domburg
2014-10-14 22:40:02 +02:00
parent a979dabd3b
commit c22ae3469f
7 changed files with 26 additions and 8 deletions
+12
View File
@@ -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.
+1
View File
@@ -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
+4 -1
View File
@@ -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;
}
+3 -3
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -1
View File
@@ -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.