mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-01-26 20:36:17 +00:00
”2016-08-25”
This commit is contained in:
parent
cbe4f1adc4
commit
86f9e3cc83
1
mdot/mdot_mqtt/mdot_mqtt/.cfignore
Normal file
1
mdot/mdot_mqtt/mdot_mqtt/.cfignore
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
15
mdot/mdot_mqtt/mdot_mqtt/.project
Normal file
15
mdot/mdot_mqtt/mdot_mqtt/.project
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>mdotserver</name>
|
||||
<comment>MQTT listener for mDot service</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.nodeclipse.ui.NodeNature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,18 +1,6 @@
|
||||
/**
|
||||
* Created by Martin on 08/02/2016.
|
||||
*/
|
||||
'use strict';
|
||||
var express = require('express');
|
||||
var path = require('path');
|
||||
var http = require('http');
|
||||
var ejs = require('ejs');
|
||||
var morgan = require('morgan');
|
||||
var cookieparser = require('cookie-parser');
|
||||
var session = require('express-session');
|
||||
var methodoverride = require('method-override');
|
||||
var bodyparser = require('body-parser');
|
||||
var errorhandler = require('errorhandler');
|
||||
var mqttConnect = require('./lib/mqtt/mqttConnect');
|
||||
var express = require('express'), http = require('http'), path = require('path'); var app = express();
|
||||
var cfenv = require('cfenv');
|
||||
|
||||
var log4js = require('log4js');
|
||||
var logger = log4js.getLogger();
|
||||
|
||||
@ -22,241 +10,20 @@ var WebSocketServer = require('websocket').server;
|
||||
var EventEmitter = require('events');
|
||||
var busEmitter = new EventEmitter();
|
||||
|
||||
var apn = require('apn');
|
||||
|
||||
require('sugar-date');
|
||||
var mqttClient = require('./lib/mqtt/mqttClient');
|
||||
|
||||
var calendar = require('./lib/office/officeController.js');
|
||||
var cal = new calendar.officeController(busEmitter);
|
||||
var mqtt = new mqttClient.mqttClient(busEmitter);
|
||||
|
||||
var lighting_v1 = require('./routes/lighting_v1');
|
||||
var heating_v1 = require('./routes/heating_v1');
|
||||
var projector_v1 = require('./routes/projector_v1');
|
||||
var isProduction = false;
|
||||
|
||||
|
||||
function restartTimer() {
|
||||
// Ibm / mqtt things go a bit weird if left on for too long so restart the server
|
||||
// at 7:30 ever morning before anyone is using it.
|
||||
var tom = Date.create('tomorrow at 7:30am');
|
||||
//app.get('/', routes.index);
|
||||
/*
|
||||
app.get("/cache/:key", cache.getCache);
|
||||
|
||||
var ms = tom.getTime() - Date.create('now').getTime();
|
||||
app.put("/cache", cache.putCache);
|
||||
app.delete("/cache/:key", cache.removeCache);
|
||||
|
||||
*/
|
||||
|
||||
console.log('Restarting in: ', ms);
|
||||
setTimeout(function() {process.exit(1);}, ms);
|
||||
|
||||
}
|
||||
mqttConnect.setEmitter(busEmitter);
|
||||
mqttConnect.doConnection();
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
isProduction = true;
|
||||
}
|
||||
|
||||
logger.debug('isProduction:', isProduction);
|
||||
|
||||
var app = express();
|
||||
|
||||
app.set('port', process.env.PORT || 4545);
|
||||
app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'ejs');
|
||||
app.use(morgan('combined'));
|
||||
app.use(cookieparser('your secret here'));
|
||||
app.use(session({
|
||||
secret: '1234567890QWERTY', resave: false, saveUninitialized: false
|
||||
}));
|
||||
/* 'default', 'short', 'tiny', 'dev' */
|
||||
app.use(methodoverride());
|
||||
|
||||
app.use(bodyparser.urlencoded({extended: false}));
|
||||
|
||||
// Parse application/json
|
||||
app.use(bodyparser.json());
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
|
||||
next();
|
||||
});
|
||||
|
||||
// Run npm start --production to use dist
|
||||
var staticDir = isProduction ? 'dist' : 'app';
|
||||
|
||||
app.use(express.static(path.join(__dirname, staticDir)));
|
||||
app.use(errorhandler({dumpExceptions: true, showStack: true}));
|
||||
|
||||
lighting_v1.use(mqttConnect);
|
||||
heating_v1.use(mqttConnect);
|
||||
projector_v1.use(mqttConnect);
|
||||
|
||||
// Calendar handler
|
||||
|
||||
busEmitter.on('lightingOn', lighting_v1.doLightsOn);
|
||||
busEmitter.on('lightingOff', lighting_v1.doLightsOff);
|
||||
|
||||
busEmitter.on('heatingOn', mqttConnect.heatingOn);
|
||||
busEmitter.on('heatingOff', mqttConnect.heatingOff);
|
||||
busEmitter.on('projectorOn', projector_v1.doProjectorOn);
|
||||
busEmitter.on('projectorOff', projector_v1.doProjectorOff);
|
||||
|
||||
|
||||
busEmitter.on('connectWS', mqttConnect.connectWS);
|
||||
busEmitter.on('restartMQTTSocket', mqttConnect.restartMQTTSocket);
|
||||
|
||||
mqttConnect.setupPing();
|
||||
cal.startController(busEmitter);
|
||||
|
||||
app.get('/stop', function(request, response) {
|
||||
cal.stopController();
|
||||
response.sendStatus(200);
|
||||
});
|
||||
|
||||
app.get('/start', function(request, response) {
|
||||
|
||||
cal.startController();
|
||||
response.sendStatus(200);
|
||||
});
|
||||
|
||||
app.get('/api/calendar', function(req, res) {
|
||||
var calJson = cal.returnCalendar();
|
||||
logger.info(calJson);
|
||||
res.json(calJson);
|
||||
});
|
||||
|
||||
app.post('/api/calendar/extend', function(req, res) {
|
||||
res.json({});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// Events and sockets
|
||||
|
||||
busEmitter.on('clientConnected', (socketSet) => {
|
||||
logger.info('-=-=-=-=-');
|
||||
logger.info(socketSet.getClientStatus());
|
||||
heating_v1.setsocket(socketSet).subscribe();
|
||||
lighting_v1.setsocket(socketSet).subscribe();
|
||||
projector_v1.setsocket(socketSet).subscribe();
|
||||
});
|
||||
|
||||
busEmitter.on('clientStatusUpdated', (v) => {
|
||||
logger.info(v);
|
||||
});
|
||||
|
||||
|
||||
|
||||
logger.info('Configuring WebSocket Listener...');
|
||||
var server = http.createServer(function(request, response) {
|
||||
logger.info((new Date()) + ' Received request for ' + request.url);
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
});
|
||||
|
||||
server.listen(3001, function() {
|
||||
logger.info((new Date()) + ' Server is listening on port 3001');
|
||||
});
|
||||
var wsServer = new WebSocketServer({
|
||||
httpServer: server, // You should not use autoAcceptConnections for production
|
||||
// applications, as it defeats all standard cross-origin protection
|
||||
// facilities built into the protocol and the browser. You should
|
||||
// *always* verify the connection's origin and decide whether or not
|
||||
// to accept it.
|
||||
autoAcceptConnections: false
|
||||
});
|
||||
|
||||
function originIsAllowed(origin) {
|
||||
// Put logic here to detect whether the specified origin is allowed.
|
||||
return true;
|
||||
}
|
||||
|
||||
wsServer.on('request', function(request) {
|
||||
|
||||
if (!originIsAllowed(request.origin)) {
|
||||
// Make sure we only accept requests from an allowed origin
|
||||
request.reject();
|
||||
logger.info((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
|
||||
return;
|
||||
}
|
||||
|
||||
var connection = request.accept('stream', request.origin);
|
||||
logger.info((new Date()) + ' Connection accepted.');
|
||||
|
||||
var sendSocketHandler = (obj) => {
|
||||
try {
|
||||
connection.sendUTF(JSON.stringify(obj));
|
||||
}
|
||||
catch (err) {
|
||||
logger.error(err);
|
||||
logger.warn('Offending object: ', obj);
|
||||
}
|
||||
};
|
||||
|
||||
busEmitter.on('sendSocket', sendSocketHandler);
|
||||
|
||||
connection.on('message', function(message) {
|
||||
if (message.type === 'utf8') {
|
||||
logger.info('Received Message: ' + message.utf8Data);
|
||||
connection.sendUTF(message.utf8Data);
|
||||
} else if (message.type === 'binary') {
|
||||
logger.info('Received Binary Message of ' + message.binaryData.length + ' bytes');
|
||||
connection.sendBytes(message.binaryData);
|
||||
}
|
||||
});
|
||||
|
||||
connection.on('close', function(reasonCode, description) {
|
||||
logger.info((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
|
||||
busEmitter.removeListener('sendSocket', sendSocketHandler);
|
||||
});
|
||||
});
|
||||
|
||||
mqttConnect.connectWS(function() {
|
||||
logger.info('Ready to plug in sockets...');
|
||||
});
|
||||
|
||||
app.post('/api/v1/lighting/off', lighting_v1.turnoff);
|
||||
app.post('/api/v1/lighting/on', lighting_v1.turnon);
|
||||
app.post('/api/v1/lighting/cmd', lighting_v1.command);
|
||||
|
||||
app.post('/api/v1/heating/off', heating_v1.turnoff);
|
||||
app.post('/api/v1/heating/on', heating_v1.turnon);
|
||||
|
||||
app.post('/api/v1/projector/off', projector_v1.turnoff);
|
||||
app.post('/api/v1/projector/on', projector_v1.turnon);
|
||||
app.post('/api/v1/projector/cmd', projector_v1.command);
|
||||
|
||||
app.post('/api/v1/register/ios', function(req, res) {
|
||||
|
||||
var body = req.body, registrationId;
|
||||
|
||||
logger.debug(body);
|
||||
|
||||
if (body.hasOwnProperty('registrationId')) {
|
||||
registrationId = body['registrationId'];
|
||||
logger.debug(registrationId);
|
||||
|
||||
cal.registeriOSToken(registrationId);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/v1/extend', function(req, res) {
|
||||
|
||||
var body = req.body, data;
|
||||
|
||||
if (body.hasOwnProperty('extendBy') && body.hasOwnProperty('uid')) {
|
||||
data = req.body;
|
||||
|
||||
cal.extendMeeting(data);
|
||||
res.sendStatus(200);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
app.listen(3000, function() {
|
||||
logger.info('Express listening on 3000');
|
||||
restartTimer();
|
||||
});
|
||||
http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); });
|
||||
|
@ -1,23 +1,14 @@
|
||||
var mqtt = require('mqtt');
|
||||
var request = require('request');
|
||||
var util = require('util');
|
||||
var logger = require('log4js').getLogger();
|
||||
|
||||
var EventEmitter = require('events');
|
||||
|
||||
//var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984');
|
||||
var nano = require('nano')('http://localhost:5984');
|
||||
var busEmitter = new EventEmitter();
|
||||
|
||||
var db_name = 'mdot';
|
||||
var dbCouch = nano.use(db_name);
|
||||
|
||||
var db = require('../server/db-connector').dbConnection;
|
||||
|
||||
var dbSave = require('../server/db-save')(db);
|
||||
|
||||
|
||||
|
||||
function dataBuilder(obj) {
|
||||
'use strict';
|
||||
var now = new Date();
|
||||
@ -84,7 +75,9 @@ var mqttClient = function() {
|
||||
var address = '.messaging.internetofthings.ibmcloud.com';
|
||||
var appKey = '9txJEf3Cjy7hkSOvkv';
|
||||
var prefix = 'iot-2/type/mDot/id/';
|
||||
var deviceId = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','HIE-mobile-2','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'];
|
||||
//var deviceId = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','HIE-mobile-2','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'];
|
||||
|
||||
var deviceId = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1----','HIE-mobile-2----','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'];
|
||||
|
||||
|
||||
//Var subscribeTopic = prefix + deviceId + '/evt/+/fmt/json';
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
var pgp = require('pg-promise')();
|
||||
|
||||
/*
|
||||
var cn = {
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
@ -16,6 +17,18 @@ var cn = {
|
||||
user: 'postgres',
|
||||
password: ''
|
||||
};
|
||||
*/
|
||||
|
||||
// ElephantSql settings
|
||||
|
||||
var cn = {
|
||||
host: 'qdjjtnkv.db.elephantsql.com',
|
||||
port: 5432,
|
||||
database: 'gxwxnqoh',
|
||||
user: 'gxwxnqoh',
|
||||
password: 'LN5Uk39GNcBCxCHv5dfL8aKuowFT6WKG'
|
||||
};
|
||||
|
||||
|
||||
exports.dbConnection = pgp(cn);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var newId = require('uuid-pure').newId;
|
||||
var atob = require('atob');
|
||||
|
||||
module.exports = function(db) {
|
||||
|
8
mdot/mdot_mqtt/mdot_mqtt/manifest.yml
Normal file
8
mdot/mdot_mqtt/mdot_mqtt/manifest.yml
Normal file
@ -0,0 +1,8 @@
|
||||
applications:
|
||||
- path: .
|
||||
memory: 256M
|
||||
instances: 1
|
||||
domain: mybluemix.net
|
||||
name: mdotmqtt
|
||||
host: mdotmqtt
|
||||
disk_quota: 1024M
|
@ -4,26 +4,22 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"atob": "^2.0.3",
|
||||
"body-parser": "^1.15.1",
|
||||
"cookie-parser": "*",
|
||||
"ejs": "*",
|
||||
"errorhandler": "*",
|
||||
"exec": "^0.2.1",
|
||||
"express": "^4.13.4",
|
||||
"express-session": "*",
|
||||
"htmlparser": "^1.7.7",
|
||||
"method-override": "*",
|
||||
"minibus": "^3.1.0",
|
||||
"morgan": "*",
|
||||
"cfenv": "1.0.x",
|
||||
"events": "^1.1.1",
|
||||
"express": "^4.14.0",
|
||||
"http": "0.0.0",
|
||||
"log4js": "^0.6.36",
|
||||
"mqtt": "^1.10.0",
|
||||
"mqtt_over_websockets": "0.0.1",
|
||||
"node-localstorage": "^1.1.2",
|
||||
"path": "^0.12.7",
|
||||
"pg-promise": "^5.2.7",
|
||||
"request": "^2.72.0",
|
||||
"routes": "^2.1.0",
|
||||
"websocket": "^1.0.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -36,7 +32,6 @@
|
||||
"clone": "^1.0.2",
|
||||
"del": "^2.2.0",
|
||||
"elapsed": "0.0.7",
|
||||
"events": "^1.1.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-autoprefixer": "^3.1.0",
|
||||
"gulp-cache": "^0.4.5",
|
||||
@ -58,7 +53,6 @@
|
||||
"gulp-uglify": "^2.0.0",
|
||||
"jshint": "^2.9.2",
|
||||
"jsonfile": "^2.3.1",
|
||||
"log4js": "^0.6.36",
|
||||
"mocha": "^3.0.2",
|
||||
"mqtt-ws": "^0.2.0",
|
||||
"nano": "^6.2.0",
|
||||
@ -72,5 +66,8 @@
|
||||
"supertest": "^2.0.0"
|
||||
},
|
||||
"author": "Martin Donnelly <martind2000@gmail.com>",
|
||||
"license": "ISC"
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": "5.7.0"
|
||||
}
|
||||
}
|
||||
|
2
mdot/mdot_server/mdot_server/.cfignore
Normal file
2
mdot/mdot_server/mdot_server/.cfignore
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
/sql/
|
15
mdot/mdot_server/mdot_server/.project
Normal file
15
mdot/mdot_server/mdot_server/.project
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>mdotserver</name>
|
||||
<comment>mDot server with MQTT</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.nodeclipse.ui.NodeNature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -21,19 +21,17 @@ var WebSocketServer = require('websocket').server;
|
||||
var EventEmitter = require('events');
|
||||
var busEmitter = new EventEmitter();
|
||||
|
||||
var apn = require('apn');
|
||||
// var apn = require('apn');
|
||||
|
||||
require('sugar-date');
|
||||
|
||||
var isProduction = false;
|
||||
|
||||
|
||||
var mdotApi = require('./lib/mdot/api.js');
|
||||
var mdotApiV2 = require('./lib/mdot/apiv2.js');
|
||||
var trackApi = require('./lib/mdot/track.js');
|
||||
var meetingApi = require('./lib/mdot/meeting.js');
|
||||
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
@ -69,6 +67,8 @@ app.use(function(req, res, next) {
|
||||
// Run npm start --production to use dist
|
||||
var staticDir = isProduction ? 'dist' : 'app';
|
||||
|
||||
staticDir = 'app';
|
||||
|
||||
app.use(express.static(path.join(__dirname, staticDir)));
|
||||
app.use(errorhandler({dumpExceptions: true, showStack: true}));
|
||||
|
||||
@ -86,9 +86,19 @@ mdotApiV2(app);
|
||||
trackApi(app);
|
||||
meetingApi(app);
|
||||
|
||||
//app.get('/api/mdot/:id', mDot.getData);
|
||||
|
||||
app.listen(3010, function() {
|
||||
logger.info('Express listening on 3010');
|
||||
var mqttClient = require('./lib/mqtt/mqttClient');
|
||||
|
||||
var mqtt;
|
||||
|
||||
if (isProduction) {
|
||||
mqtt = new mqttClient.mqttClient(busEmitter);
|
||||
}
|
||||
|
||||
var port = (process.env.VCAP_APP_PORT || 3010);
|
||||
var host = (process.env.VCAP_APP_HOST || 'localhost');
|
||||
|
||||
app.listen(port, function() {
|
||||
logger.info('Express listening on ',host, port);
|
||||
|
||||
});
|
||||
|
@ -47,20 +47,6 @@
|
||||
dataSetLux.dataProvider = chartData;
|
||||
dataSetLux.categoryField = "date";
|
||||
|
||||
/*
|
||||
{
|
||||
"date": "2016-08-10T11:27:21.000Z",
|
||||
"co2": 599,
|
||||
"humid": 42.7,
|
||||
"lux": 23,
|
||||
"noise": 1664,
|
||||
"temp": 21.7,
|
||||
"occupancy": 0
|
||||
},
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// set data sets to the chart
|
||||
chart.dataSets = [dataSetLux];
|
||||
|
||||
|
@ -14,21 +14,25 @@
|
||||
};
|
||||
|
||||
var sendAuthentication = function(xhr) {
|
||||
var user = 'a-qz0da4-dfwwdkmkzr'; // Your actual username
|
||||
var pass = '9txJEf3Cjy7hkSOvkv'; // Your actual password
|
||||
var user = mqttConfig.userName; // Your actual username
|
||||
var pass = mqttConfig.appKey; // Your actual password
|
||||
var token = user.concat(':', pass);
|
||||
xhr.setRequestHeader('Authorization', ('Basic '.concat(btoa(token))));
|
||||
|
||||
console.log('Auth:', ('Basic '.concat(btoa(token))));
|
||||
};
|
||||
|
||||
/*
|
||||
__ __ ___ ___ ___ _ ___
|
||||
| \/ |/ _ \| \| __| | / __|
|
||||
| |\/| | (_) | |) | _|| |__\__ \
|
||||
|_| |_|\___/|___/|___|____|___/
|
||||
*/
|
||||
|
||||
var MainModel = Backbone.Model.extend({});
|
||||
|
||||
var EventsModel = Backbone.Model.extend({
|
||||
initialize: function() {
|
||||
_.bindAll(this, 'processAdded');
|
||||
this.on('all', function(d) {
|
||||
console.log('model:all', d);
|
||||
this.temporal = {low: 0, high: 0};
|
||||
});
|
||||
this.on('remove', function() {
|
||||
$('#output').empty();
|
||||
});
|
||||
@ -43,11 +47,13 @@
|
||||
Get a branch from the date tree and see if the reduced set of records has a matching timestamp..
|
||||
*/
|
||||
let count = 0;
|
||||
let tsDate = new Date(ts);
|
||||
let tsMS = tsDate.getTime();
|
||||
let branch = this.dateTree[tsDate.getFullYear().toString()][tsDate.getMonth().toString()][tsDate.getDate().toString()];
|
||||
const tsDate = new Date(ts);
|
||||
const tsMS = tsDate.getTime();
|
||||
const branch = this.dateTree[tsDate.getFullYear().toString()][tsDate.getMonth().toString()][tsDate.getDate().toString()];
|
||||
|
||||
if (typeof branch === 'undefined') {return count;}
|
||||
if (typeof branch === 'undefined') {
|
||||
return count;
|
||||
}
|
||||
_(branch).each(function(item) {
|
||||
if ((tsMS >= item.startMS) && (tsMS <= item.endMS)) {
|
||||
count = item.count;
|
||||
@ -63,9 +69,9 @@
|
||||
*/
|
||||
var _tree = {};
|
||||
_(occupancy).each(function(item) {
|
||||
let newItem = item;
|
||||
const newItem = item;
|
||||
let day, month,year;
|
||||
let _date = new Date(item.start);
|
||||
const _date = new Date(item.start);
|
||||
|
||||
newItem.startMS = new Date(item.start).getTime();
|
||||
newItem.endMS = new Date(item.end).getTime();
|
||||
@ -102,9 +108,8 @@
|
||||
|
||||
|
||||
processAdded: function() {
|
||||
console.log('Model:ProcessAdded');
|
||||
console.time('processAdd');
|
||||
var skipOccupancy = false;
|
||||
console.time('processAdd');
|
||||
var tempCollection = new Backbone.Collection();
|
||||
|
||||
var events;
|
||||
@ -174,31 +179,31 @@
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
___ ___ _ _ ___ ___ _____ ___ ___ _ _ ___
|
||||
/ __/ _ \| | | | | __/ __|_ _|_ _/ _ \| \| / __|
|
||||
| (_| (_) | |__| |__| _| (__ | | | | (_) | .` \__ \
|
||||
\___\___/|____|____|___\___| |_| |___\___/|_|\_|___/
|
||||
|
||||
*/
|
||||
|
||||
var mDotCollection = Backbone.Collection.extend({
|
||||
model: EventsModel,
|
||||
url: 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/',
|
||||
initialize: function() {
|
||||
this.on('update', function() {
|
||||
|
||||
// Nothing
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var ItemView = Backbone.View.extend({
|
||||
tagName: 'div', className: 'item mui-container', initialize: function() {
|
||||
this.template = _.template($('#item-template').html());
|
||||
console.log('ItemView:Init');
|
||||
}, render: function() {
|
||||
|
||||
console.log('ItemView:Render');
|
||||
_(this.model.events).each(function(i) {
|
||||
this.$el.append(this.template({item: i}));
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
/*
|
||||
__ _____ _____ _____
|
||||
\ \ / /_ _| __\ \ / / __|
|
||||
\ V / | || _| \ \/\/ /\__ \
|
||||
\_/ |___|___| \_/\_/ |___/
|
||||
*/
|
||||
|
||||
var MDOT = Backbone.View.extend({
|
||||
model: EventsModel, el: $('#output'),
|
||||
@ -213,49 +218,41 @@
|
||||
}, refresh: function() {
|
||||
|
||||
}, update: function() {
|
||||
console.log('MDOT:update');
|
||||
this.collection.each(function(model) {
|
||||
|
||||
this.collection.each(function() {
|
||||
});
|
||||
|
||||
}, render: function() {
|
||||
console.log('MDOT:render');
|
||||
$('#output').empty();
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
var MainModel = Backbone.Model.extend({});
|
||||
|
||||
|
||||
var MainView = Backbone.View.extend({
|
||||
el: $('#main'), template: _.template($('#main-template').html()), events: {
|
||||
'change select#device': 'changeDevice',
|
||||
'click button#refresh': 'updateDevice',
|
||||
submit: function(event) {}
|
||||
submit: function() {
|
||||
// Catch the submit
|
||||
}
|
||||
|
||||
}, initialize: function() {
|
||||
_.bindAll(this, 'render', 'changeDevice', 'updateDevice');
|
||||
|
||||
this.model.on('change', this.updateDevice);
|
||||
console.log('MainView:', this);
|
||||
this.render();
|
||||
}, render: function() {
|
||||
$(this.el).html(this.template());
|
||||
return this;
|
||||
}, changeDevice: function() {
|
||||
var newDevice;
|
||||
console.log('MainView:ChangeDevice');
|
||||
newDevice = this.$el.find('#device')[0].value;
|
||||
|
||||
this.model.set('device', newDevice);
|
||||
}, updateDevice: function() {
|
||||
var fetchObj = {beforeSend: sendAuthentication};
|
||||
console.log('MainView:Updatedevice');
|
||||
notification.clearAll();
|
||||
if (this.model.has('device')) {
|
||||
this.collection.url = '/apiv2/mdot/' + this.model.get('device');
|
||||
|
||||
$('#output').empty();
|
||||
notification.notify('info', 'Loading...');
|
||||
this.collection.fetch(fetchObj);
|
||||
@ -281,18 +278,15 @@
|
||||
this.categoryAxesSettings = new AmCharts.CategoryAxesSettings();
|
||||
this.dataSet = new AmCharts.DataSet();
|
||||
|
||||
console.log('GraphView!');
|
||||
_.bindAll(this, 'render', 'updateGraphV2', 'setupChart');
|
||||
this.collection.on('update', function(d) {
|
||||
console.log('GraphView Collection update trigger!!');
|
||||
this.collection.on('update', function() {
|
||||
// Trigger the redraw
|
||||
this.updateGraphV2();
|
||||
}, this);
|
||||
|
||||
}, events: {
|
||||
'change select#displaymode': 'changeMode'
|
||||
}, setupChart: function() {
|
||||
console.log('chart:SetupChart');
|
||||
|
||||
this.categoryAxesSettings.minPeriod = 'mm';
|
||||
this.chart.categoryAxesSettings = this.categoryAxesSettings;
|
||||
|
||||
@ -301,157 +295,11 @@
|
||||
this.chart.dataSets = [this.dataSet];
|
||||
},
|
||||
|
||||
doChartV3: function(chartData) {
|
||||
var self = this;
|
||||
console.log('doChartV3');
|
||||
console.time('doChartV3');
|
||||
console.log(JSON.stringify(chartData));
|
||||
self.chart = AmCharts.makeChart( "chartdiv", {
|
||||
"type": "stock",
|
||||
"theme": "dark",
|
||||
"dataSets": [ {
|
||||
"fieldMappings": [
|
||||
{
|
||||
"fromField": "value",
|
||||
"toField": "value"
|
||||
} ],
|
||||
"color": "#0000ff",
|
||||
"dataProvider": chartData,
|
||||
"title": "West Stock",
|
||||
"categoryField": "date"
|
||||
}, {
|
||||
"fieldMappings": [ {
|
||||
"fromField": "lux",
|
||||
"toField": "lux"
|
||||
} ],
|
||||
"color": "#00ff00",
|
||||
"dataProvider": chartData,
|
||||
"compared": true,
|
||||
"title": "Eastr Stock",
|
||||
"categoryField": "date"
|
||||
} ],
|
||||
|
||||
|
||||
"panels": [ {
|
||||
"title": "Value",
|
||||
"showCategoryAxis": false,
|
||||
"percentHeight": 70,
|
||||
"luxAxes": [ {
|
||||
"id": "v1",
|
||||
"dashLength": 5
|
||||
} ],
|
||||
|
||||
"categoryAxis": {
|
||||
"dashLength": 5
|
||||
},
|
||||
|
||||
"stockGraphs": [ {
|
||||
"type": "line",
|
||||
"id": "g1",
|
||||
"openField": "open",
|
||||
"closeField": "close",
|
||||
"highField": "high",
|
||||
"lowField": "low",
|
||||
"valueField": "close",
|
||||
"lineColor": "#7f8da9",
|
||||
"fillColors": "#7f8da9",
|
||||
"negativeLineColor": "#db4c3c",
|
||||
"negativeFillColors": "#db4c3c",
|
||||
"fillAlphas": 1,
|
||||
"useDataSetColors": false,
|
||||
"comparable": true,
|
||||
"compareField": "value",
|
||||
"showBalloon": false,
|
||||
"proCandlesticks": true
|
||||
} ],
|
||||
|
||||
"stockLegend": {
|
||||
"valueTextRegular": undefined,
|
||||
"periodValueTextComparing": "[[percents.value.close]]%"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"title": "Volume",
|
||||
"percentHeight": 30,
|
||||
"marginTop": 1,
|
||||
"showCategoryAxis": true,
|
||||
"valueAxes": [ {
|
||||
"dashLength": 5
|
||||
} ],
|
||||
|
||||
"categoryAxis": {
|
||||
"dashLength": 5
|
||||
},
|
||||
|
||||
"stockGraphs": [ {
|
||||
"valueField": "volume",
|
||||
"type": "column",
|
||||
"showBalloon": false,
|
||||
"fillAlphas": 1
|
||||
} ],
|
||||
|
||||
"stockLegend": {
|
||||
"markerType": "none",
|
||||
"markerSize": 0,
|
||||
"labelText": "",
|
||||
"periodValueTextRegular": "[[value.close]]"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
"chartScrollbarSettings": {
|
||||
"graph": "g1",
|
||||
"graphType": "line",
|
||||
"usePeriod": "WW"
|
||||
},
|
||||
|
||||
"chartCursorSettings": {
|
||||
"valueLineBalloonEnabled": true,
|
||||
"valueLineEnabled": true
|
||||
},
|
||||
|
||||
"periodSelector": {
|
||||
"position": "bottom",
|
||||
"periods": [ {
|
||||
"period": "DD",
|
||||
"count": 10,
|
||||
"label": "10 days"
|
||||
}, {
|
||||
"period": "MM",
|
||||
"selected": true,
|
||||
"count": 1,
|
||||
"label": "1 month"
|
||||
}, {
|
||||
"period": "YYYY",
|
||||
"count": 1,
|
||||
"label": "1 year"
|
||||
}, {
|
||||
"period": "YTD",
|
||||
"label": "YTD"
|
||||
}, {
|
||||
"period": "MAX",
|
||||
"label": "MAX"
|
||||
} ]
|
||||
},
|
||||
"export": {
|
||||
"enabled": true
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
|
||||
$('#chartdiv').empty();
|
||||
self.chart.write('chartdiv');
|
||||
|
||||
console.timeEnd('doChartV3');
|
||||
},
|
||||
//DataProvider: chartData,
|
||||
doChartV2: function(chartData) {
|
||||
var self = this;
|
||||
console.time('doChartV2');
|
||||
self.chart = AmCharts.makeChart('chartdiv', {
|
||||
type: 'stock',
|
||||
type: 'serial',
|
||||
theme: 'light',
|
||||
|
||||
legend: {
|
||||
@ -498,18 +346,8 @@
|
||||
offset: 50,
|
||||
position: 'right',
|
||||
gridColor: '#556374'
|
||||
}/*,
|
||||
},
|
||||
{
|
||||
id: 'noise',
|
||||
axisColor: 'rgb(99, 157, 189)',
|
||||
axisThickness: 2,
|
||||
gridAlpha: 0,
|
||||
offset: 100,
|
||||
axisAlpha: 1,
|
||||
position: 'left',
|
||||
gridColor: '#556374'
|
||||
}*/
|
||||
,{
|
||||
id: 'occupancy',
|
||||
axisColor: '#aaaaaa',
|
||||
axisThickness: 2,
|
||||
@ -522,7 +360,7 @@
|
||||
],
|
||||
graphs: [{id: 'occ',
|
||||
valueAxis: 'occupancy',
|
||||
type: 'column',
|
||||
type: 'line',
|
||||
clustered: false,
|
||||
columnWidth: 1,
|
||||
lineColor: '#aaaaaa',
|
||||
@ -559,14 +397,7 @@
|
||||
title: 'Humidity',
|
||||
valueField: 'humid',
|
||||
fillAlphas: 0
|
||||
}/*,
|
||||
{
|
||||
valueAxis: 'noise',
|
||||
lineColor: 'rgb(99, 157, 189)',
|
||||
title: 'Sound',
|
||||
valueField: 'noise',
|
||||
fillAlphas: 0
|
||||
}*/
|
||||
}
|
||||
],
|
||||
chartScrollbar: {
|
||||
graph: 'occ',oppositeAxis: false,
|
||||
@ -622,10 +453,8 @@
|
||||
});
|
||||
});
|
||||
console.timeEnd('chartData');
|
||||
console.log('Record count:',chartData.length);
|
||||
|
||||
// Console.log(chartData);
|
||||
self.doChartV3(chartData);
|
||||
self.doChartV2(chartData);
|
||||
console.timeEnd('updateGraphV2');
|
||||
}
|
||||
|
||||
@ -635,17 +464,16 @@
|
||||
stacking: false
|
||||
});
|
||||
var DeviceCollection = new Backbone.Collection;
|
||||
var OccupancyCollection = new Backbone.Collection;
|
||||
|
||||
var mdotCollection = new mDotCollection();
|
||||
|
||||
var mainSettings = new MainModel();
|
||||
var mainview = new MainView({
|
||||
var views = {};
|
||||
views.mainview = new MainView({
|
||||
collection: mdotCollection, model: mainSettings
|
||||
});
|
||||
|
||||
var mdot = new MDOT({collection: mdotCollection});
|
||||
views.mdot = new MDOT({collection: mdotCollection});
|
||||
|
||||
var grapher = new GraphView({collection: DeviceCollection});
|
||||
views.grapher = new GraphView({collection: DeviceCollection});
|
||||
|
||||
})(jQuery);
|
||||
|
@ -11,7 +11,7 @@ module.exports = function(app) {
|
||||
var mdotRouter = express.Router();
|
||||
|
||||
mdotRouter.get('/:id', function(req, res) {
|
||||
console.log(req.headers);
|
||||
logger.debug(req.headers);
|
||||
|
||||
var data = {};
|
||||
logger.debug('mDot-GetData');
|
||||
@ -25,7 +25,7 @@ module.exports = function(app) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.query.hasOwnProperty('start') && req.query.hasOwnProperty('start')) {
|
||||
if (req.query.hasOwnProperty('start') && req.query.hasOwnProperty('end')) {
|
||||
data.start = req.query.start;
|
||||
data.end = req.query.end;
|
||||
}
|
||||
|
130
mdot/mdot_server/mdot_server/lib/mqtt/IoTFconnector.js
Normal file
130
mdot/mdot_server/mdot_server/lib/mqtt/IoTFconnector.js
Normal file
@ -0,0 +1,130 @@
|
||||
|
||||
|
||||
|
||||
var IoTFconnector = function (orgId, api_key, auth_token, $rootScope) {
|
||||
|
||||
|
||||
//this.connected = '';
|
||||
this.clientId = "a:" + orgId + ":" + Date.now();
|
||||
|
||||
console.log("clientId: " + this.clientId);
|
||||
this.hostname = orgId + ".messaging.internetofthings.ibmcloud.com";
|
||||
this.client = '';
|
||||
|
||||
this.initialize = function () {
|
||||
|
||||
client = new Messaging.Client(this.hostname, 8883, this.clientId);
|
||||
|
||||
|
||||
client.onMessageArrived = function (msg) {
|
||||
console.log("Message from :" + msg.destinationName);
|
||||
};
|
||||
|
||||
var connectOptions = new Object();
|
||||
connectOptions.keepAliveInterval = 3600;
|
||||
connectOptions.useSSL = true;
|
||||
connectOptions.userName = api_key;
|
||||
connectOptions.password = auth_token;
|
||||
|
||||
connectOptions.onSuccess = function () {
|
||||
IoTFconnector.prototype.clientStatus.connected = true;
|
||||
// $rootScope.$broadcast("clientStatusUpdated", clientStatus);
|
||||
console.log("MQTT connected to host: " + client.host + " port : " + client.port + " at " + Date.now());
|
||||
|
||||
}
|
||||
|
||||
connectOptions.onFailure = function (e) {
|
||||
console.log("MQTT connection failed at " + Date.now() + "\nerror: " + e.errorCode + " : " + e.errorMessage);
|
||||
}
|
||||
|
||||
console.log("about to connect to " + client.host);
|
||||
client.connect(connectOptions);
|
||||
|
||||
//client = new Messaging.Client(this.hostname, 8883, this.clientId);
|
||||
|
||||
//// Initialize the Realtime Graph
|
||||
////var rtGraph = new RealtimeGraph();
|
||||
//client.onMessageArrived = function(msg) {
|
||||
// //var topic = msg.destinationName;
|
||||
|
||||
// //var payload = JSON.parse(msg.payloadString);
|
||||
// ////First message, instantiate the graph
|
||||
// //if (firstMessage) {
|
||||
// // $('#chart').empty();
|
||||
// // firstMessage = false;
|
||||
// // rtGraph.displayChart(null, payload);
|
||||
// //} else {
|
||||
// // rtGraph.graphData(payload);
|
||||
// //}
|
||||
// console.log("Message from :" + msg.destinationName);
|
||||
//};
|
||||
|
||||
//client.onConnectionLost = function(e) {
|
||||
// console.log("Connection Lost at " + Date.now() + " : " + e.errorCode + " : " + e.errorMessage);
|
||||
// this.connect(connectOptions);
|
||||
//}
|
||||
|
||||
//var connectOptions = new Object();
|
||||
//connectOptions.keepAliveInterval = 3600;
|
||||
//connectOptions.useSSL = true;
|
||||
//connectOptions.userName = api_key;
|
||||
//connectOptions.password = auth_token;
|
||||
|
||||
//connectOptions.onSuccess = function() {
|
||||
// IoTFconnector.prototype.connected = true;
|
||||
// console.log("MQTT connected to host: " + client.host + " port : " + client.port + " at " + Date.now());
|
||||
|
||||
//}
|
||||
|
||||
//connectOptions.onFailure = function(e) {
|
||||
// console.log("MQTT connection failed at " + Date.now() + "\nerror: " + e.errorCode + " : " + e.errorMessage);
|
||||
//}
|
||||
|
||||
//console.log("about to connect to " + client.host);
|
||||
//client.connect(connectOptions);
|
||||
}
|
||||
|
||||
|
||||
this.initialize();
|
||||
|
||||
//var imageHTML = '<div class="iotdashboardtext">The selected device is not currently sending events to the Internet of Things Foundation</div><br><div class="iotdashboardtext">Select to view historical data or select a different device.</div> <img class="iotimagesMiddle" align="middle" alt="Chart" src="../../images/IOT_Icons_Thing02.svg">';
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
IoTFconnector.prototype.clientStatus = { connected: false, subscribeTopic: '' };;
|
||||
|
||||
IoTFconnector.prototype.disconnect = function disconnect() {
|
||||
client.disconnect();
|
||||
console.log("Connection closed");
|
||||
}
|
||||
|
||||
IoTFconnector.prototype.connect = function connect() {
|
||||
// this.initialize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
IoTFconnector.prototype.subscribe = function subscribe(deviceId) {
|
||||
var subscribeOptions = {
|
||||
qos: 0,
|
||||
onSuccess: function () {
|
||||
console.log("subscribed to " + IoTFconnector.prototype.clientStatus.subscribeTopic);
|
||||
},
|
||||
onFailure: function () {
|
||||
console.log("Failed to subscribe to " + IoTFconnector.prototype.clientStatus.subscribeTopic);
|
||||
console.log("As messages are not available, visualization is not possible");
|
||||
}
|
||||
};
|
||||
|
||||
if (IoTFconnector.prototype.clientStatus.subscribeTopic != "") {
|
||||
console.log("Unsubscribing to " + IoTFconnector.prototype.clientStatus.subscribeTopic);
|
||||
client.unsubscribe(IoTFconnector.prototype.clientStatus.subscribeTopic);
|
||||
};
|
||||
|
||||
IoTFconnector.prototype.clientStatus.subscribeTopic = "iot-2/type/iotsample-ti-cc3200/id/" + deviceId + "/evt/+/fmt/json";
|
||||
|
||||
client.subscribe(IoTFconnector.prototype.clientStatus.subscribeTopic, subscribeOptions);
|
||||
}
|
150
mdot/mdot_server/mdot_server/lib/mqtt/mqttClient.js
Normal file
150
mdot/mdot_server/mdot_server/lib/mqtt/mqttClient.js
Normal file
@ -0,0 +1,150 @@
|
||||
var mqtt = require('mqtt');
|
||||
var logger = require('log4js').getLogger();
|
||||
|
||||
var EventEmitter = require('events');
|
||||
|
||||
var busEmitter = new EventEmitter();
|
||||
|
||||
var db = require('../server/db-connector').dbConnection;
|
||||
|
||||
var dbSave = require('../server/db-save')(db);
|
||||
|
||||
function dataBuilder(obj) {
|
||||
'use strict';
|
||||
var now = new Date();
|
||||
var newObj = {device_type: 'mDot', evt_type: 'update', timestamp: {}, evt: {}};
|
||||
|
||||
newObj.device_id = obj.topic.split('/')[4];
|
||||
|
||||
newObj.evt = obj;
|
||||
newObj.timestamp['$date'] = now.getTime();
|
||||
|
||||
return newObj;
|
||||
}
|
||||
|
||||
function insertEntry(obj) {
|
||||
|
||||
var newObj = dataBuilder(obj);
|
||||
|
||||
newObj.rtype = 1;
|
||||
|
||||
logger.debug('Inserting into couch...');
|
||||
// logger.info(util.inspect(newObj));
|
||||
dbCouch.insert(newObj, function(err, body, header) {
|
||||
if (err) {
|
||||
logger.error('Error inserting into couch');
|
||||
return;
|
||||
}
|
||||
});
|
||||
logger.debug('Insert done..');
|
||||
}
|
||||
|
||||
var doInsertEntry = (obj) => {
|
||||
// Logger.info('sendSocket: ' + JSON.stringify(obj));
|
||||
|
||||
// insertEntry(obj);
|
||||
|
||||
dbSave.addNewEvent(obj)
|
||||
.then(function(d) {
|
||||
'use strict';
|
||||
logger.info('Finished - Raw',d);
|
||||
})
|
||||
.catch(function(e) {
|
||||
'use strict';
|
||||
logger.error(e);
|
||||
});
|
||||
|
||||
|
||||
dbSave.addProcessedEvent(obj)
|
||||
.then(function(d) {
|
||||
'use strict';
|
||||
logger.info('Finished - Processed',d);
|
||||
})
|
||||
.catch(function(e) {
|
||||
'use strict';
|
||||
logger.error(e);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var mqttClient = function() {
|
||||
|
||||
var subscribeTopic;
|
||||
var orgId = 'qz0da4';
|
||||
var userName = 'a-qz0da4-dfwwdkmkzr';
|
||||
var address = '.messaging.internetofthings.ibmcloud.com';
|
||||
var appKey = '9txJEf3Cjy7hkSOvkv';
|
||||
var prefix = 'iot-2/type/mDot/id/';
|
||||
//var deviceId = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','HIE-mobile-2','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'];
|
||||
|
||||
var deviceId = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1----','HIE-mobile-2----','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'];
|
||||
|
||||
|
||||
//Var subscribeTopic = prefix + deviceId + '/evt/+/fmt/json';
|
||||
|
||||
|
||||
this.connected = false;
|
||||
|
||||
var options = {
|
||||
keepalive: 3600,
|
||||
clientId: 'a:' + orgId + ':' + Date.now(),
|
||||
username: userName,
|
||||
password: new Buffer(appKey)
|
||||
|
||||
};
|
||||
|
||||
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
||||
|
||||
this.client.on('connect', function() {
|
||||
connected = true;
|
||||
logger.info('Connected to ', address);
|
||||
}.bind(this));
|
||||
|
||||
|
||||
for (var t = 0;t < deviceId.length;t++) {
|
||||
subscribeTopic = prefix + deviceId[t] + '/evt/+/fmt/json';
|
||||
logger.info('Subscribing:', subscribeTopic);
|
||||
this.client.subscribe(subscribeTopic);
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.client.on('message', function(topic, message) {
|
||||
console.log('onMessage',topic);
|
||||
|
||||
var json = JSON.parse(message.toString());
|
||||
|
||||
json.topic = topic;
|
||||
// logger.debug(JSON.stringify(json));
|
||||
|
||||
busEmitter.emit('saveData', json);
|
||||
|
||||
}.bind(this));
|
||||
|
||||
this.isConnected = function() {
|
||||
|
||||
return this.connected;
|
||||
};
|
||||
|
||||
this.client.on('connected', function() {
|
||||
logger.debug('mqttConnect - doConnection - Connected');
|
||||
|
||||
});
|
||||
this.client.on('disconnect', function(e) {
|
||||
logger.error('mqttConnect - doConnection - disconnect');
|
||||
logger.error(e);
|
||||
});
|
||||
this.client.on('error', function(e) {
|
||||
logger.error('mqttConnect - doConnection - disconnect');
|
||||
logger.error(e);
|
||||
});
|
||||
|
||||
|
||||
busEmitter.on('saveData', doInsertEntry);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports.mqttClient = mqttClient;
|
353
mdot/mdot_server/mdot_server/lib/mqtt/mqttConnect.js
Normal file
353
mdot/mdot_server/mdot_server/lib/mqtt/mqttConnect.js
Normal file
@ -0,0 +1,353 @@
|
||||
/**
|
||||
* Created by Martin on 08/02/2016.
|
||||
*/
|
||||
'use strict';
|
||||
var mqtt = require('mqtt');
|
||||
|
||||
var Messaging = require('mqtt_over_websockets');
|
||||
var log4js = require('log4js');
|
||||
var logger = log4js.getLogger();
|
||||
|
||||
var mqttConfig = {
|
||||
orgId: 'qz0da4',
|
||||
userName: 'martind2000',
|
||||
appKey: 'MPReoa43',
|
||||
prefix: 'iot-2/type/Ti-CC3200/id/'
|
||||
};
|
||||
|
||||
function randomString(length) {
|
||||
return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
|
||||
}
|
||||
|
||||
/*
|
||||
Projector: 'ProjectorISP15',
|
||||
lighting: 'LightingISP15',
|
||||
heating: 'HeatingISP15',
|
||||
|
||||
*/
|
||||
var live = true;
|
||||
|
||||
logger.warn('!!! Live? ', live);
|
||||
module.exports = {
|
||||
restartTimer : 0,
|
||||
pingTimer: 0,
|
||||
statuses: {},
|
||||
sockets: null,
|
||||
wsClient: null,
|
||||
watches: {},
|
||||
client: null,
|
||||
projector: live ? 'Projector' : 'ProjectorISP15',
|
||||
lighting: live ? 'Lighting' : 'LightingISP15',
|
||||
heating: live ? 'Heating' : 'HeatingISP15',
|
||||
myID: 0,
|
||||
connected: false,
|
||||
options: {
|
||||
// Keepalive: 3600,
|
||||
keepalive: 60,
|
||||
clientId: 'a:' + mqttConfig.orgId + ':' + Date.now(),
|
||||
username: mqttConfig.userName,
|
||||
password: new Buffer(mqttConfig.appKey)
|
||||
|
||||
},
|
||||
lightList: {o: 'frontLight', f: 'frontLight',n: 'backLight', g: 'backLight'},
|
||||
updateStatus: function(id, packet) {
|
||||
this.statuses[id] = packet;
|
||||
logger.info('Statuses:', this.statuses);
|
||||
},
|
||||
|
||||
setEmitter: function(newEmitter) {
|
||||
this.emitter = newEmitter;
|
||||
},
|
||||
doConnection: function(cb) {
|
||||
console.log('Do connection');
|
||||
var self = this;
|
||||
if (this.client === null) {
|
||||
this.client = mqtt.connect('mqtt://' + 'silvrtree.co.uk', this.options);
|
||||
|
||||
this.client.on('connect', function() {
|
||||
logger.info('Connected to SilvrBroker');
|
||||
self.connected = this.connected;
|
||||
});
|
||||
this.client.on('connected', function() {
|
||||
logger.debug('mqttConnect - doConnection - Connected');
|
||||
|
||||
});
|
||||
this.client.on('disconnect', function(e) {
|
||||
logger.error('mqttConnect - doConnection - disconnect');
|
||||
logger.error(e);
|
||||
});
|
||||
this.client.on('error', function(e) {
|
||||
logger.error('mqttConnect - doConnection - disconnect');
|
||||
logger.error(e);
|
||||
});
|
||||
|
||||
}
|
||||
return this;
|
||||
},
|
||||
isConnected: function() {
|
||||
return this.connected;
|
||||
},
|
||||
sendCommand: function(deviceID, command) {
|
||||
var payload = {
|
||||
id: 'd',
|
||||
text: command
|
||||
|
||||
};
|
||||
},
|
||||
projectorOn: function(callback) {
|
||||
var packet;
|
||||
console.log('projectorOn:');
|
||||
var _callback = callback || {};
|
||||
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
packet = {id: this.projector, status: true};
|
||||
var destinationName = mqttConfig.prefix + this.projector + '/cmd/' + 'ON' + '/fmt/json';
|
||||
this.client.publish(destinationName, 'ON', _callback);
|
||||
this.emitter.emit('sendSocket',packet);
|
||||
logger.debug('Storing status...');
|
||||
this.updateStatus('projector', packet);
|
||||
},
|
||||
projectorOff: function(callback) {
|
||||
var packet;
|
||||
var _callback = callback || {};
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
packet = {id: this.projector, status: false};
|
||||
var destinationName = mqttConfig.prefix + this.projector + '/cmd/' + 'OFF' + '/fmt/json';
|
||||
this.client.publish(destinationName, 'OFF', _callback);
|
||||
this.emitter.emit('sendSocket',packet);
|
||||
console.log('Storing status...');
|
||||
this.updateStatus('projector', packet);
|
||||
|
||||
},
|
||||
projectorCmd: function(id, callback) {
|
||||
var packet;
|
||||
var _callback = callback || {};
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var destinationName = mqttConfig.prefix + this.projector + '/cmd/' + id + '/fmt/json';
|
||||
this.client.publish(destinationName, 'cmd', _callback);
|
||||
},
|
||||
heatingOn: function(callback) {
|
||||
console.log('Turn heating on...');
|
||||
var _callback = callback || null;
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
var destinationName = mqttConfig.prefix + this.heating + '/cmd/' + 'on' + '/fmt/json';
|
||||
this.client.publish(destinationName, 'ON', _callback);
|
||||
this.emitter.emit('sendSocket',{id: this.heating, status: true});
|
||||
},
|
||||
heatingOff: function(callback) {
|
||||
var _callback = callback || {};
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
var destinationName = mqttConfig.prefix + this.heating + '/cmd/' + 'off' + '/fmt/json';
|
||||
this.client.publish(destinationName, 'OFF', _callback);
|
||||
this.emitter.emit('sendSocket',{id: this.heating, status: false});
|
||||
},
|
||||
lightingOn: function(id, callback) {
|
||||
var packet;
|
||||
|
||||
console.log('lightingOn:' + id);
|
||||
var _callback = callback || null;
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
var destinationName = mqttConfig.prefix + this.lighting + '/cmd/' + id + '/fmt/json';
|
||||
this.client.publish(destinationName, 'ON', _callback);
|
||||
packet = {id: this.lighting, device: id, status: true};
|
||||
this.emitter.emit('sendSocket',packet);
|
||||
logger.debug('Storing status...');
|
||||
this.updateStatus(this.lightList[id], packet);
|
||||
},
|
||||
lightingOff: function(id, callback) {
|
||||
var packet;
|
||||
var _callback = callback || null;
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
var destinationName = mqttConfig.prefix + this.lighting + '/cmd/' + id + '/fmt/json';
|
||||
this.client.publish(destinationName, 'OFF', _callback);
|
||||
packet = {id: this.lighting, device: id, status: false};
|
||||
this.emitter.emit('sendSocket', packet);
|
||||
this.updateStatus(this.lightList[id], packet);
|
||||
},
|
||||
lightingCommand: function(id, callback) {
|
||||
var packet;
|
||||
var _callback = callback || null;
|
||||
if (!this.client) {
|
||||
return -1;
|
||||
}
|
||||
var destinationName = mqttConfig.prefix + this.lighting + '/cmd/' + id + '/fmt/json';
|
||||
this.client.publish(destinationName, 'cmd', _callback);
|
||||
},
|
||||
|
||||
setupEvents: function() {
|
||||
|
||||
this.emitter.on('lightingOn', this.lightingOn);
|
||||
this.emitter.on('lightingOff', this.lightingOff);
|
||||
this.emitter.on('heatingOn', this.heatingOn);
|
||||
this.emitter.on('heatingOff', this.heatingOff);
|
||||
this.emitter.on('projectorOn', this.projectorOn);
|
||||
this.emitter.on('projectorOff', this.projectorOff);
|
||||
},
|
||||
setupPing: function() {
|
||||
logger.warn('Starting ping timer...');
|
||||
|
||||
this.pingTimer = setTimeout(function() {this.ping();}.bind(this), 10000);
|
||||
},
|
||||
ping: function() {
|
||||
//Logger.error('Ping!');
|
||||
this.sendRefresh();
|
||||
var now = new Date;
|
||||
var mod = 10000 - (now.getTime() % 10000);
|
||||
|
||||
setTimeout(function() {this.ping();}.bind(this),mod + 10);
|
||||
|
||||
},
|
||||
sendRefresh: function() {
|
||||
// logger.debug('+ Send refresh', this.statuses);
|
||||
|
||||
for (var item in this.statuses) {
|
||||
if (this.statuses.hasOwnProperty(item)) {
|
||||
console.log(this.statuses[item]);
|
||||
this.emitter.emit('sendSocket', this.statuses[item]);
|
||||
}
|
||||
}
|
||||
// logger.debug('+ Send refresh');
|
||||
},
|
||||
preRestartConnection: function() {
|
||||
logger.debug('Restart connection...');
|
||||
//this.emitter.emit('restartMQTTSocket', this);
|
||||
//logger.debug(this);
|
||||
this.restartMQTTSocket();
|
||||
},
|
||||
startMQTTSocket:function() {
|
||||
logger.warn('Restarting socket?');
|
||||
this.connectWS();
|
||||
},
|
||||
restartMQTTSocket: function() {
|
||||
this.wsClient.disconnect();
|
||||
// setTimeout(this.startMQTTSocket.bind(this), 15000);
|
||||
},
|
||||
connectWS: function(connectCB) {
|
||||
|
||||
logger.debug('Going to connect WS');
|
||||
var self = this;
|
||||
var hostname = 'silvrtree.co.uk';
|
||||
var clientId = 'a:' + 'qz0da4' + ':' + Date.now();
|
||||
|
||||
var api_key = 'martind2000';
|
||||
var auth_token = 'MPReoa43';
|
||||
|
||||
this.wsClient =new Messaging.Client(hostname, 8883, clientId);
|
||||
//var wsClient = new Messaging.Client(hostname, 8883, clientId);
|
||||
var wsClient = this.wsClient;
|
||||
var clientStatus = {connected: false, subscribed: false, deviceConnected: false};
|
||||
var sensorData = {};
|
||||
|
||||
|
||||
this.restartTimer = setTimeout(this.preRestartConnection.bind(this), 60000);
|
||||
|
||||
wsClient.onMessageArrived = function(msg) {
|
||||
//logger.info("Message from :" + msg.destinationName);
|
||||
clearTimeout(self.restartTimer);
|
||||
self.restartTimer = setTimeout(self.preRestartConnection.bind(self), 60000);
|
||||
clientStatus.deviceConnected = true;
|
||||
sensorData = JSON.parse(msg.payloadString);
|
||||
// Logger.debug(sensorData);
|
||||
var temp = msg.destinationName.split('/');
|
||||
if (self.watches.hasOwnProperty(temp[4])) {
|
||||
|
||||
// Logger.info('Emit: ' + JSON.stringify({id:self.watches[temp[4]],sensorData:sensorData}));
|
||||
|
||||
self.emitter.emit('sendSocket',{id: self.watches[temp[4]],sensorData: sensorData});
|
||||
}
|
||||
|
||||
};
|
||||
wsClient.onConnectionLost = function(e) {
|
||||
logger.error('+ wsClient.onConnectionLost');
|
||||
logger.error(e);
|
||||
logger.warn('Going to force a restart of the Socket.. Hold on.');
|
||||
setTimeout(self.startMQTTSocket.bind(self), 15000);
|
||||
//self.emitter.emit('sendSocket',{id: 'deviceLost',data: e});
|
||||
//var wsReconnectTimer = setTimeout(function() {logger.debug('TRYING TO RECONNECT TO MQTT');self.emitter.emit('connectWS');}.bind(this),30000);
|
||||
logger.error('- wsClient.onConnectionLost');
|
||||
};
|
||||
|
||||
|
||||
var connectOptions = {};
|
||||
connectOptions.keepAliveInterval = 3600;
|
||||
connectOptions.useSSL = true;
|
||||
connectOptions.userName = api_key;
|
||||
connectOptions.password = auth_token;
|
||||
|
||||
connectOptions.onSuccess = function() {
|
||||
clientStatus.connected = true;
|
||||
logger.info('MQTT connected to host: ' + wsClient.host + ' port : ' + wsClient.port + ' at ' + Date.now());
|
||||
|
||||
self.emitter.emit('clientStatusUpdated', clientStatus);
|
||||
self.emitter.emit('clientConnected', self.sockets);
|
||||
};
|
||||
|
||||
connectOptions.onFailure = function(e) {
|
||||
self.emitter.emit('sendSocket',{id: 'deviceNotConnecting'});
|
||||
logger.error('wsClient onFailure', e);
|
||||
logger.error('MQTT connection failed at ' + Date.now() + '\nerror: ' + e.errorCode + ' : ' + e.errorMessage);
|
||||
//var wsReconnectTimer = setTimeout(function() {logger.debug('TRYING TO RECONNECT TO MQTT');self.emitter.emit('connectWS');}.bind(this),30000);
|
||||
};
|
||||
|
||||
logger.debug('about to connect to ' + wsClient.host);
|
||||
wsClient.connect(connectOptions);
|
||||
|
||||
this.sockets = {
|
||||
|
||||
getClientStatus: function() {
|
||||
return clientStatus;
|
||||
},
|
||||
subscribe: function(deviceId, emitterId) {
|
||||
logger.debug('trying to subscribe');
|
||||
var subscribeTopic = 'iot-2/type/Ti-CC3200/id/' + deviceId + '/evt/+/fmt/json';
|
||||
logger.debug(subscribeTopic);
|
||||
|
||||
var subscribeOptions = {
|
||||
qos: 0,
|
||||
onSuccess: function() {
|
||||
logger.info('subscribed to ' + subscribeTopic);
|
||||
clientStatus.subscribed = true;
|
||||
// $rootScope.$broadcast("clientStatusUpdated", clientStatus);
|
||||
|
||||
self.emitter.emit('clientStatusUpdated', clientStatus);
|
||||
self.watches[deviceId] = emitterId;
|
||||
},
|
||||
onFailure: function() {
|
||||
logger.error('Failed to subscribe to ' + subscribeTopic);
|
||||
logger.error('As messages are not available, visualization is not possible');
|
||||
}
|
||||
};
|
||||
|
||||
/*If (IoTFconnector.prototype.clientStatus.subscribeTopic != "") {
|
||||
console.log("Unsubscribing to " + subscribeTopic);
|
||||
wsClient.unsubscribe(IoTFconnector.prototype.clientStatus.subscribeTopic);
|
||||
};*/
|
||||
|
||||
wsClient.subscribe(subscribeTopic, subscribeOptions);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return this.sockets;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
7
mdot/mdot_server/mdot_server/lib/mqtt/mqttSocket.js
Normal file
7
mdot/mdot_server/mdot_server/lib/mqtt/mqttSocket.js
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* User: Martin Donnelly
|
||||
* Date: 2016-07-28
|
||||
* Time: 14:48
|
||||
*
|
||||
*/
|
1791
mdot/mdot_server/mdot_server/lib/mqtt/mqttws31.js
Normal file
1791
mdot/mdot_server/mdot_server/lib/mqtt/mqttws31.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@
|
||||
|
||||
var pgp = require('pg-promise')();
|
||||
|
||||
/*
|
||||
var cn = {
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
@ -16,6 +17,17 @@ var cn = {
|
||||
user: 'postgres',
|
||||
password: ''
|
||||
};
|
||||
*/
|
||||
|
||||
// ElephantSql settings
|
||||
|
||||
var cn = {
|
||||
host: 'jumbo.db.elephantsql.com',
|
||||
port: 5432,
|
||||
database: 'amlrxqev',
|
||||
user: 'amlrxqev',
|
||||
password: 'K11cvCplk0--oNafsYj4ISN-rVQmVS3y'
|
||||
};
|
||||
|
||||
exports.dbConnection = pgp(cn);
|
||||
|
||||
|
@ -70,7 +70,7 @@ module.exports = function(db) {
|
||||
_obj.deviceID = module.deviceIds.indexOf(params.id);
|
||||
room = _obj.deviceID;
|
||||
|
||||
if (params.hasOwnProperty('start') && params.hasOwnProperty('start')) {
|
||||
if (params.hasOwnProperty('start') && params.hasOwnProperty('end')) {
|
||||
|
||||
logger.debug('params.start',params.start);
|
||||
logger.debug('params.start',Sugar.Date.create(params.start));
|
||||
@ -83,10 +83,8 @@ module.exports = function(db) {
|
||||
.then(function(d) {
|
||||
|
||||
self.sqlGetMeetingByRoom(room)
|
||||
.then(function(mrd) {
|
||||
|
||||
console.log('d:',d);
|
||||
console.log('mrd:',mrd);
|
||||
.then(function() {
|
||||
// nothing done
|
||||
})
|
||||
.catch(function(e) {
|
||||
logger.error(e);
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var newId = require('uuid-pure').newId;
|
||||
var atob = require('atob');
|
||||
|
||||
module.exports = function(db) {
|
||||
@ -17,6 +16,7 @@ module.exports = function(db) {
|
||||
return resolve('ok');
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
@ -26,8 +26,6 @@ module.exports = function(db) {
|
||||
let _data = data;
|
||||
|
||||
console.log('sqlInsertDecoded', _data.deviceid, _data.timestamp);
|
||||
console.log('insert_decoded',
|
||||
[_data.deviceid, _data.timestamp, _data.lux, _data.co2, _data.temp, _data.humidity, _data.sound]);
|
||||
return new Promise(function(resolve, reject) {
|
||||
db.func('insert_decoded',
|
||||
[_data.deviceid, _data.timestamp, _data.lux, _data.co2, _data.temp, _data.humidity, _data.sound])
|
||||
@ -35,6 +33,7 @@ module.exports = function(db) {
|
||||
return resolve('ok');
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
@ -56,6 +55,7 @@ module.exports = function(db) {
|
||||
return resolve({reply: 'raw event inserted'});
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
@ -68,14 +68,13 @@ module.exports = function(db) {
|
||||
|
||||
let _data = self.rawBreaker(data);
|
||||
|
||||
console.log(_data);
|
||||
|
||||
self.sqlInsertDecoded(_data)
|
||||
.then((d)=> {
|
||||
console.log('Postgres returns', d);
|
||||
return resolve({reply: 'Processed event inserted'});
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
@ -96,6 +95,7 @@ module.exports = function(db) {
|
||||
_obj.humid = (parseInt(_data[12] + _data[13] + _data[14] + _data[15] + _data[16], 10) / 10);
|
||||
_obj.noise = parseInt('0x' + ('0' + bytes[17]).substr(-2) + ('0' + bytes[18]).substr(-2));
|
||||
_obj.binData = bytes;
|
||||
console.log(_obj);
|
||||
return _obj;
|
||||
};
|
||||
|
||||
@ -104,7 +104,9 @@ module.exports = function(db) {
|
||||
var workObj = {};
|
||||
|
||||
var device_name = data.topic.split('/')[4];
|
||||
console.log('Device_name', device_name);
|
||||
workObj.deviceid = self.deviceIds.indexOf(device_name);
|
||||
|
||||
if (data.hasOwnProperty('data')) {
|
||||
|
||||
var _data = self.decoder(data.data);
|
||||
@ -114,7 +116,7 @@ module.exports = function(db) {
|
||||
workObj.temp = _data.temp;
|
||||
workObj.humidity = _data.humid;
|
||||
workObj.sound = _data.noise;
|
||||
workObj.timestamp = new Date(data.gateway_info['0'].gw_time);
|
||||
workObj.timestamp = new Date();
|
||||
|
||||
return workObj;
|
||||
} else {
|
||||
|
8
mdot/mdot_server/mdot_server/manifest.yml
Normal file
8
mdot/mdot_server/mdot_server/manifest.yml
Normal file
@ -0,0 +1,8 @@
|
||||
applications:
|
||||
- path: .
|
||||
memory: 256M
|
||||
instances: 1
|
||||
domain: mybluemix.net
|
||||
name: mdotmqtt
|
||||
host: mdotmqtt
|
||||
disk_quota: 1024M
|
@ -2,7 +2,7 @@
|
||||
"name": "mdotserver",
|
||||
"version": "0.0.1",
|
||||
"description": "mDot Dashboard Server",
|
||||
"main": "index.js",
|
||||
"main": "app.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
@ -10,12 +10,15 @@
|
||||
"atob": "^2.0.3",
|
||||
"body-parser": "^1.15.1",
|
||||
"btoa": "^1.1.2",
|
||||
"cfenv": "1.0.x",
|
||||
"cookie-parser": "*",
|
||||
"ejs": "*",
|
||||
"errorhandler": "*",
|
||||
"events": "^1.1.1",
|
||||
"express": "^4.13.4",
|
||||
"express-session": "*",
|
||||
"htmlparser": "^1.7.7",
|
||||
"log4js": "^0.6.36",
|
||||
"method-override": "*",
|
||||
"minibus": "^3.1.0",
|
||||
"morgan": "*",
|
||||
@ -25,8 +28,9 @@
|
||||
"pg-promise": "^5.2.7",
|
||||
"request": "^2.74.0",
|
||||
"request-promise": "^4.1.1",
|
||||
"sugar-date": "^2.0.0",
|
||||
"uuid-pure": "^1.0.10",
|
||||
"websocket": "^1.0.22"
|
||||
"websocket": "^1.0.23"
|
||||
},
|
||||
"devDependencies": {
|
||||
"after": "^0.8.1",
|
||||
@ -73,7 +77,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --recursive --reporter spec --bail --check-leaks --timeout 3000",
|
||||
"start": "node app"
|
||||
"start": "node app.js"
|
||||
},
|
||||
"author": "Martin Donnelly",
|
||||
"license": "ISC",
|
||||
|
@ -11,9 +11,9 @@ var exec = require('child_process').exec;
|
||||
|
||||
function run_script() {
|
||||
'use strict';
|
||||
exec('psql -Upostgres -d mdot -h localhost -f ../mdot.sql', function(err) {
|
||||
exec('psql postgres://amlrxqev:K11cvCplk0--oNafsYj4ISN-rVQmVS3y@jumbo.db.elephantsql.com:5432/amlrxqev -f ../sql/mdot.sql', function(err) {
|
||||
if (err !== null) {
|
||||
console.log('exec error: ' + err);
|
||||
console.log('exec error: ', err);
|
||||
return -1;
|
||||
} else {
|
||||
// addUsers();
|
||||
|
130457
mdot/mdot_server/mdot_server/sql/mdot.sql
Normal file
130457
mdot/mdot_server/mdot_server/sql/mdot.sql
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user