HTTP server (#324)

extras/httpd and http_server example
This commit is contained in:
lujji 2017-01-27 08:38:01 +00:00 committed by Ruslan V. Uss
parent ebfbc1144c
commit f64935eb1d
19 changed files with 5050 additions and 0 deletions

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/siimple.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="shortcut icon" href="img/favicon.png">
<title>HTTP Server</title>
</head>
<body>
<ul class="navbar">
<li><a href="/">Home</a></li>
<li><a href="about">About</a></li>
</ul>
<div class="grid main">
<h1>404 - Page not found</h1>
<div class="alert alert-error">Sorry, the page you are requesting was not found on this server.</div>
</div>
</body>
</html>

View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/siimple.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="shortcut icon" href="img/favicon.png">
<title>HTTP Server</title>
</head>
<body>
<ul class="navbar">
<li><a href="/">Home</a></li>
<li><a class="active" href="about">About</a></li>
</ul>
<div class="grid main">
<h1>About</h1>
<p>This server is built on httpd from LwIP.</p>
<p>For more info see <a href="http://www.nongnu.org/lwip/2_0_0/group__httpd.html">HTTP Server documentation</a>.</p>
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,73 @@
ul.navbar {
list-style-type: none;
margin-bottom: 32px;
padding: 0;
overflow: hidden;
background-color: #333;
}
ul.navbar li {
float: left;
}
ul.navbar li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
ul.navbar li a:hover:not(.active) {
background-color: #111;
}
ul.navbar li a.active {
background-color: #09a0f6;
}
@media screen and (max-width: 600px){
ul.navbar li.right,
ul.navbar li {float: none;}
}
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #03A9F4; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
text-align: left;
padding-left: 14px;
background-color: #E1F5FE; color: #03A9F4;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 14px;
background-color: #FFFFFF; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
border: 2px solid #03A9F4; border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

View file

@ -0,0 +1,76 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/siimple.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="shortcut icon" href="img/favicon.png">
<title>HTTP Server</title>
</head>
<body>
<ul class="navbar">
<li><a class="active" href="/">Home</a></li>
<li><a href="about">About</a></li>
</ul>
<div class="grid main">
<h1>ESP8266 HTTP Server</h1>
<div class="alert alert-done">HTTP Server is up and running.</div>
<p>This is an example HTTP server with CGI and SSI support. The switch below will allow you to test CGI handler and turn
the blue LED on or off.</p>
<div class="cover" align="center">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="led-switch" onclick="gpio();">
<label class="onoffswitch-label" for="led-switch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<h1>Server Status</h1>
<table class="table table-striped">
<tr>
<td><b>Uptime:</b></td>
<td><!--#uptime--> seconds</td>
</tr>
<tr>
<td><b>Free heap:</b></td>
<td><!--#heap--> bytes</td>
</tr>
<tr>
<td><b>LED state:</b></td>
<td id="ledState"><!--#led--></td>
</tr>
</table>
<h1>How it works</h1>
<p> Each time the server detects a tag of the form <code>&lt;!--#name--&gt;</code> in a .shtml, .ssi or .shtm file
where <code>name</code> appears as one of the tags supplied to <code>http_set_ssi_handler</code> in the <code>pcConfigSSITags</code> array,
an insert string is appended after the tag string in file and sent back to the client.</p>
<p>A CGI handler function is called each time the server is asked for a file
whose name was previously registered as a CGI function using a call to <code>http_set_cgi_handler</code>.
This function allows you to access the parameters provided along with the URI.</p>
</div>
<script>
window.onload = function () {
var ls = document.getElementById('ledState').innerHTML;
ls = ls.split(/-->/).pop().trim();
document.getElementById('led-switch').checked = (ls == 'On');
};
function gpio() {
if (document.getElementById('led-switch').checked)
window.location.href = 'gpio?off=2';
else
window.location.href = 'gpio?on=2';
};
</script>
</body>
</html>