Skip to content

Commit

Permalink
update web pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed May 24, 2015
1 parent 47eb82c commit c55485c
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 50 deletions.
5 changes: 3 additions & 2 deletions html/console.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
</head>
<body>
<div id="main">
<h1>ESP Link - Debug Console</h1>
<pre>
<div id="topnav">%topnav%</div>
<h1><span class="esp">esp</span> link - Debug Console</h1>
<pre class="console">
%console%
</pre>
</div>
Expand Down
6 changes: 2 additions & 4 deletions html/help.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
</head>
<body>
<div id="main">
<p><a href="/index.tpl">Home</a> | <a href="/wifi/wifi.tpl">Wifi</a> |
Serial | <a href="/led.tpl">LED</a></p>

<h1>ESP Link Help</h1>
<div id="topnav">%topnav%</div>
<h1><span class="esp">esp</span> link - Help</h1>

The ESP Link functions in two wifi modes: Station+AccessPoint (STA+AP) and Station (STA).
In the STA+AP mode it presents a network called esp8266 that you can connect to using the
Expand Down
17 changes: 2 additions & 15 deletions html/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@
</head>
<body>
<div id="main">
<p><a href="/index.tpl">Home</a> | <a href="/wifi/wifi.tpl">Wifi</a> |
Serial | <a href="/led.tpl">LED</a> | <a href="/help.tpl">Help</a> |
<a href="/console.tpl">Console</a>
</p>

<h1>ESP Link</h1>
<div id="topnav">%topnav%</div>
<h1><span class="esp">esp</span> link</h1>
<p>
The ESP Link connects the ESP's serial port to Wifi and it can
program microcontrollers over the serial port, in particular Arduinos, AVRs, and
NXP's LPC800-series ARM processors.</p>

<h1>Status</h1>
<ul>
<li>This page has been loaded <b>%counter%</b> times</li>
<li>Manage <a href="/wifi">wifi</a></li>
<li>Control the <a href="led.tpl">LED</a></li>
</ul>
</p>

</div>
</body></html>
3 changes: 2 additions & 1 deletion html/led.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
</head>
<body>
<div id="main">
<h1>ESP Link - LED test</h1>
<div id="topnav">%topnav%</div>
<h1><span class="esp">esp</span> link - LED test</h1>
<p>
If there's a LED connected to GPIO2, it's now %ledstate%. You can change that using the buttons below.
</p>
Expand Down
45 changes: 42 additions & 3 deletions html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,54 @@ body {

#main {
background-color: #FFFFCC;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
border: 2px solid #000000;
width: 800px;
margin: 0 auto;
padding: 20px
}

h1 {
margin-top: 0;
font-size: 2.4em;
}
h1 .esp {
font-size: 3em;
}

#topnav {
background-color: #CC9966;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
border: 0px solid #000000;
padding: 10px;
margin-left: auto;
margin-right: auto;
color: #ffff99;
}
#topnav a {
color: #ffff99;
font-weight: bold;
font-stretch: expanded;
}

pre.console {
background-color: #663300;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
border: 0px solid #000000;
color: #66ff66;
padding: 5px;
}

pre.console a {
color: #66ff66;
}

.lock-icon {
background-image: url("/wifi/icons.png");
background-color: transparent;
Expand Down
5 changes: 2 additions & 3 deletions html/wifi/wifi.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ window.onload=function(e) {
</head>
<body>
<div id="main">
<p><a href="/index.tpl">Home</a> | Wifi | Serial | <a href="/led.tpl">LED</a></p>

<h1>ESP Link - Wifi Configuration</h1>
<div id="topnav">%topnav%</div>
<h1><span class="esp">esp</span> link - Wifi Configuration</h1>
<p>
Current WiFi mode: %WiFiMode%<br>
Current network: %currSsid% Status: %currStatus% Phy:%currPhy%
Expand Down
34 changes: 28 additions & 6 deletions user/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ flash as a binary. Also handles the hit counter on the main page.
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Jeroen Domburg <[email protected]> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* Jeroen Domburg <[email protected]> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/

Expand All @@ -25,7 +25,7 @@ static char currLedState=0;
int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) {
int len;
char buff[1024];

if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -55,6 +55,8 @@ int ICACHE_FLASH_ATTR tplLed(HttpdConnData *connData, char *token, void **arg) {
} else {
os_strcpy(buff, "off");
}
} else if (os_strcmp(token, "topnav")==0) {
printNav(buff);
}
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
Expand All @@ -64,13 +66,33 @@ static long hitCounter=0;

//Template code for the counter on the index page.
int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) {
char buff[128];
char buff[256];
if (token==NULL) return HTTPD_CGI_DONE;

if (os_strcmp(token, "counter")==0) {
if (os_strcmp(token, "topnav")==0) {
printNav(buff);
} else if (os_strcmp(token, "counter")==0) {
hitCounter++;
os_sprintf(buff, "%ld", hitCounter);
}
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}

static char *navLinks[][2] = {
{ "Home", "/index.tpl" }, { "Wifi", "/wifi/wifi.tpl" }, { "Serial", "/index.tpl" },
{ "Esp log", "/console.tpl" }, { "Help", "/help.tpl" },
{ 0, 0 },
};

// Print the navigation links into the buffer and return the length of what got added
int ICACHE_FLASH_ATTR printNav(char *buff) {
int len = 0;
for (uint8_t i=0; navLinks[i][0] != NULL; i++) {
if (i > 0) buff[len++] = '|';
//os_printf("nav %d: %s -> %s\n", i, navLinks[i][0], navLinks[i][1]);
len += os_sprintf(buff+len, " <a href=\"%s\">%s</a> ", navLinks[i][1], navLinks[i][0]);
}
//os_printf("nav: %s\n", buff);
return len;
}
3 changes: 2 additions & 1 deletion user/cgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
int cgiLed(HttpdConnData *connData);
int tplLed(HttpdConnData *connData, char *token, void **arg);
int tplCounter(HttpdConnData *connData, char *token, void **arg);
int printNav(char *buff);

#endif
#endif
3 changes: 3 additions & 0 deletions user/cgiwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Cgi/template routines for the /wifi url.

#include <esp8266.h>
#include "cgiwifi.h"
#include "cgi.h"
#include "status.h"

//Enable this to disallow any changes in AP settings
Expand Down Expand Up @@ -397,6 +398,8 @@ int ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg)
os_strcpy(buff, "Click <a href=\"setmode.cgi?mode=1\">here</a> to go to STA mode.");
break;
}
} else if (os_strcmp(token, "topnav")==0) {
printNav(buff);
}
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
Expand Down
31 changes: 17 additions & 14 deletions user/console.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <esp8266.h>
#include "uart.h"
#include "cgi.h"
#include "console.h"

// Web console for the esp8266 to replace outputting to uart1.
Expand All @@ -13,12 +14,13 @@ static int console_wr, console_rd;
static void ICACHE_FLASH_ATTR
console_write(char c) {
int wr = (console_wr+1)%BUF_MAX;
if (wr != console_rd) {
console_buf[console_wr] = c;
console_wr = wr;
}
if (wr == console_rd)
console_rd = (console_rd+1) % BUF_MAX; // full, eat first char
console_buf[console_wr] = c;
console_wr = wr;
}

#if 0
static char ICACHE_FLASH_ATTR
console_read(void) {
char c = 0;
Expand All @@ -28,10 +30,11 @@ console_read(void) {
}
return c;
}
#endif

static void ICACHE_FLASH_ATTR
console_write_char(char c) {
//uart0_write_char(c);
uart0_write_char(c);
if (c == '\n') console_write('\r');
console_write(c);
}
Expand All @@ -40,18 +43,18 @@ console_write_char(char c) {
int ICACHE_FLASH_ATTR
tplConsole(HttpdConnData *connData, char *token, void **arg) {
if (token==NULL) return HTTPD_CGI_DONE;
char buff[256];

if (os_strcmp(token, "console") == 0) {
char buf[128];
int n = 0;
while (console_rd != console_wr) {
buf[n++] = console_read();
if (n == 128) {
httpdSend(connData, buf, n);
n = 0;
}
if (console_wr > console_rd) {
httpdSend(connData, console_buf+console_rd, console_wr-console_rd);
} else if (console_rd != console_wr) {
httpdSend(connData, console_buf+console_rd, BUF_MAX-console_rd);
httpdSend(connData, console_buf, console_wr);
}
if (n > 0) httpdSend(connData, buf, n);
} else if (os_strcmp(token, "topnav")==0) {
printNav(buff);
httpdSend(connData, buff, -1);
} else {
httpdSend(connData, "Unknown\n", -1);
}
Expand Down
2 changes: 1 addition & 1 deletion user/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ HttpdBuiltInUrl builtInUrls[]={
{"/flash/next", cgiGetFirmwareNext, NULL},
{"/flash/upload", cgiUploadFirmware, NULL},
{"/flash/reboot", cgiRebootFirmware, NULL},
{"/led.tpl", cgiEspFsTemplate, tplLed},
{"/index.tpl", cgiEspFsTemplate, tplCounter},
{"/help.tpl", cgiEspFsTemplate, tplCounter},
{"/led.cgi", cgiLed, NULL},
{"/console.tpl", cgiEspFsTemplate, tplConsole},

Expand Down

0 comments on commit c55485c

Please sign in to comment.