Added webcounter to initial page

v0.9.0
Jeroen Domburg 10 years ago
parent a979dabd3b
commit c22ae3469f
  1. 3
      html/index.tpl
  2. 12
      user/cgi.c
  3. 1
      user/cgi.h
  4. 5
      user/cgiwifi.c
  5. 6
      user/espfs.c
  6. 4
      user/httpd.c
  7. 3
      user/user_main.c

@ -6,7 +6,8 @@
<div id="main">
<h1>It Works</h1>
<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>
<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>

@ -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.

@ -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

@ -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;
}

@ -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;

@ -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;

@ -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.

Loading…
Cancel
Save