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('dht');
// mqtt_client.subscribe('ir'); // mqtt_client.subscribe('ir');
mqtt_client.subscribe('ESP_Easy/+');
mqtt_client.subscribe('ESP_Easy/+/+'); mqtt_client.subscribe('ESP_Easy/+/+');
mqtt_client.publish('tasmota', 'controller connected') mqtt_client.publish('tasmota', 'controller connected')
}); });
@@ -246,11 +247,36 @@ mqtt_client.on('message', function (topic, message) {
} }
handled = true; 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(); 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) { // db.devicemessages.insert(1, "A23_Garden_Humidity", message, function (err, data) {
// if (!err) { console.log("success: "+ data);} // if (!err) { console.log("success: "+ data);}
// else { console.log("error: " + err); } // else { console.log("error: " + err); }
@@ -278,6 +304,15 @@ mqtt_client.on('message', function (topic, message) {
SaveDhtIf(); SaveDhtIf();
handled = true; 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){ if(!handled){
console.log(topic + " > " + message ); console.log(topic + " > " + message );
} }
@@ -285,11 +320,19 @@ mqtt_client.on('message', function (topic, message) {
function SaveDhtIf(){ function SaveDhtIf(){
if(dht.Temp && dht.Hum && dht.Pres && dht.Soil) 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) { db.devicemessages.insert(1, "A23_Garden_dht", JSON.stringify(dht), function (err, data) {
if (!err) { console.log("success: "+ data);} if (!err) { console.log("success: "+ data);}
else { console.log("error: " + err); } else { console.log("error: " + err); }
}); });
dht = {}; 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=" "integrity": "sha1-bYCcnNDPe7iVLYD8hPoT1H3bEwg="
}, },
"deasync": { "deasync": {
"version": "0.1.19", "version": "0.1.20",
"resolved": "https://registry.npmjs.org/deasync/-/deasync-0.1.19.tgz", "resolved": "https://registry.npmjs.org/deasync/-/deasync-0.1.20.tgz",
"integrity": "sha512-oh3MRktfnPlLysCPpBpKZZzb4cUC/p0aA3SyRGp15lN30juJBTo/CiD0d4fR+f1kBtUQoJj1NE9RPNWQ7BQ9Mg==", "integrity": "sha512-E1GI7jMI57hL30OX6Ht/hfQU8DO4AuB9m72WFm4c38GNbUD4Q03//XZaOIHZiY+H1xUaomcot5yk2q/qIZQkGQ==",
"requires": { "requires": {
"bindings": "^1.5.0", "bindings": "^1.5.0",
"node-addon-api": "^1.7.1" "node-addon-api": "^1.7.1"
@@ -1101,9 +1101,12 @@
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"ejs": { "ejs": {
"version": "3.0.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.0.2.tgz", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.2.tgz",
"integrity": "sha512-IncmUpn1yN84hy2shb0POJ80FWrfGNY0cxO9f4v+/sG7qcBvAtVWUA1IdzY/8EYUmOVhoKJVdJjNd3AZcnxOjA==" "integrity": "sha512-zFuywxrAWtX5Mk2KAuoJNkXXbfezpNA0v7i+YC971QORguPekpjpAgeOv99YWSdKXwj7JxI2QAWDeDkE8fWtXw==",
"requires": {
"jake": "^10.6.1"
}
}, },
"emoji-regex": { "emoji-regex": {
"version": "7.0.3", "version": "7.0.3",
@@ -1420,9 +1423,9 @@
} }
}, },
"express-session": { "express-session": {
"version": "1.17.0", "version": "1.17.1",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.0.tgz", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz",
"integrity": "sha512-t4oX2z7uoSqATbMfsxWMbNjAL0T5zpvcJCk3Z9wnPPN7ibddhnmDZXHfEcoBMG2ojKXZoCyPMc5FbtK+G7SoDg==", "integrity": "sha512-UbHwgqjxQZJiWRTMyhvWGvjBQduGCSBDhhZXYenziMFjxst5rMV+aJZ6hKPHZnPyHGsrqRICxtX8jtEbm/z36Q==",
"requires": { "requires": {
"cookie": "0.4.0", "cookie": "0.4.0",
"cookie-signature": "1.0.6", "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", "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==" "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": { "finalhandler": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@@ -1973,6 +1984,11 @@
"integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=", "integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=",
"optional": true "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": { "has-symbols": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", "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", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" "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": { "js-beautify": {
"version": "1.11.0", "version": "1.11.0",
"resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.11.0.tgz", "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.11.0.tgz",
@@ -2961,9 +3013,9 @@
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
}, },
"moment": { "moment": {
"version": "2.24.0", "version": "2.25.3",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", "resolved": "https://registry.npmjs.org/moment/-/moment-2.25.3.tgz",
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" "integrity": "sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg=="
}, },
"moment-timezone": { "moment-timezone": {
"version": "0.5.28", "version": "0.5.28",
@@ -2974,12 +3026,12 @@
} }
}, },
"mongodb": { "mongodb": {
"version": "3.5.5", "version": "3.5.7",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.5.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.7.tgz",
"integrity": "sha512-GCjDxR3UOltDq00Zcpzql6dQo1sVry60OXJY3TDmFc2SWFY6c8Gn1Ardidc5jDirvJrx2GC3knGOImKphbSL3A==", "integrity": "sha512-lMtleRT+vIgY/JhhTn1nyGwnSMmJkJELp+4ZbrjctrnBxuLbj6rmLuJFz8W2xUzUqWmqoyVxJLYuC58ZKpcTYQ==",
"requires": { "requires": {
"bl": "^2.2.0", "bl": "^2.2.0",
"bson": "^1.1.1", "bson": "^1.1.4",
"denque": "^1.4.1", "denque": "^1.4.1",
"require_optional": "^1.0.1", "require_optional": "^1.0.1",
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
@@ -3005,15 +3057,15 @@
} }
}, },
"mongoose": { "mongoose": {
"version": "5.9.7", "version": "5.9.13",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.7.tgz", "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.13.tgz",
"integrity": "sha512-WJOBh9WMvivqBK8my9HFtSzSySKdUxJPNGAwswEakAasWUcPXJl3yHMtZ4ngGnKbwTT9KnAr75xamlt/PouR9w==", "integrity": "sha512-MsFdJAaCTVbDA3gYskUEpUN1kThL7sp4zh8N9rGt0+9vYMn28q92NLK90vGssM9qjOGWp8HqLeT1fBgfMZDnKA==",
"requires": { "requires": {
"bson": "~1.1.1", "bson": "^1.1.4",
"kareem": "2.3.1", "kareem": "2.3.1",
"mongodb": "3.5.5", "mongodb": "3.5.7",
"mongoose-legacy-pluralize": "1.0.2", "mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.6.0", "mpath": "0.7.0",
"mquery": "3.2.2", "mquery": "3.2.2",
"ms": "2.1.2", "ms": "2.1.2",
"regexp-clone": "1.0.0", "regexp-clone": "1.0.0",
@@ -3245,9 +3297,9 @@
"integrity": "sha1-mxnDdpeOIblF7Xd2eO2VTUt7VHU=" "integrity": "sha1-mxnDdpeOIblF7Xd2eO2VTUt7VHU="
}, },
"mpath": { "mpath": {
"version": "0.6.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.6.0.tgz", "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz",
"integrity": "sha512-i75qh79MJ5Xo/sbhxrDrPSEG0H/mr1kcZXJ8dH6URU5jD/knFxCVqVC/gVSW7GIXL/9hHWlT9haLbCXWOll3qw==" "integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg=="
}, },
"mqtt": { "mqtt": {
"version": "1.14.1", "version": "1.14.1",
@@ -4592,9 +4644,9 @@
"integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4=" "integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4="
}, },
"sequelize": { "sequelize": {
"version": "5.21.6", "version": "5.21.8",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.6.tgz", "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.8.tgz",
"integrity": "sha512-RsgEpP2PP7txeoTWxoLLoe3xX8R2WYQAO7LNba2Ok3/pV5EFfKZry4fJXH56DUHJB909msMCHg0CJKDsQVbjcQ==", "integrity": "sha512-UOxGMJ7eSnProTMWX9wRr0T9TcuW0YedFmU7s+YBZT9/RmfJeANYPdJXjXg4E+Yg+dJl4WWvBEu9r2oe+d/1/Q==",
"requires": { "requires": {
"bluebird": "^3.5.0", "bluebird": "^3.5.0",
"cls-bluebird": "^2.1.0", "cls-bluebird": "^2.1.0",
@@ -5513,9 +5565,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"ws": { "ws": {
"version": "7.2.3", "version": "7.3.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==" "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w=="
}, },
"x-xss-protection": { "x-xss-protection": {
"version": "1.3.0", "version": "1.3.0",

View File

@@ -22,17 +22,17 @@
"cookie-auth": "^2.4.2", "cookie-auth": "^2.4.2",
"cookie-parser": "^1.4.5", "cookie-parser": "^1.4.5",
"cors": "2.8.5", "cors": "2.8.5",
"deasync": "^0.1.19", "deasync": "^0.1.20",
"ejs": "^3.0.2", "ejs": "^3.1.2",
"express": "^4.8.7", "express": "^4.8.7",
"express-ejs-layouts": "^2.5.0", "express-ejs-layouts": "^2.5.0",
"express-namespace": "^0.1.1", "express-namespace": "^0.1.1",
"express-session": "^1.17.0", "express-session": "^1.17.1",
"got": "^10.7.0", "got": "^10.7.0",
"helmet": "3.21.3", "helmet": "3.21.3",
"moment": "^2.24.0", "moment": "^2.25.3",
"moment-timezone": "^0.5.13", "moment-timezone": "^0.5.13",
"mongoose": "^5.9.7", "mongoose": "^5.9.13",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"mosca": "^2.8.3", "mosca": "^2.8.3",
"mysql": "^2.18.1", "mysql": "^2.18.1",
@@ -45,11 +45,11 @@
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"plaintextparser": "^1.0.3", "plaintextparser": "^1.0.3",
"request": "^2.88.2", "request": "^2.88.2",
"sequelize": "^5.21.6", "sequelize": "^5.21.8",
"sequelize-cli": "^5.5.1", "sequelize-cli": "^5.5.1",
"swagger-ui-express": "^2.0.13", "swagger-ui-express": "^2.0.13",
"sync-request": "^4.0.2", "sync-request": "^4.0.2",
"vash": "^0.13.0", "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'); const request = require('request');
function GetDht() { function GetDht() {
try {//?
var result; var result;
(async () => { (async () => {
try { 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)); console.log("DHT: "+ util.inspect(ret.body));
var j = JSON.parse(ret.body); var j = JSON.parse(ret.body);
console.log("JSON> " + util.inspect(j)); console.log("JSON> " + util.inspect(j));
@@ -26,16 +27,20 @@ function GetDht() {
console.log(error); console.log(error);
} }
})(); })();
while(result === undefined) { while(result === undefined) {
require('deasync').runLoopOnce(); require('deasync').runLoopOnce();
} }
return result; return result;
} catch(error){
console.log(error);
} }
}
exports.SendCmd = function (url, cmd) 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); console.log("IR_SEND_RAW:" + url);
(async () => { (async () => {
try { try {

View File

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