refactring & config object
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
{
|
||||
"development": {
|
||||
"username": "root",
|
||||
"password": "Zelen0ku4e",
|
||||
"database": "iot",
|
||||
"host": "127.0.0.1",
|
||||
"port":"3305",
|
||||
"port":"3306",
|
||||
"dialect": "mysql",
|
||||
"operatorsAliases": false
|
||||
"operatorsAliases": false,
|
||||
"logFile":"/dht.log"
|
||||
},
|
||||
"production": {
|
||||
"username": "iot",
|
||||
"password": "!iot_popovi",
|
||||
"database": "iot",
|
||||
"host": "localhost",
|
||||
"port":"3306",
|
||||
"dialect": "mysql",
|
||||
"operatorsAliases": false,
|
||||
"logFile":"/var/www/dht.log"
|
||||
}
|
||||
}
|
||||
|
||||
20
dht.js
20
dht.js
@@ -99,7 +99,10 @@ function(req, res){
|
||||
function(req, res){
|
||||
res.render('chart', { user: req.user });
|
||||
});
|
||||
app.get('/garden/:days?', function(req, res){ res.render('chartGarden', {model:req.params}); });
|
||||
|
||||
app.get('/garden/:days?', function(req, res){
|
||||
res.render('chartGarden', {model:req.params});
|
||||
});
|
||||
|
||||
//Authentication --
|
||||
|
||||
@@ -119,13 +122,13 @@ app.use('/waterTest',function(req, res){
|
||||
app.use('/water',function(req, res){
|
||||
var time = req.query.t;
|
||||
console.log("Watering cmd for: " + time);
|
||||
request('http://'+config.GardenIP+'/control?cmd=event,manualwatering='+ time, { json: true }, (err, res, body) => {
|
||||
request('http://'+config.GardenIP+'/tools?cmd=event,manualwatering='+ time, { json: true }, (err, res, body) => {
|
||||
if (err) { return console.log("Problem watering: " + err); }
|
||||
console.log("Watering cmd successfully sent!");
|
||||
});
|
||||
});
|
||||
app.use('/waterStop',function(req, res){
|
||||
request('http://'+config.GardenIP+'/control?cmd=event,stopwatering', { json: true }, (err, res, body) => {
|
||||
request('http://'+config.GardenIP+'/tools?cmd=event,stopwatering', { json: true }, (err, res, body) => {
|
||||
if (err) { return console.log("Problem watering: " + err); }
|
||||
console.log("STOP watering cmd sent!");
|
||||
});
|
||||
@@ -201,8 +204,11 @@ wss.on('connection', ws => {
|
||||
|
||||
var mosca = require('mosca');
|
||||
var mqtt_settings = {
|
||||
port:1883,
|
||||
secure : {
|
||||
port:1883
|
||||
}
|
||||
if(credentials)
|
||||
{
|
||||
mqtt_settings.secure = {
|
||||
port: 8444,
|
||||
keyPath: SECURE_KEY,
|
||||
certPath: SECURE_CERT,
|
||||
@@ -366,12 +372,14 @@ function SaveDhtIf(){
|
||||
console.log("Missing all data to write to DB !");
|
||||
}
|
||||
}
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const cfg = require(__dirname + '/config/config.json')[env];
|
||||
|
||||
(function() {
|
||||
var exLog = console.log;
|
||||
console.log = function(msg) {
|
||||
exLog.apply(this, arguments);
|
||||
fs.appendFileSync('/var/www/dht.log', msg +"\r\n");
|
||||
fs.appendFileSync(cfg.logFile, msg +"\r\n");
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
3333
package-lock.json
generated
3333
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
0
sqltools_20210716130107_17192.log
Normal file
0
sqltools_20210716130107_17192.log
Normal file
@@ -1,3 +1,6 @@
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../../config/config.json')[env];
|
||||
|
||||
|
||||
const Sequelize = require("sequelize");
|
||||
const mongoose = require('mongoose');
|
||||
@@ -14,7 +17,7 @@ let DevicesSchema = new Schema({
|
||||
});
|
||||
|
||||
|
||||
var sqlz = new Sequelize('iot', 'iot', '!iot_popovi',{dialect: 'mysql', logging: false});
|
||||
var sqlz = new Sequelize(config.database, config.username, config.password,{dialect: config.dialect, logging: false});
|
||||
var Device = sqlz.define('device', {
|
||||
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
|
||||
name: Sequelize.STRING,
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
//devicemessages
|
||||
var mysql = require('mysql');
|
||||
|
||||
|
||||
// const fs = require('fs');
|
||||
// const path = require('path');
|
||||
// const Sequelize = require('sequelize');
|
||||
// const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../../config/config.json')[env];
|
||||
|
||||
|
||||
var pool = mysql.createPool({
|
||||
connectionLimit : 20,
|
||||
host : 'localhost',
|
||||
user : 'iot',
|
||||
password : '!iot_popovi',
|
||||
database : 'iot'
|
||||
host : config.host,
|
||||
user : config.username,
|
||||
password : config.password,
|
||||
database : config.database
|
||||
});
|
||||
// var con = mysql.createConnection({
|
||||
// host : 'localhost',
|
||||
@@ -40,8 +50,8 @@ exports.findByName = function(fieldName, days, cb) {
|
||||
|
||||
exports.insert = function(device_id, field_name, value, cb){
|
||||
var params = [device_id, field_name,value];
|
||||
let sql = `INSERT INTO devicemessages(device_id,field_name,field_value,timestamp,createdAt,updatedAt )
|
||||
VALUES (?,?,?,NOW(),NOW(),NOW());`;
|
||||
let sql = `INSERT INTO devicemessages(device_id,field_name,field_value,timestamp)
|
||||
VALUES (?,?,?,NOW());`;
|
||||
pool.getConnection(function(err, con) {
|
||||
if (err) throw err; // not connected!
|
||||
con.query(sql,params,(err, r) => {
|
||||
|
||||
@@ -11,6 +11,7 @@ function GetDht() {
|
||||
var result;
|
||||
(async () => {
|
||||
try {
|
||||
//http://192.168.0.58/json?view=sensorupdate
|
||||
var url='http://'+'192.168.1.143'+'/cm?cmnd=status%2010&user=admin&password=vlado555';
|
||||
request(url, { json: true }, (err, res, body) => {
|
||||
if (err) { return console.log("Problem getting current conditions: " + err); }
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
var GardenIP = '192.168.0.18';
|
||||
var AcIP = '192.168.1.143';
|
||||
var HouseDhtIP = '192.168.1.126';
|
||||
var HomeControllerMQTT = '192.168.0.10'; //GW02
|
||||
var localPath = "/n";
|
||||
|
||||
module.exports = {
|
||||
GardenIP: '192.168.0.18',
|
||||
GardenIP: '192.168.0.58',
|
||||
AcIP : '192.168.1.143',
|
||||
HouseDhtIP : '192.168.1.126',
|
||||
HomeControllerMQTT : '192.168.0.10',
|
||||
localPath : "/n",
|
||||
HomeControllerMQTT : '192.168.0.10',//GW02
|
||||
localPath : "",
|
||||
foo: function () {
|
||||
// whatever
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user