Lots of remote changes.

dht is now processing commands!
hurray!
This commit is contained in:
d-popov
2020-04-09 12:16:02 +03:00
parent 794eda52af
commit b628ade4dd
18 changed files with 1810 additions and 39 deletions

20
views/accontrol.ejs Normal file
View File

@@ -0,0 +1,20 @@
<h2>AC Control for <%= model.user.username %></h2>
<form action="/n/accontrol" class="form-inline" method="POST">
<div class="form-group">
<input type='checkbox' name='power' <%= model.data.power|true ? "checked" : "" %> data-toggle='toggle'
data-style='android' data-on='ON' data-off='Off' />
</div>
<div class="form-group">
<input type='checkbox' name='heat' <%= model.data.heat|true ? "checked" : "" %> data-toggle='toggle' data-on='Heat'
data-off='Cool' data-onstyle='warning' data-offstyle='info' />
</div>
<div class="form-group">
<input type='number' name='temp' value='<%= model.data.temp|23%>' min='16' max='32' step='0.5' />
</div>
<div class="form-group">
<!-- <input type='checkbox' name='econo'<%= model.data.econo ? "checked" : "" %> data-toggle='toggle' data-style='android' data-on='Eco' data-off='Normal' data-onstyle='info' data-offstyle='warning'/> -->
<input type='submit' class='button' value='SET!'>
</div>
</form>
INFO:
<%= model.info %>

128
views/chart.ejs Normal file
View File

@@ -0,0 +1,128 @@
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<%- contentFor('head') %>
<script>
var current;
window.onload = function () {
var dataPoints1 = [];
var dataPoints2 = [];
/*{ x: new Date(2017, 0, 3), y: 650 },
{ x: new Date(2017, 0, 4), y: 700 },
*/
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2",
zoomEnabled: true,
zoomType: "x",
exportEnabled: true,
title:{
text: "Retrieving current A23 conditions..."
},
/* subtitles:[{
text: "X Axis scale is Logarithmic",
fontSize: 14
}],*/
axisX:{
valueFormatString: "HH:mm DD MMM",
crosshair: {
enabled: true,
snapToDataPoint: true
}
},
axisY: {
title: "Temperature",
lineColor: "#C24642",
titleFontColor: "#C24642",
labelFontColor: "#C24642",
crosshair: {
enabled: true
}
},
axisY2: [
{
title: "Relative hum %",
titleFontColor: "#51CDA0",
labelFontColor: "#51CDA0"
}
],
//{title: "Temperature",
//lineColor: "#C24642",
//titleFontColor: "#C0504E",
//labelFontColor: "#C0504E"
//},
toolTip:{
shared:true
},
legend:{
cursor:"pointer",
verticalAlign: "bottom",
horizontalAlign: "left",
dockInsidePlotArea: true,
itemclick: toogleDataSeries
},
data: [{
name: "Temperature",
type: "spline",//line
showInLegend: true,
markerType: "square",
xValueFormatString: "HH:mm on DD MMM, YYYY",
color: "#F08080",
dataPoints: dataPoints2
},
{
name: "Humidiry",
type: "spline",
axisYType: "secondary",
axisYIndex: 1,
showInLegend: true,
lineDashType: "dash",
dataPoints: dataPoints1
}]
});
function toogleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
chart.render();
}
function addData(data) {
for (var i = 0; i < data.length; i++) {
if(data[i].field_name == "A23_DHT"){
var dht = JSON.parse(data[i].field_value).dht;
var date = new Date(data[i]["timestamp"]);
if(dht && dht.hum <= 100){
dataPoints1.push({
x: date,
y: dht.hum
});
dataPoints2.push({
x: date,
y: dht.temp
});
}
}
}
chart.render();
$.getJSON("/n/dht", function(data){
if(data && data.dht){
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
}else {
chart.title.set("text", "A23 conditions");
}
});
}
$.getJSON("/n/dht/A23_DHT", addData);
}
</script>

28
views/layout.ejs Normal file
View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>ESP8266 Weather Server</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="/n/css/bootstrap4-toggle.css" type="text/css" >
<style>
html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}
.button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}
.button2 {background-color: #77878A;}
</style>
<%- defineContent("head") %>
</head>
<body>
<%- include('nav'); -%>
<main role='main' class='container'>
<%- body %>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- <script src='https://code.jquery.com/jquery-3.2.1.slim.min.js' integrity='sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN' crossorigin='anonymous'></script> -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js' integrity='sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q' crossorigin='anonymous'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js' integrity='sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl' crossorigin='anonymous'></script>
<script src="/n/js/bootstrap4-toggle.js" integrity="sha256-8hY+ssbh4ap2bCD3tlbINeezcjxRL5IlWDmzNLQBO/U="></script>
<%- defineContent("scripts") %>
</body>
</html>

13
views/login.ejs Normal file
View File

@@ -0,0 +1,13 @@
<form action="/n/login" method="post">
<div class="form-group">
<label>Username:</label>
<input type="text" name="username" class="form-control" />
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" name="password" class="form-control" />
</div>
<div class="form-group">
<input type="submit" class='btn btn-default button' value="Log In" />
</div>
</form>

4
views/nav.ejs Normal file
View File

@@ -0,0 +1,4 @@
<a href="/n/accontrol" >control</a>
<a href="/n/logout" >log out</a>
<a href="/n/chart"> chart</a>