mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-01-26 20:26:17 +00:00
”2016-09-19”
This commit is contained in:
parent
5305418f5e
commit
cb7c38e6d4
@ -107,7 +107,9 @@ app.use(function(req, res, next) {
|
||||
|
||||
// Run npm start --production to use dist
|
||||
var staticDir = isProduction ? 'dist' : 'app';
|
||||
var graphFile = isProduction ? 'graph-release' : 'test';
|
||||
//var graphFile = isProduction ? 'graph-release' : 'test2';
|
||||
staticDir = 'app';
|
||||
var graphFile = 'test2';
|
||||
|
||||
app.use(express.static(path.join(__dirname, staticDir)));
|
||||
app.use(errorhandler({dumpExceptions: true, showStack: true}));
|
||||
|
1956
mdot/mDotServer.censis/mDotServer.censis/app/css/custom.css
Normal file
1956
mdot/mDotServer.censis/mDotServer.censis/app/css/custom.css
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,3 +3,23 @@
|
||||
|
||||
color:rgba(255,0,99,1);
|
||||
}
|
||||
|
||||
|
||||
[mui-row~="gutter--flush"],[data-mui-row~="gutter--flush"],[mui-row~="gutter"],[data-mui-row~="gutter"] {
|
||||
padding-left: 1em
|
||||
}
|
||||
|
||||
[mui-row~="gutter--flush"]>[mui-col],[data-mui-row~="gutter--flush"]>[mui-col],[mui-row~="gutter--flush"]>[data-mui-col],[data-mui-row~="gutter--flush"]>[data-mui-col],[mui-row~="gutter"]>[mui-col],[mui-row~="gutter"]>[data-mui-col],[data-mui-row~="gutter"]>[mui-col],[data-mui-row~="gutter"]>[data-mui-col] {
|
||||
padding-right: 1em
|
||||
}
|
||||
|
||||
[mui-row~="gutter--flush"],[data-mui-row~="gutter--flush"] {
|
||||
margin-left: -1em;
|
||||
margin-right: -1em
|
||||
}
|
||||
|
||||
|
||||
.spacer {
|
||||
margin-top: 15px;
|
||||
|
||||
}
|
||||
|
@ -139,7 +139,7 @@
|
||||
};
|
||||
|
||||
var minmaxesA = [
|
||||
{low:578,high:656, mp:617, count:1},
|
||||
{low:640,high:656, mp:617, count:1},
|
||||
{low:657,high:709, mp:695, count:2},
|
||||
{low:710,high:737, mp:723, count:3},
|
||||
{low:738,high:778, mp:752, count:4},
|
||||
@ -160,6 +160,8 @@
|
||||
skipOccupancy = true;
|
||||
}
|
||||
|
||||
skipOccupancy = true;
|
||||
|
||||
_(events.data).each(function(i) {
|
||||
var _occupancy = 0;
|
||||
|
||||
|
@ -2,6 +2,12 @@ var WEBSOCKET = function(model) {
|
||||
|
||||
var wsUrl = 'ws://localhost:3001';
|
||||
|
||||
if ('https:' === document.location.protocol) {
|
||||
wsUrl = 'wss://mdotserver.bluemix.net:3001';
|
||||
} else {
|
||||
wsUrl = 'ws://localhost:3001';
|
||||
}
|
||||
|
||||
this.socket = null;
|
||||
this.timer = 0;
|
||||
|
||||
|
16
mdot/mDotServer.censis/mDotServer.censis/custom.scss
Normal file
16
mdot/mDotServer.censis/mDotServer.censis/custom.scss
Normal file
@ -0,0 +1,16 @@
|
||||
@import "./src/bower_modules/mui/src/sass/mui/colors";
|
||||
|
||||
$mui-body-bg-color: mui-color('grey','900');
|
||||
$mui-input-font-color: mui-color('white');
|
||||
$mui-base-font-family: Ubuntu, Arial, Verdana, Tahoma !default;
|
||||
$mui-primary-color-dark: mui-color('grey','800');
|
||||
$mui-accent-color: #bad649;
|
||||
$mui-text-accent: mui-color('pink','A400');
|
||||
$mui-btn-accent-font-color: #004c6d;
|
||||
$mui-accent-color-dark: mui-color('green', 'A100');
|
||||
$mui-accent-color-light: mui-color('green', 'A400');
|
||||
$mui-tab-font-color: rgba(255, 255, 255, 0.87);
|
||||
|
||||
|
||||
// import MUI SASS
|
||||
@import "./src/bower_modules/mui/src/sass/mui";
|
@ -9,7 +9,7 @@
|
||||
|
||||
var pgp = require('pg-promise')();
|
||||
|
||||
var cn = {
|
||||
var localCN = {
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
database: 'mdot',
|
||||
@ -19,13 +19,15 @@ var cn = {
|
||||
|
||||
// ElephantSql settings
|
||||
|
||||
/*var cn = {
|
||||
var remoteCN = {
|
||||
host: 'jumbo.db.elephantsql.com',
|
||||
port: 5432,
|
||||
database: 'amlrxqev',
|
||||
user: 'amlrxqev',
|
||||
password: 'K11cvCplk0--oNafsYj4ISN-rVQmVS3y'
|
||||
};*/
|
||||
};
|
||||
|
||||
const cn = process.env.NODE_ENV === 'production' ? remoteCN : localCN;
|
||||
|
||||
|
||||
exports.dbConnection = pgp(cn);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
var WebSocketServer = require('websocket').server;
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
|
||||
var logger = require('log4js').getLogger();
|
||||
|
||||
|
@ -80,7 +80,7 @@
|
||||
"scripts": {
|
||||
"test": "mocha --recursive --reporter spec --bail --check-leaks --timeout 3000",
|
||||
"start": "node app.js",
|
||||
"prepublish": "gulp default"
|
||||
"prepublish": ""
|
||||
},
|
||||
"author": "Martin Donnelly",
|
||||
"license": "ISC",
|
||||
|
@ -19,6 +19,7 @@
|
||||
<style>
|
||||
html, body { height: 100%; width: 100%; margin: 0; font-family:ubuntu,sans-serif;}
|
||||
div { height: 100%; width: 100%; }
|
||||
.divfix { /*height: 100% !important;*/ }
|
||||
.mui-col-md-12 { height: 100%; width: 100%; }
|
||||
h1{
|
||||
|
||||
@ -122,7 +123,7 @@
|
||||
<body style="background-color:black">
|
||||
<div class="mui-container" style="width:100%; ">
|
||||
<div class='mui-row'style="width:100%">
|
||||
<div class="mui-col-md-3" style="padding:initial">
|
||||
<div class="mui-col-md-3" style="padding:initial;background-color:yellow;">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12 panel" style="height:15%; border-width:10px;border-style:solid;border-color:black; background-color:#404040">
|
||||
|
||||
@ -176,11 +177,11 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mui-col-md-9"style="padding:initial">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12 panel" style="height:70%; border-width:10px;border-style:solid;border-color:black; background-color:#404040;">
|
||||
<div class="mui-col-md-9 divfix" style="padding:initial">
|
||||
<div class="mui-row divfix">
|
||||
<div class="mui-col-md-12 panel divfix" style="height:70%; border-width:10px;border-style:solid;border-color:black; background-color:#404040;">
|
||||
|
||||
<div id="chartdiv" style="width:100%; background-color:#404040;"></div>
|
||||
<div class='divfix' id="chartdiv" style="width:100%; background-color:#404040;"></div>
|
||||
|
||||
|
||||
</div>
|
||||
|
394
mdot/mDotServer.censis/mDotServer.censis/views/test2.ejs
Normal file
394
mdot/mDotServer.censis/mDotServer.censis/views/test2.ejs
Normal file
@ -0,0 +1,394 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Graph</title>
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<!-- build:css -->
|
||||
<link rel="stylesheet" href="fonts/fonts.css"/>
|
||||
<link href="css/custom.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/test.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/style.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/weather-icons.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" href="css/notification.css">
|
||||
<link href="css/flatWeatherPlugin.css" rel="stylesheet"/>
|
||||
<!-- endbuild -->
|
||||
<style>
|
||||
html, body { height: 100%; width: 100%; color: white; }
|
||||
|
||||
h1 {
|
||||
|
||||
/*color: #FD5F00;*/
|
||||
/*color: #ff0063;*/
|
||||
font-family: 'Ubuntu Condensed';;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-size: 70px;
|
||||
font-variant: normal;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#example {
|
||||
position: relative;
|
||||
color: #ff0063;
|
||||
background: #00000;
|
||||
/*padding: 10px;
|
||||
margin: 30px auto;*/
|
||||
width: auto;
|
||||
border-radius: 1px;
|
||||
height: auto;
|
||||
font-size: xx-small;
|
||||
}
|
||||
|
||||
.item_content {
|
||||
height: 100px;
|
||||
/* border: 1px solid grey;*/
|
||||
min-height: 100px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.item_content a.title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.item_content div.body, .item_content div.site, .item_content div.tags {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #313131;
|
||||
}
|
||||
|
||||
.time, .date, .temp, .weather {
|
||||
text-align: center;
|
||||
font-family: 'Ubuntu Condensed', sans-serif;
|
||||
font-size: 40px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.time span.hour:after {
|
||||
content: ":";
|
||||
}
|
||||
|
||||
.time { margin-top: 10%; }
|
||||
|
||||
.date {
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
margin-top: 10%;
|
||||
min-height: 57px;
|
||||
height: 57px;
|
||||
}
|
||||
|
||||
.temp::after {
|
||||
content: "°c";
|
||||
}
|
||||
|
||||
.item_content div.tags {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.noConnection {
|
||||
color: rgb(244, 150, 26);
|
||||
}
|
||||
|
||||
#caltext {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.fourpcNudge {
|
||||
margin-top: 4% !important;
|
||||
}
|
||||
|
||||
.widget {
|
||||
height: 255px;
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
#chartdiv {
|
||||
height: 600px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 100%; width: 100%; margin-top: 0%
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mui-container" style="width:100%; ">
|
||||
<div class='mui-row'>
|
||||
<div class="mui-col-md-3">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12">
|
||||
<div class=" mui--bg-primary-dark " style="height:15%;">
|
||||
<img src="lib/images/SB_logo.png"
|
||||
style="height:70%; width:100%;margin-top:10%"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-12 spacer">
|
||||
<div class=" mui--bg-primary-dark " style="height:15%;">
|
||||
<div class='' id="main"></div>
|
||||
<!--<div id="output"></div>-->
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-12 spacer">
|
||||
<div class=" mui--bg-primary-dark " style="height:15%;">
|
||||
<div class="mui-col-xs-6 mui--bg-primary-dark">
|
||||
<div id="time"
|
||||
class="mui--text-center time mui--text-accent"></div>
|
||||
</div>
|
||||
<div class="mui-col-xs-6 mui--bg-primary-dark">
|
||||
<div id="date"
|
||||
class="mui--text-center date mui--text-accent"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-12 spacer">
|
||||
<div
|
||||
class=" mui--bg-primary-dark mui--text-center weather mui--text-accent"
|
||||
style="height:15%;">
|
||||
<div id="weatherIcon"
|
||||
class="mui-col-xs-6 mui--bg-primary-dark"></div>
|
||||
<div id="weatherText"
|
||||
class="mui-col-xs-6 mui--bg-primary-dark"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-12 spacer">
|
||||
<div
|
||||
class=" mui--bg-primary-dark mui--text-center weather mui--text-accent"
|
||||
style="height:15%;">
|
||||
<div id="censisLogo" class="mui-col-xs-12 mui--bg-primary-dark">
|
||||
<img src="lib/images/censis_logo_white.png"
|
||||
style="height:70%; width:80%;margin-top:5%;margin-left:10%"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-9 ">
|
||||
<div class="mui-row ">
|
||||
<div class="mui-col-md-12" style="height:70%;">
|
||||
<div class='divfix mui--bg-primary-dark' id="chartdiv"
|
||||
style="width:100%; margin-bottom: 15px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='mui-row'>
|
||||
<div class="mui-col-md-3">
|
||||
<div class=" mui--bg-primary-dark widget">
|
||||
<div style="height:40%">
|
||||
<img src="lib/images/CarbonDioxide.png" class="logo"/>
|
||||
</div>
|
||||
<div class="mui-row" style="height:50%;" id="widget-co2"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-3">
|
||||
<div class=" mui--bg-primary-dark widget">
|
||||
<div style="height:40%">
|
||||
<img src="lib/images/Temperature.png" class="logo"/>
|
||||
</div>
|
||||
<div class="mui-row" style="height:50%" id="widget-temp"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-3">
|
||||
<div class=" mui--bg-primary-dark widget">
|
||||
<div style="height:40%">
|
||||
<img src="lib/images/Humidity.png" class="logo"/>
|
||||
</div>
|
||||
<div class="mui-row" style="height:50%;" id="widget-humidity"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-3">
|
||||
<div class=" mui--bg-primary-dark widget">
|
||||
<div style="height:40%">
|
||||
<img src="lib/images/Lux.png" class="logo"/>
|
||||
</div>
|
||||
<div class="mui-row" style="height:100%;" id="widget-lux"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/template" id="loaded-template">
|
||||
<!--<div
|
||||
style="background-color: darkred;color: white;font-weight: 900;text-align: center">Loaded
|
||||
</div>-->
|
||||
</script>
|
||||
<script type="text/template" id="main-template">
|
||||
<div class="mui-select mui--bg-primary-dark mui--text-accent">
|
||||
<select id="device" name="device">
|
||||
<option>Select Room</option>
|
||||
<option>
|
||||
HIE-mobile-1
|
||||
</option>
|
||||
<option>
|
||||
HIE-demo
|
||||
</option>
|
||||
<option>
|
||||
HIE-mobile-2
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-1
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-2
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-3
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-4
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-5
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-6
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-7
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-1
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-2
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-3
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-4
|
||||
</option>
|
||||
<option>
|
||||
HIE-mDot-1
|
||||
</option>
|
||||
</select>
|
||||
</div><!--<div class="mui-row">
|
||||
<div class="mui-col-md-12">
|
||||
<button id='refresh'
|
||||
class="mui-btn mui-btn--small mui-btn--primary">Refresh
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>-->
|
||||
</script>
|
||||
<script type="text/template" id="list-template">
|
||||
|
||||
</script>
|
||||
<script type="text/template" id="item-template">
|
||||
<!--<div class="mui-row">
|
||||
<div class="mui-col-md-2"><%= item.timestamp %></div>
|
||||
<div class="mui-col-md-2"><%= item.lux %></div>
|
||||
<div class="mui-col-md-2"><%= item.co2 %></div>
|
||||
<div class="mui-col-md-2"><%= item.temp %></div>
|
||||
<div class="mui-col-md-2"><%= item.humidity %></div>
|
||||
<div class="mui-col-md-2"><%= item.sound %></div>
|
||||
</div>-->
|
||||
</script>
|
||||
<script type="text/template" id="AMChart-template">
|
||||
<!--<div class="mui-container">
|
||||
<div class="mui-row">
|
||||
<div class="mui-select mui-col-md-12">
|
||||
<select id="displaymode" name="displaymode">
|
||||
<option value="0"></option>
|
||||
<option value="1">
|
||||
Light
|
||||
</option>
|
||||
<option value="2">
|
||||
Temp
|
||||
</option>
|
||||
<option value="3">
|
||||
Co2
|
||||
</option>
|
||||
<option value="4">
|
||||
Humidity
|
||||
</option>
|
||||
<option value="5">
|
||||
Noise
|
||||
</option>
|
||||
<option value="6">
|
||||
Light & Co2
|
||||
</option>
|
||||
<option value="7">
|
||||
Temperature & Humidity
|
||||
</option>
|
||||
|
||||
</select> <label>Graph</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
</script>
|
||||
<script type="text/template" id="graph-template">
|
||||
<!--<div class="mui-container">
|
||||
<div class="mui-row">
|
||||
<div class="mui-select mui-col-md-6">
|
||||
<select id="displaymode" name="displaymode">
|
||||
<option value="0"></option>
|
||||
<option value="1">
|
||||
Light
|
||||
</option>
|
||||
<option value="2">
|
||||
Temp
|
||||
</option>
|
||||
<option value="3">
|
||||
Co2
|
||||
</option>
|
||||
<option value="4">
|
||||
Humidity
|
||||
</option>
|
||||
<option value="5">
|
||||
Noise
|
||||
</option>
|
||||
</select> <label>Graph</label>
|
||||
</div>
|
||||
<div class="mui-col-md-6">
|
||||
<svg id="graphSVG" width="300" height="150" fill="blue">
|
||||
<line x1="46" y1="12" x2="280" y2="12"
|
||||
style="stroke:#004c6d;stroke-width:2;"></line>
|
||||
<text id="maxY" x="36" y="15" text-anchor="end">--</text>
|
||||
<line x1="46" y1="136" x2="280" y2="136"
|
||||
style="stroke:#004c6d;stroke-width:2;"></line>
|
||||
<text id="MinY" x="36" y="139" text-anchor="end">0</text>
|
||||
<polyline id="line" fill="none" stroke="#2196F3" text-anchor="end"
|
||||
stroke-width="1" points=""></polyline>
|
||||
<g id="datapoints"></g>
|
||||
<g id="baseline"></g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
</script>
|
||||
<script type="text/template" id="widget-template">
|
||||
<h1 class="mui--text-accent"><%= value %></h1>
|
||||
</script>
|
||||
<!-- build:vendor -->
|
||||
<script src="lib/mui.js"></script>
|
||||
<script src="lib/notification.js"></script>
|
||||
<script src="lib/jquery.js"></script>
|
||||
<!--integrity="sha256-laXWtGydpwqJ8JA+X9x2miwmaiKhn8tVmOVEigRNtP4="
|
||||
crossorigin="anonymous"></script>-->
|
||||
<script src="lib/base64.js"></script>
|
||||
<script src="lib/underscore.js"></script>
|
||||
<script src="lib/backbone.js"></script>
|
||||
<script src="lib/sugar-date.js"></script>
|
||||
<script src="lib/notification.js"></script>
|
||||
<script src="lib/amcharts.js"></script>
|
||||
<script src="lib/serial.js"></script>
|
||||
<script src="lib/amstock.js"></script>
|
||||
<script src="lib/themes/dark.js"></script>
|
||||
<!--<script src="lib/jquery.flatWeatherPlugin.min.js"></script>-->
|
||||
<script src="lib/jquery.flatWeatherPlugin.js"></script>
|
||||
<!-- endbuild -->
|
||||
<!-- build:js -->
|
||||
<script src="js/clock.js"></script>
|
||||
<script src="js/websocket.js"></script>
|
||||
<script src="js/socketmanager.js"></script>
|
||||
<script src="js/mdot.js"></script>
|
||||
<!-- endbuild -->
|
||||
</body>
|
||||
</html>
|
@ -26,7 +26,6 @@ var mqtt = new mqttClient.mqttClient(busEmitter);
|
||||
|
||||
var historianApi = require('./lib/historian/emulator.js');
|
||||
|
||||
|
||||
var app = express();
|
||||
|
||||
var port = (process.env.VCAP_APP_PORT || 3010);
|
||||
@ -39,8 +38,23 @@ if (process.env.NODE_ENV === 'production') {
|
||||
isProduction = true;
|
||||
}
|
||||
|
||||
var restartTimer = 0;
|
||||
|
||||
logger.warn('isProduction:', isProduction);
|
||||
|
||||
var doRestart = () => {
|
||||
mqtt = new mqttClient.mqttClient(busEmitter);
|
||||
};
|
||||
|
||||
busEmitter.on('MAJORERROR', () => {
|
||||
'use strict';
|
||||
logger.warn('Major error discovered. Restarting MQTT Service in 10 seconds.');
|
||||
|
||||
clearTimeout(restartTimer);
|
||||
restartTimer = setTimeout(doRestart, 10000);
|
||||
|
||||
});
|
||||
|
||||
|
||||
var heartBeat = function() {
|
||||
console.log(this);
|
||||
|
44
mdot/mqttArchiver/mqttArchiver/lib/mailer.js
Normal file
44
mdot/mqttArchiver/mqttArchiver/lib/mailer.js
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
*
|
||||
* User: Martin Donnelly
|
||||
* Date: 2016-04-08
|
||||
* Time: 16:35
|
||||
*
|
||||
*/
|
||||
var UltraSES = require('ultrases'), dateFormat = require('dateformat');
|
||||
|
||||
var logger = require('log4js').getLogger();
|
||||
|
||||
var mailer = new UltraSES({
|
||||
aws: {
|
||||
accessKeyId: 'AKIAJWJS75F7WNCGK64A',
|
||||
secretAccessKey: '8irYxThCp4xxyrbr00HzWcODe2qdNrR7X7S5BKup',
|
||||
region: 'eu-west-1'
|
||||
}, defaults: {
|
||||
from: 'Martin Donnelly <martind2000@gmail.com>'
|
||||
}
|
||||
});
|
||||
|
||||
const prefix = process.env.NODE_ENV === 'production' ? 'Production' : 'Dev';
|
||||
|
||||
module.exports = {
|
||||
|
||||
sendEmailV1: function(contents) {
|
||||
var now = new Date();
|
||||
var email = {
|
||||
to: 'martind2000@gmail.com', subject: 'MQTT ' + prefix + ' Archiver Alert'
|
||||
};
|
||||
|
||||
var msg = '<h1>MQTT ' + prefix + ' Archiver Alert</h1><p>Alert logged at ' + dateFormat(now, "dddd, mmmm dS, yyyy, HH:MM:ss") + '</p><pre>' + contents + '</pre>';
|
||||
|
||||
mailer.sendHTML(email, msg, function(err){
|
||||
if(err) {
|
||||
logger.error(err);
|
||||
throw err;
|
||||
}
|
||||
logger.info('email sent!');
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
};
|
@ -1,3 +1,4 @@
|
||||
'use strict';
|
||||
var mqtt = require('mqtt');
|
||||
var logger = require('log4js').getLogger();
|
||||
|
||||
@ -10,17 +11,26 @@ var requestify = require('requestify');
|
||||
var db = require('../server/db-connector').dbConnection;
|
||||
|
||||
var dbSave = require('../server/db-save')(db);
|
||||
var emailer = require('../mailer');
|
||||
|
||||
//var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984');
|
||||
/*
|
||||
var nano = require('nano')('http://localhost:5984');
|
||||
var db_name = 'mqttarchive';
|
||||
var dbCouch = nano.use(db_name);
|
||||
*/
|
||||
|
||||
let remoteHost = process.env.NODE_ENV === 'production' ? 'http://mdotserver.mybluemix.net/apiv2/message' : 'http://localhost:3011/apiv2/message';
|
||||
|
||||
function dataBuilder(obj) {
|
||||
'use strict';
|
||||
|
||||
var now = new Date();
|
||||
var newObj = {device_type: 'mDot', evt_type: 'update', timestamp: {}, evt: {}};
|
||||
var newObj = {
|
||||
device_type: 'mDot',
|
||||
evt_type: 'update',
|
||||
timestamp: {},
|
||||
evt: {}
|
||||
};
|
||||
|
||||
newObj.device_id = obj.topic.split('/')[4];
|
||||
|
||||
@ -30,7 +40,6 @@ function dataBuilder(obj) {
|
||||
return newObj;
|
||||
}
|
||||
|
||||
|
||||
function saveToDB(data) {
|
||||
// logger.debug('Inserting into couch...');
|
||||
// Logger.info(util.inspect(obj));
|
||||
@ -45,28 +54,28 @@ function saveToDB(data) {
|
||||
|
||||
var doSendMessage = (obj) => {
|
||||
'use strict';
|
||||
requestify.post('http://localhost:3011/apiv2/message', obj)
|
||||
//requestify.post('http://mdotserver.mybluemix.net/apiv2/message', obj)
|
||||
.then(function(response) {
|
||||
// Get the response body
|
||||
// logger.debug(response.getBody());
|
||||
})
|
||||
|
||||
|
||||
requestify.post(remoteHost, obj)
|
||||
.then(function(response) {
|
||||
// Get the response body
|
||||
// logger.debug(response.getBody());
|
||||
})
|
||||
.catch(function(e) {
|
||||
logger.error('doSendMessage',e);
|
||||
logger.error('doSendMessage', e);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var doInsertEntry = (obj) => {
|
||||
// Logger.info('sendSocket: ' + JSON.stringify(obj));
|
||||
|
||||
// insertEntry(obj);
|
||||
// insertEntry(obj);
|
||||
|
||||
dbSave.addNewEvent(obj)
|
||||
.then(function(d) {
|
||||
'use strict';
|
||||
logger.info('Obj',obj.type);
|
||||
saveToDB(obj);
|
||||
// logger.info('Obj', obj.type);
|
||||
// saveToDB(obj);
|
||||
if (obj.type === 'mDot') {
|
||||
busEmitter.emit('sendMessage', obj);
|
||||
}
|
||||
@ -76,92 +85,106 @@ var doInsertEntry = (obj) => {
|
||||
logger.error(e);
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
var watchDog = 0;
|
||||
var watchDogTimeout = () => {
|
||||
'use strict';
|
||||
logger.warn(
|
||||
'Watchdog timeout. Message has not been received for over 90 seconds.');
|
||||
emailer.sendEmailV1('Watchdog timeout. Message has not been received for over 90 seconds.');
|
||||
};
|
||||
|
||||
|
||||
var mqttClient = function() {
|
||||
var count=0;
|
||||
var subscribeTopic;
|
||||
var orgId = 'qz0da4';
|
||||
var userName = 'a-qz0da4-dfwwdkmkzr';
|
||||
var address = '.messaging.internetofthings.ibmcloud.com';
|
||||
var appKey = '9txJEf3Cjy7hkSOvkv';
|
||||
|
||||
//Var subscribeTopic = prefix + deviceId + '/evt/+/fmt/json';
|
||||
var count = 0;
|
||||
var subscribeTopic;
|
||||
var orgId = 'qz0da4';
|
||||
var userName = 'a-qz0da4-dfwwdkmkzr';
|
||||
var address = '.messaging.internetofthings.ibmcloud.com';
|
||||
var appKey = '9txJEf3Cjy7hkSOvkv';
|
||||
|
||||
var connection = 'mqtt://' + orgId + address;
|
||||
|
||||
this.connected = false;
|
||||
this.connected = false;
|
||||
|
||||
var options = {
|
||||
keepalive: 10,
|
||||
clientId: 'a:' + orgId + ':' + Date.now(),
|
||||
username: userName,
|
||||
password: new Buffer(appKey),
|
||||
reconnectPeriod:1000,
|
||||
connectTimeout:30 * 1000
|
||||
var options = {
|
||||
keepalive: 10,
|
||||
clientId: 'a:' + orgId + ':' + Date.now(),
|
||||
username: userName,
|
||||
password: new Buffer(appKey),
|
||||
reconnectPeriod: 1000,
|
||||
connectTimeout: 30 * 1000
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
||||
logger.info('Connecting to ', connection);
|
||||
//this.client = mqtt.connect(connection, options);
|
||||
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
||||
|
||||
this.client.on('connect', function() {
|
||||
connected = true;
|
||||
logger.info('Connected to ', address);
|
||||
}.bind(this));
|
||||
this.client.on('connect', function() {
|
||||
// connected = true;
|
||||
logger.info('Connected to ', address);
|
||||
emailer.sendEmailV1('Connected to ' + address);
|
||||
}.bind(this));
|
||||
|
||||
this.client.on('connected', function() {
|
||||
logger.debug('mqttConnect - doConnection - Connected');
|
||||
logger.debug('mqttConnect - doConnection - Connected');
|
||||
|
||||
});
|
||||
watchDog = setTimeout(watchDogTimeout, 90000);
|
||||
console.log(watchDog);
|
||||
|
||||
});
|
||||
this.client.on('close', function() {
|
||||
logger.warn('mqttConnect - Connection closed');
|
||||
|
||||
});
|
||||
|
||||
this.client.on('offline', function() {
|
||||
logger.warn('mqttConnect - OFFLINE!');
|
||||
emailer.sendEmailV1('mqttConnect - OFFLINE!');
|
||||
});
|
||||
|
||||
|
||||
this.client.on('error', function(e) {
|
||||
logger.error('mqttConnect - error');
|
||||
logger.error(e);
|
||||
});
|
||||
|
||||
this.client.on('reconnect', function() {
|
||||
logger.warn('mqttConnect - Attempting to reconnect...');
|
||||
logger.warn('mqttConnect - Attempting to reconnect...');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
subscribeTopic = 'iot-2/type/+/id/+/evt/+/fmt/json';
|
||||
//subscribeTopic = 'livingroomTemp';
|
||||
logger.info('Subscribing:', subscribeTopic);
|
||||
|
||||
this.client.subscribe(subscribeTopic);
|
||||
|
||||
this.client.on('message', function(topic, message) {
|
||||
this.client.on('message', function(topic, message) {
|
||||
|
||||
var json = JSON.parse(message.toString());
|
||||
var json = JSON.parse(message.toString());
|
||||
|
||||
var topicArray = topic.split('/');
|
||||
json.topic = topic;
|
||||
json.type = topicArray[2];
|
||||
json.device = topicArray[4];
|
||||
json.event = topicArray[6];
|
||||
var topicArray = topic.split('/');
|
||||
json.topic = topic;
|
||||
json.type = topicArray[2];
|
||||
json.device = topicArray[4];
|
||||
json.event = topicArray[6];
|
||||
|
||||
busEmitter.emit('saveData', json);
|
||||
count++;
|
||||
busEmitter.emit('saveData', json);
|
||||
clearTimeout(watchDog);
|
||||
watchDog = setTimeout(watchDogTimeout, 20000);
|
||||
count++;
|
||||
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
|
||||
busEmitter.on('saveData', doInsertEntry);
|
||||
busEmitter.on('sendMessage', doSendMessage);
|
||||
busEmitter.on('saveData', doInsertEntry);
|
||||
busEmitter.on('sendMessage', doSendMessage);
|
||||
|
||||
this.getCount = function() {
|
||||
'use strict';
|
||||
return count;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports.mqttClient = mqttClient;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
var pgp = require('pg-promise')();
|
||||
|
||||
var cn = {
|
||||
var localCN = {
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
database: 'mqttstore',
|
||||
@ -19,15 +19,16 @@ var cn = {
|
||||
|
||||
// ElephantSql settings
|
||||
|
||||
/*
|
||||
var cn = {
|
||||
var remoteCN = {
|
||||
host: 'jumbo.db.elephantsql.com',
|
||||
port: 5432,
|
||||
database: 'vmlcokon',
|
||||
user: 'vmlcokon',
|
||||
password: 'PQUYLiIW4M6r7SWyZevrES_rRAULYFkp'
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
const cn = process.env.NODE_ENV === 'production' ? remoteCN : localCN;
|
||||
|
||||
|
||||
exports.dbConnection = pgp(cn);
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "mdot_mqtt",
|
||||
"name": "mqttArchiver",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
@ -14,6 +14,7 @@
|
||||
"body-parser": "^1.15.2",
|
||||
"cfenv": "1.0.x",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"dateformat": "^1.0.12",
|
||||
"ejs": "^2.5.1",
|
||||
"errorhandler": "^1.4.3",
|
||||
"events": "^1.1.1",
|
||||
@ -35,6 +36,7 @@
|
||||
"routes": "^2.1.0",
|
||||
"sugar": "^2.0.1",
|
||||
"sugar-date": "^2.0.0",
|
||||
"ultrases": "^0.1.3",
|
||||
"websocket": "^1.0.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -81,6 +83,6 @@
|
||||
"author": "Martin Donnelly <martind2000@gmail.com>",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": "5.7.0"
|
||||
"node": "6.0.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user