cummulative changes

This commit is contained in:
d-popov
2020-06-09 00:38:35 +03:00
parent 8a68a07112
commit 6a8a895f69
5 changed files with 211 additions and 83 deletions

51
dht.js
View File

@@ -212,6 +212,7 @@ mqtt_client.on('connect', function () {
// mqtt_client.subscribe('dht');
// mqtt_client.subscribe('ir');
mqtt_client.subscribe('ESP_Easy/+');
mqtt_client.subscribe('ESP_Easy/+/+');
mqtt_client.publish('tasmota', 'controller connected')
});
@@ -246,11 +247,36 @@ mqtt_client.on('message', function (topic, message) {
}
handled = true;
}
if(topic === "ESP_Easy/Water/Moisture")
if(topic === "ESP_Easy/status/LWT")
{
console.log("MANGO> " + message + "% moisture");
console.log("ESP_Easy >'" + message + "'");
var stat = {};
var pairs = message.toString().split(';');
stat.event = pairs[0];
for (var i = 0; i < pairs.length; i++)
{
var pair = pairs[i].split(':');
if(pair.length == 2){
stat[pair[0].trim()] = pair[1].trim() || '';
//console.log( "'"+pair[0] +"' >'" + pair[1] + "'");
}
}
dht.ssid=stat["SSID"];
dht.rssi=stat["RSSI"];
if(stat.event ==='ON'){console.log("Device is ONLINE! <" + dht.ssid + "> " + dht.rssi + "dB" );}
if(stat.event ==='OFF'){console.log("Device went ofline!");}
handled = true;
}
if(topic === "ESP_Easy/Soil/RH")
{
console.log("Garden > soil " + message + "% moisture");
dht.Soil = message.toString();
SaveDhtIf();
if(dht.Soil > 10){
SaveDhtIf();
} else {
console.log("Got suspicious soil RH value:" + dht.Soil);
dht.Soil = null;
}
// db.devicemessages.insert(1, "A23_Garden_Humidity", message, function (err, data) {
// if (!err) { console.log("success: "+ data);}
// else { console.log("error: " + err); }
@@ -278,6 +304,15 @@ mqtt_client.on('message', function (topic, message) {
SaveDhtIf();
handled = true;
}
if(topic === "ESP_Easy/Water/start" || topic === "ESP_Easy/Water/stop")
{
var j = JSON.parse(message);
console.log("Garden > Finished watering with " + j.soil + "% soil RH");
dht.Soil = j.soil;
SaveDhtIf();
handled = true;
}
if(!handled){
console.log(topic + " > " + message );
}
@@ -285,11 +320,19 @@ mqtt_client.on('message', function (topic, message) {
function SaveDhtIf(){
if(dht.Temp && dht.Hum && dht.Pres && dht.Soil)
{
console.log("Writing to DB > " + JSON.stringify(dht));
if(dht.Soil < 5)
{
console.log("Soil reported below 5%! Probable loose sensor wire. Record discarded" );
dht = {};
return;
}
console.log("Writing to DB > " + JSON.stringify(dht)+"; SSID: '"+dht.ssid+"' RSSI:"+ dht.rssi + "dB");
db.devicemessages.insert(1, "A23_Garden_dht", JSON.stringify(dht), function (err, data) {
if (!err) { console.log("success: "+ data);}
else { console.log("error: " + err); }
});
dht = {};
}else{
console.log("Missing all data to write to DB !");
}
}

114
package-lock.json generated
View File

@@ -922,9 +922,9 @@
"integrity": "sha1-bYCcnNDPe7iVLYD8hPoT1H3bEwg="
},
"deasync": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/deasync/-/deasync-0.1.19.tgz",
"integrity": "sha512-oh3MRktfnPlLysCPpBpKZZzb4cUC/p0aA3SyRGp15lN30juJBTo/CiD0d4fR+f1kBtUQoJj1NE9RPNWQ7BQ9Mg==",
"version": "0.1.20",
"resolved": "https://registry.npmjs.org/deasync/-/deasync-0.1.20.tgz",
"integrity": "sha512-E1GI7jMI57hL30OX6Ht/hfQU8DO4AuB9m72WFm4c38GNbUD4Q03//XZaOIHZiY+H1xUaomcot5yk2q/qIZQkGQ==",
"requires": {
"bindings": "^1.5.0",
"node-addon-api": "^1.7.1"
@@ -1101,9 +1101,12 @@
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"ejs": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.0.2.tgz",
"integrity": "sha512-IncmUpn1yN84hy2shb0POJ80FWrfGNY0cxO9f4v+/sG7qcBvAtVWUA1IdzY/8EYUmOVhoKJVdJjNd3AZcnxOjA=="
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.2.tgz",
"integrity": "sha512-zFuywxrAWtX5Mk2KAuoJNkXXbfezpNA0v7i+YC971QORguPekpjpAgeOv99YWSdKXwj7JxI2QAWDeDkE8fWtXw==",
"requires": {
"jake": "^10.6.1"
}
},
"emoji-regex": {
"version": "7.0.3",
@@ -1420,9 +1423,9 @@
}
},
"express-session": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.0.tgz",
"integrity": "sha512-t4oX2z7uoSqATbMfsxWMbNjAL0T5zpvcJCk3Z9wnPPN7ibddhnmDZXHfEcoBMG2ojKXZoCyPMc5FbtK+G7SoDg==",
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz",
"integrity": "sha512-UbHwgqjxQZJiWRTMyhvWGvjBQduGCSBDhhZXYenziMFjxst5rMV+aJZ6hKPHZnPyHGsrqRICxtX8jtEbm/z36Q==",
"requires": {
"cookie": "0.4.0",
"cookie-signature": "1.0.6",
@@ -1583,6 +1586,14 @@
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"filelist": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.1.tgz",
"integrity": "sha512-8zSK6Nu0DQIC08mUC46sWGXi+q3GGpKydAG36k+JDba6VRpkevvOWUW5a/PhShij4+vHT9M+ghgG7eM+a9JDUQ==",
"requires": {
"minimatch": "^3.0.4"
}
},
"finalhandler": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@@ -1973,6 +1984,11 @@
"integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=",
"optional": true
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"has-symbols": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
@@ -2373,6 +2389,42 @@
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
},
"jake": {
"version": "10.6.1",
"resolved": "https://registry.npmjs.org/jake/-/jake-10.6.1.tgz",
"integrity": "sha512-pHUK3+V0BjOb1XSi95rbBksrMdIqLVC9bJqDnshVyleYsET3H0XAq+3VB2E3notcYvv4wRdRHn13p7vobG+wfQ==",
"requires": {
"async": "0.9.x",
"chalk": "^2.4.2",
"filelist": "^1.0.1",
"minimatch": "^3.0.4"
},
"dependencies": {
"async": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
"integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"js-beautify": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.11.0.tgz",
@@ -2961,9 +3013,9 @@
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
},
"moment": {
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
"version": "2.25.3",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.25.3.tgz",
"integrity": "sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg=="
},
"moment-timezone": {
"version": "0.5.28",
@@ -2974,12 +3026,12 @@
}
},
"mongodb": {
"version": "3.5.5",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.5.tgz",
"integrity": "sha512-GCjDxR3UOltDq00Zcpzql6dQo1sVry60OXJY3TDmFc2SWFY6c8Gn1Ardidc5jDirvJrx2GC3knGOImKphbSL3A==",
"version": "3.5.7",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.7.tgz",
"integrity": "sha512-lMtleRT+vIgY/JhhTn1nyGwnSMmJkJELp+4ZbrjctrnBxuLbj6rmLuJFz8W2xUzUqWmqoyVxJLYuC58ZKpcTYQ==",
"requires": {
"bl": "^2.2.0",
"bson": "^1.1.1",
"bson": "^1.1.4",
"denque": "^1.4.1",
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2",
@@ -3005,15 +3057,15 @@
}
},
"mongoose": {
"version": "5.9.7",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.7.tgz",
"integrity": "sha512-WJOBh9WMvivqBK8my9HFtSzSySKdUxJPNGAwswEakAasWUcPXJl3yHMtZ4ngGnKbwTT9KnAr75xamlt/PouR9w==",
"version": "5.9.13",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.13.tgz",
"integrity": "sha512-MsFdJAaCTVbDA3gYskUEpUN1kThL7sp4zh8N9rGt0+9vYMn28q92NLK90vGssM9qjOGWp8HqLeT1fBgfMZDnKA==",
"requires": {
"bson": "~1.1.1",
"bson": "^1.1.4",
"kareem": "2.3.1",
"mongodb": "3.5.5",
"mongodb": "3.5.7",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.6.0",
"mpath": "0.7.0",
"mquery": "3.2.2",
"ms": "2.1.2",
"regexp-clone": "1.0.0",
@@ -3245,9 +3297,9 @@
"integrity": "sha1-mxnDdpeOIblF7Xd2eO2VTUt7VHU="
},
"mpath": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.6.0.tgz",
"integrity": "sha512-i75qh79MJ5Xo/sbhxrDrPSEG0H/mr1kcZXJ8dH6URU5jD/knFxCVqVC/gVSW7GIXL/9hHWlT9haLbCXWOll3qw=="
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz",
"integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg=="
},
"mqtt": {
"version": "1.14.1",
@@ -4592,9 +4644,9 @@
"integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4="
},
"sequelize": {
"version": "5.21.6",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.6.tgz",
"integrity": "sha512-RsgEpP2PP7txeoTWxoLLoe3xX8R2WYQAO7LNba2Ok3/pV5EFfKZry4fJXH56DUHJB909msMCHg0CJKDsQVbjcQ==",
"version": "5.21.8",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.8.tgz",
"integrity": "sha512-UOxGMJ7eSnProTMWX9wRr0T9TcuW0YedFmU7s+YBZT9/RmfJeANYPdJXjXg4E+Yg+dJl4WWvBEu9r2oe+d/1/Q==",
"requires": {
"bluebird": "^3.5.0",
"cls-bluebird": "^2.1.0",
@@ -5513,9 +5565,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"ws": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ=="
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
"integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w=="
},
"x-xss-protection": {
"version": "1.3.0",

View File

@@ -22,17 +22,17 @@
"cookie-auth": "^2.4.2",
"cookie-parser": "^1.4.5",
"cors": "2.8.5",
"deasync": "^0.1.19",
"ejs": "^3.0.2",
"deasync": "^0.1.20",
"ejs": "^3.1.2",
"express": "^4.8.7",
"express-ejs-layouts": "^2.5.0",
"express-namespace": "^0.1.1",
"express-session": "^1.17.0",
"express-session": "^1.17.1",
"got": "^10.7.0",
"helmet": "3.21.3",
"moment": "^2.24.0",
"moment": "^2.25.3",
"moment-timezone": "^0.5.13",
"mongoose": "^5.9.7",
"mongoose": "^5.9.13",
"morgan": "^1.10.0",
"mosca": "^2.8.3",
"mysql": "^2.18.1",
@@ -45,11 +45,11 @@
"passport-local": "^1.0.0",
"plaintextparser": "^1.0.3",
"request": "^2.88.2",
"sequelize": "^5.21.6",
"sequelize": "^5.21.8",
"sequelize-cli": "^5.5.1",
"swagger-ui-express": "^2.0.13",
"sync-request": "^4.0.2",
"vash": "^0.13.0",
"ws": "^7.2.3"
"ws": "^7.3.0"
}
}

View File

@@ -6,10 +6,11 @@ const got = require('got');
const request = require('request');
function GetDht() {
try {//?
var result;
(async () => {
try {
var ret = await got('http://192.168.1.126/cm?cmnd=status%2010');
var ret = await got('http://192.168.1.126/cm?cmnd=status%2010&user=admin&password=vlado555');
console.log("DHT: "+ util.inspect(ret.body));
var j = JSON.parse(ret.body);
console.log("JSON> " + util.inspect(j));
@@ -26,16 +27,20 @@ function GetDht() {
console.log(error);
}
})();
while(result === undefined) {
require('deasync').runLoopOnce();
}
while(result === undefined) {
require('deasync').runLoopOnce();
}
return result;
} catch(error){
console.log(error);
}
}
exports.SendCmd = function (url, cmd)
{
url = url +"/cm?cmnd=irsend%200,"+cmd;
url = url +"/cm?cmnd=irsend%200,"+cmd+"&user=admin&password=vlado555";
console.log("IR_SEND_RAW:" + url);
(async () => {
try {

View File

@@ -1,13 +1,15 @@
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<div id="now" class="form-text">getting inside conditions...</div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<%- contentFor('head') %>
<script>
var current;
window.onload = function () {
var temp = {in:[], out:[]};
var hum = {in:[], out:[],outSoil:[]};
var press = {out:[]};
var temp = { in: [], out: [], outDew:[] };
var hum = { in: [], out: [], outSoil: []};
var press = { out: [] };
var time = [];
/*{ x: new Date(2017, 0, 3), y: 650 },
{ x: new Date(2017, 0, 4), y: 700 },
*/
@@ -49,14 +51,20 @@
titleFontColor: "#C24642",
labelFontColor: "#C24642",
suffix: " °C",
minimum: -10,
// maximum: 40,
} , {
crosshair: {
enabled: true
},
//minimum: -10,
// maximum: 40,
}, {
title: "ATM Pressure",
lineColor: "#A477C6",
titleFontColor: "#A477C6",
labelFontColor: "#A477C6",
suffix: "hPa",
suffix: " hPa",
crosshair: {
enabled: true
},
minimum: 990,
//maximum: 1080,
},
@@ -68,7 +76,10 @@
labelFontColor: "#51CDA0",
minimum: 0,
maximum: 100,
suffix: "%",
suffix: " %",
crosshair: {
enabled: true
},
}
],
data: [{
@@ -80,13 +91,21 @@
color: "#F08080",
dataPoints: temp.out
},
/*{
name: "Dew Point",
type: "line",//line
showInLegend: true,
markerType: "none",
color: "#94D8F6",
dataPoints: temp.outDew
},*/
{
name: "In Temperature",
type: "line",//line
showInLegend: true,
//markerType: "square",
//xValueFormatString: "HH:mm on DD MMM, YYYY",
markerType: "none",
color: "#92D050",
lineThickness: 4,
dataPoints: temp.in
},
{
@@ -101,20 +120,21 @@
//----- sright axies -----
{
name: "Air RH",
axisYType: "secondary",//at right
axisYType: "secondary", //at right
//axisYIndex: 1,
type: "spline",
showInLegend: true,
lineDashType: "dash",
//lineDashType: "dash",
dataPoints: hum.out
},
{
{
name: "Soil RH",
axisYType: "secondary",
axisYIndex: 1,
type: "spline",
type: "line",
lineThickness: 4,
showInLegend: true,
lineDashType: "dash",
//lineDashType: "dash",
color: "#99D9EA",
dataPoints: hum.outSoil
}]
@@ -134,19 +154,20 @@
for (var i = 0; i < data.length; i++) {
var date = new Date(data[i]["timestamp"]);
if (data[i].field_name == "A23_Garden_dht") {
time.push(date);
var dht = JSON.parse(data[i].field_value);
hum.out.push({ x: date, y: parseFloat(dht.Hum) });
temp.out.push({ x: date, y: parseFloat(dht.Temp) });
press.out.push({ x: date, y: parseFloat(dht.Pres)});
temp.outDew.push({ x: date, y: parseFloat(dht.Temp) - ((parseFloat(dht.Hum))/5) });
press.out.push({ x: date, y: parseFloat(dht.Pres) });
if (dht.Soil) {
hum.outSoil.push({ x: date, y: parseFloat(dht.Soil) });
hum.outSoil.push({ x: date, y: parseFloat(dht.Soil) });
}
}
var date = new Date(data[i]["timestamp"]);
if(data[i].field_name == "A23_DHT"){
//console.log("Got DHT:" + date);
if (data[i].field_name == "A23_DHT") {
time.push(date);
var dht = JSON.parse(data[i].field_value).dht;
if(dht && dht.hum <= 100){
if (dht && dht.hum <= 100) {
hum.in.push({
x: date,
y: dht.hum
@@ -160,21 +181,28 @@
}
chart.render();
/*
$.getJSON("/n/dht?e=now", function(data){
if(data && data.dht){
chart.title.set("text", "Currently " + data.temp + "°C, " + data.hum +"% RH, ATM:" + data.press + "hPa");
}else {
chart.title.set("text", "Weather conditions");
}
});
*/
if (temp.out.length > 0 && hum.out.length > 0 && press.out.length > 0 && time.length > 0) {
//setTimeout(function(){
chart.title.set("text", "Out: " + temp.out[temp.out.length-1].y + "°C, "
+ hum.out[hum.out.length-1].y + "% RH, "
+ press.out[press.out.length-1].y + " hPa ("
+ time[time.length-1].toLocaleString() + ")");
//},5000);
}
chart.render();
}
$.getJSON("/n/device/A23_DHT/1", addData);
$.getJSON("/n/device/A23_Garden_dht/1", addData);
$.getJSON("/n/device/A23_DHT/7", addData);
$.getJSON("/n/device/A23_Garden_dht/7", addData);
setTimeout(function(){
$.getJSON("/n/dht?e=now", function(data){
if(data && data.dht){
$("#now").text("In A23 currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
}else {
$("#now").text("failed to get inside conditions" );
}
});
},5000);
}
</script>