removed relative path;
MQTT port & toppic fixed;
This commit is contained in:
3
dht.js
3
dht.js
@@ -201,7 +201,7 @@ wss.on('connection', ws => {
|
||||
|
||||
var mosca = require('mosca');
|
||||
var mqtt_settings = {
|
||||
port:1884,
|
||||
port:1883,
|
||||
secure : {
|
||||
port: 8444,
|
||||
keyPath: SECURE_KEY,
|
||||
@@ -230,6 +230,7 @@ mqtt_client.on('connect', function () {
|
||||
// mqtt_client.subscribe('dht');
|
||||
// mqtt_client.subscribe('ir');
|
||||
|
||||
// ESP_Easy_0 = garden
|
||||
mqtt_client.subscribe('Garden/+');
|
||||
mqtt_client.subscribe('Garden/+/+');
|
||||
mqtt_client.publish('tasmota', 'controller connected');
|
||||
|
||||
12
server.js
12
server.js
@@ -76,22 +76,22 @@ app.get('/login',
|
||||
});
|
||||
|
||||
app.post('/login',
|
||||
passport.authenticate('local', { failureRedirect: config.localPath+ '/login' }),
|
||||
passport.authenticate('local', { failureRedirect: '/login' }),
|
||||
function(req, res) {
|
||||
res.redirect(config.localPath+ '/');
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
app.get('/logout',
|
||||
function(req, res){
|
||||
req.logout();
|
||||
res.redirect(config.localPath+ '/');
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
app.get('/accontrol',
|
||||
// passport.authenticate('local', {
|
||||
// failureRedirect: config.localPath+ '/login' ,
|
||||
// successRedirect: config.localPath+ '/accontrol'}),
|
||||
require('connect-ensure-login').ensureLoggedIn(config.localPath+ '/login'),
|
||||
// failureRedirect: '/login' ,
|
||||
// successRedirect: '/accontrol'}),
|
||||
require('connect-ensure-login').ensureLoggedIn('/login'),
|
||||
function(req, res){
|
||||
res.render('accontrol', { user: req.user });
|
||||
});
|
||||
|
||||
12
src/auth.js
12
src/auth.js
@@ -15,13 +15,13 @@ var CookieStrategy = require('passport-cookie').Strategy;
|
||||
var session = require('express-session');
|
||||
const cookierParser = require('cookie-parser');
|
||||
|
||||
var ensureLoggedIn = require("connect-ensure-login").ensureLoggedIn(config.localPath + "/login");
|
||||
var ensureLoggedIn = require("connect-ensure-login").ensureLoggedIn("/login");
|
||||
|
||||
module.exports = {
|
||||
ensureLoggedIn_Orig: ensureLoggedIn,
|
||||
ensureLoggedIn_P: function (req, res, next){passport.authenticate('local', {
|
||||
successRedirect: config.localPath + '/accontrol',
|
||||
failureRedirect: config.localPath + '/login' })},
|
||||
successRedirect: '/accontrol',
|
||||
failureRedirect: '/login' })},
|
||||
passport: passport,
|
||||
ensureLoggedIn_New: function (req, res, next) {
|
||||
if (req.isAuthenticated()) {
|
||||
@@ -123,8 +123,8 @@ module.exports = {
|
||||
|
||||
app.post('/login',
|
||||
passport.authenticate('local', {
|
||||
successRedirect: config.localPath + '/accontrol',
|
||||
failureRedirect: config.localPath + '/login' }),
|
||||
successRedirect: '/accontrol',
|
||||
failureRedirect: '/login' }),
|
||||
// authenticated user.
|
||||
function(req, res) {
|
||||
console.log("logged in. session:" + req.session);
|
||||
@@ -134,7 +134,7 @@ module.exports = {
|
||||
|
||||
app.get('/logout', function(req, res){
|
||||
req.logout();
|
||||
res.redirect(config.localPath + '/login');
|
||||
res.redirect( '/login');
|
||||
});
|
||||
|
||||
return app;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<h2>AC Control for <% if (model.user) {model.user.username; } %></h2>
|
||||
<h4 id="current">Retrieving current conditions...</h4>
|
||||
<!-- class="form-inline" -->
|
||||
<form id="accontrol" action= config.localPath + "/accontrol" method="POST">
|
||||
<form id="accontrol" action="/accontrol" 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' />
|
||||
@@ -34,7 +34,7 @@ INFO:
|
||||
<%- contentFor('head') %>
|
||||
<script>
|
||||
|
||||
const url = 'wss://iot.d-popov.com' + config.localPath + '/ws'
|
||||
const url = 'wss://iot.d-popov.com/ws'
|
||||
const connection = new WebSocket(url)
|
||||
connection.onopen = (d) => {
|
||||
console.log(`WebSocket error: ${d}`)
|
||||
@@ -57,7 +57,7 @@ INFO:
|
||||
<script>
|
||||
|
||||
window.onload = function () {
|
||||
$.getJSON(config.localPath + "/dht?e=now", function(data){
|
||||
$.getJSON("/dht?e=now", function(data){
|
||||
if(data && data.dht){
|
||||
$('#current').text( "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH. Dew point : " + data.dht.dew + "°C" );
|
||||
}else {
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
}
|
||||
chart.render();
|
||||
|
||||
$.getJSON(config.localPath + "/dht?e=now", function(data){
|
||||
$.getJSON( "/dht?e=now", function(data){
|
||||
if(data && data.dht){
|
||||
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
||||
}else {
|
||||
@@ -154,8 +154,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
$.getJSON(config.localPath + "/device/A23_DHT/7", addData);
|
||||
$.getJSON(config.localPath + "/device/A23_Garden_Humidity/7", addData);
|
||||
$.getJSON("/device/A23_DHT/7", addData);
|
||||
$.getJSON( "/device/A23_Garden_Humidity/7", addData);
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
Period
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
|
||||
<a class="dropdown-item" href=config.localPath + "/garden/1">Day</a>
|
||||
<a class="dropdown-item" href=config.localPath + "/garden/2">2 Days</a>
|
||||
<a class="dropdown-item" href=config.localPath + "/garden/7">Week</a>
|
||||
<a class="dropdown-item" href=config.localPath + "/garden/30">Month</a>
|
||||
<a class="dropdown-item" href=config.localPath + "/garden/91">Quarter</a>
|
||||
<a class="dropdown-item" href="/garden/1">Day</a>
|
||||
<a class="dropdown-item" href="/garden/2">2 Days</a>
|
||||
<a class="dropdown-item" href="/garden/7">Week</a>
|
||||
<a class="dropdown-item" href= "/garden/30">Month</a>
|
||||
<a class="dropdown-item" href="/garden/91">Quarter</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -224,10 +224,10 @@
|
||||
chart.render();
|
||||
}
|
||||
|
||||
$.getJSON(config.localPath + "/device/A23_DHT/<%= model.days ? model.days : '7' %>", addData);
|
||||
$.getJSON(config.localPath + "/device/A23_Garden_dht/<%= model.days ? model.days : '7' %>", addData);
|
||||
$.getJSON("/device/A23_DHT/<%= model.days ? model.days : '7' %>", addData);
|
||||
$.getJSON("/device/A23_Garden_dht/<%= model.days ? model.days : '7' %>", addData);
|
||||
setTimeout(function(){
|
||||
$.getJSON(config.localPath + "/dht?e=now", function(data){
|
||||
$.getJSON("/dht?e=now", function(data){
|
||||
if(data && data.dht){
|
||||
$("#now").text("In A23 currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
||||
}else {
|
||||
@@ -236,7 +236,7 @@
|
||||
});
|
||||
},5000);
|
||||
|
||||
$("#water").on("click", function(){$.ajax({url:config.localPath + "/water?t="+$("#waterTime").val()});});
|
||||
$("#waterStop").on("click", function(){$.ajax({url:config.localPath + "/waterStop"});});
|
||||
$("#water").on("click", function(){$.ajax({url:"/water?t="+$("#waterTime").val()});});
|
||||
$("#waterStop").on("click", function(){$.ajax({url: "/waterStop"});});
|
||||
}
|
||||
</script>
|
||||
@@ -5,7 +5,7 @@
|
||||
<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" >
|
||||
<link rel="stylesheet" href="/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;}
|
||||
@@ -22,7 +22,7 @@
|
||||
<!-- <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>
|
||||
<script src="/js/bootstrap4-toggle.js" integrity="sha256-8hY+ssbh4ap2bCD3tlbINeezcjxRL5IlWDmzNLQBO/U="></script>
|
||||
<%- defineContent("scripts") %>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,4 +1,4 @@
|
||||
<form action=config.localPath+ "/login" method="post">
|
||||
<form action="/login" method="post">
|
||||
<div class="form-group">
|
||||
<label>Username:</label>
|
||||
<input type="text" name="username" class="form-control" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
<a href=config.localPath + "/accontrol" >control</a>
|
||||
<a href=config.localPath + "/logout" >log out</a>
|
||||
<a href=config.localPath + "/chart"> chart</a>
|
||||
<a href=config.localPath + "/garden"> garden</a>
|
||||
<a href="/accontrol" >control</a>
|
||||
<a href="/logout" >log out</a>
|
||||
<a href="/chart"> chart</a>
|
||||
<a href="/garden"> garden</a>
|
||||
Reference in New Issue
Block a user