From fac5f7cd4502e45fcd55af9f18c52f0196fd2bad Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Mon, 8 Aug 2016 16:45:03 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=9D2016-08-08=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartoffice/SODashServer/SODashServer/app.js | 11 +++++ .../SODashServer/SODashServer/app/js/mdot.js | 5 +- .../SODashServer/SODashServer/lib/mdot/api.js | 47 +++++++++++++++++++ .../SODashServer/lib/mdot/mdot.js | 18 +++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 smartoffice/SODashServer/SODashServer/lib/mdot/api.js create mode 100644 smartoffice/SODashServer/SODashServer/lib/mdot/mdot.js diff --git a/smartoffice/SODashServer/SODashServer/app.js b/smartoffice/SODashServer/SODashServer/app.js index f9706e2..2a0fa5a 100644 --- a/smartoffice/SODashServer/SODashServer/app.js +++ b/smartoffice/SODashServer/SODashServer/app.js @@ -34,6 +34,10 @@ var heating_v1 = require('./routes/heating_v1'); var projector_v1 = require('./routes/projector_v1'); var isProduction = false; +var mdotApi = require('./lib/mdot/api.js'); + + + function restartTimer() { // Ibm / mqtt things go a bit weird if left on for too long so restart the server @@ -133,6 +137,9 @@ app.post('/api/calendar/extend', function(req, res) { + + + // Events and sockets busEmitter.on('clientConnected', (socketSet) => { @@ -256,6 +263,10 @@ app.post('/api/v1/extend', function(req, res) { }); +mdotApi(app); + +//app.get('/api/mdot/:id', mDot.getData); + app.listen(3000, function() { logger.info('Express listening on 3000'); restartTimer(); diff --git a/smartoffice/SODashServer/SODashServer/app/js/mdot.js b/smartoffice/SODashServer/SODashServer/app/js/mdot.js index 7151a55..bd806a4 100644 --- a/smartoffice/SODashServer/SODashServer/app/js/mdot.js +++ b/smartoffice/SODashServer/SODashServer/app/js/mdot.js @@ -212,8 +212,9 @@ console.log(fetchObj.data); } if (this.model.has('device')) { - //FetchObj.data = $.param({key:'"'+ this.model.get('device') + '"'}); - this.collection.url = 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/' + this.model.get('device'); + // FetchObj.data = $.param({key:'"'+ this.model.get('device') + '"'}); + // this.collection.url = 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/' + this.model.get('device'); + this.collection.url = '/api/mdot/' + this.model.get('device'); // this.collection.url = 'http://127.0.0.1:5984/mdot/_design/getDevice/_view/getDevice'; this.collection.fetch(fetchObj); } else { diff --git a/smartoffice/SODashServer/SODashServer/lib/mdot/api.js b/smartoffice/SODashServer/SODashServer/lib/mdot/api.js new file mode 100644 index 0000000..02d33cd --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/lib/mdot/api.js @@ -0,0 +1,47 @@ +var logger = require('log4js').getLogger(); +var util = require('util'); + +var mdot = require('./mdot.js'); + +module.exports = function(app) { + var express = require('express'); + var mdotRouter = express.Router(); + + mdotRouter.get('/:id', function(req, res) { + console.log(req.headers); + + var data = {}; + logger.debug('mDot-GetData'); + logger.debug(req); + + if (!req.params.id) { + logger.error('MDot','Missing required paramter'); + res.status(400).send({ + status: 'error', + error: 'missing required parameter' + }); + return; + } + + logger.debug(req.params.id); + + if (req.params.hasOwnProperty('id')) { + data.id = req.params.id; + + logger.debug(data); + + + mdot.doGet() + .then(() => { + 'use strict'; + console.log('outside the promise'); + }); + + //logger.debug(util.inspect(mdot,{showHidden:true})); + } + + }); + + app.use('/api/mdot/', mdotRouter); +}; + diff --git a/smartoffice/SODashServer/SODashServer/lib/mdot/mdot.js b/smartoffice/SODashServer/SODashServer/lib/mdot/mdot.js new file mode 100644 index 0000000..d3aa14e --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/lib/mdot/mdot.js @@ -0,0 +1,18 @@ +'use strict'; +var logger = require('log4js').getLogger(); + + +var self = module.exports = { + + + doGet : function(data) { + + return new Promise(function(resolve, reject) { + logger.debug('doGet Promise'); + resolve(''); + }); + } + +}; + +