mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-02-04 13:50:14 +00:00
”2016-08-22”
This commit is contained in:
parent
0bfa4f6c4b
commit
ff8e7a9912
23174
mdot/mdot_mqtt/mdot_mqtt/backup.sql
Normal file
23174
mdot/mdot_mqtt/mdot_mqtt/backup.sql
Normal file
File diff suppressed because it is too large
Load Diff
@ -56,22 +56,22 @@ var doInsertEntry = (obj) => {
|
|||||||
dbSave.addNewEvent(obj)
|
dbSave.addNewEvent(obj)
|
||||||
.then(function(d) {
|
.then(function(d) {
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('Finished - Raw',d);
|
logger.info('Finished - Raw',d);
|
||||||
})
|
})
|
||||||
.catch(function(e) {
|
.catch(function(e) {
|
||||||
'use strict';
|
'use strict';
|
||||||
console.error(e);
|
logger.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
dbSave.addProcessedEvent(obj)
|
dbSave.addProcessedEvent(obj)
|
||||||
.then(function(d) {
|
.then(function(d) {
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('Finished - Processed',d);
|
logger.info('Finished - Processed',d);
|
||||||
})
|
})
|
||||||
.catch(function(e) {
|
.catch(function(e) {
|
||||||
'use strict';
|
'use strict';
|
||||||
console.error(e);
|
logger.error(e);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ var mqttClient = function() {
|
|||||||
var address = '.messaging.internetofthings.ibmcloud.com';
|
var address = '.messaging.internetofthings.ibmcloud.com';
|
||||||
var appKey = '9txJEf3Cjy7hkSOvkv';
|
var appKey = '9txJEf3Cjy7hkSOvkv';
|
||||||
var prefix = 'iot-2/type/mDot/id/';
|
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-demo','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';
|
//Var subscribeTopic = prefix + deviceId + '/evt/+/fmt/json';
|
||||||
|
@ -17,6 +17,7 @@ module.exports = function(db) {
|
|||||||
return resolve('ok');
|
return resolve('ok');
|
||||||
})
|
})
|
||||||
.catch((err)=> {
|
.catch((err)=> {
|
||||||
|
console.error(err);
|
||||||
return reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -33,6 +34,7 @@ module.exports = function(db) {
|
|||||||
return resolve('ok');
|
return resolve('ok');
|
||||||
})
|
})
|
||||||
.catch((err)=> {
|
.catch((err)=> {
|
||||||
|
console.error(err);
|
||||||
return reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -54,6 +56,7 @@ module.exports = function(db) {
|
|||||||
return resolve({reply: 'raw event inserted'});
|
return resolve({reply: 'raw event inserted'});
|
||||||
})
|
})
|
||||||
.catch((err)=> {
|
.catch((err)=> {
|
||||||
|
console.error(err);
|
||||||
return reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -72,6 +75,7 @@ module.exports = function(db) {
|
|||||||
return resolve({reply: 'Processed event inserted'});
|
return resolve({reply: 'Processed event inserted'});
|
||||||
})
|
})
|
||||||
.catch((err)=> {
|
.catch((err)=> {
|
||||||
|
console.error(err);
|
||||||
return reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -92,6 +96,7 @@ module.exports = function(db) {
|
|||||||
_obj.humid = (parseInt(_data[12] + _data[13] + _data[14] + _data[15] + _data[16], 10) / 10);
|
_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.noise = parseInt('0x' + ('0' + bytes[17]).substr(-2) + ('0' + bytes[18]).substr(-2));
|
||||||
_obj.binData = bytes;
|
_obj.binData = bytes;
|
||||||
|
console.log(_obj);
|
||||||
return _obj;
|
return _obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,58 +54,22 @@
|
|||||||
return newArray;
|
return newArray;
|
||||||
|
|
||||||
},
|
},
|
||||||
findOccupancy: function(ts, occupancy)
|
|
||||||
{
|
|
||||||
let tsMS = new Date(ts).getTime();
|
|
||||||
|
|
||||||
// console.log(new Date(ts).getTime());
|
|
||||||
// console.log(ts);
|
|
||||||
_(occupancy).each(function(item) {
|
|
||||||
|
|
||||||
// console.log(new Date(item.start).getTime(), new Date(item.start).getTime());
|
|
||||||
// console.log(item.start, item.end);
|
|
||||||
if ((ts >= new Date(item.start).getTime()) && (ts <= new Date(item.end).getTime()))
|
|
||||||
{
|
|
||||||
// console.log('Occupancy', item.count);
|
|
||||||
return item.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
}, this);
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
processAdded: function() {
|
processAdded: function() {
|
||||||
console.log('Model:ProcessAdded');
|
console.log('Model:ProcessAdded');
|
||||||
var self = this;
|
var self = this;
|
||||||
var tempCollection = new Backbone.Collection();
|
var tempCollection = new Backbone.Collection();
|
||||||
var occuCollection = new Backbone.Collection();
|
|
||||||
var occupancy = [];
|
var occupancy = [];
|
||||||
|
|
||||||
var events;
|
var events;
|
||||||
|
|
||||||
_.invoke(DeviceCollection.toArray(), 'destroy');
|
_.invoke(DeviceCollection.toArray(), 'destroy');
|
||||||
// _.invoke(OccupancyCollection.toArray(), 'destroy');
|
|
||||||
|
|
||||||
// console.log(this);
|
|
||||||
|
|
||||||
this.temporal = {low: 0, high: 0};
|
this.temporal = {low: 0, high: 0};
|
||||||
events = this.get('events');
|
events = this.get('events');
|
||||||
|
|
||||||
//_(this.get('events')).each(function(i) {
|
|
||||||
_(events.data).each(function(i) {
|
_(events.data).each(function(i) {
|
||||||
let _occupancy;
|
|
||||||
|
|
||||||
if (this.temporal.low === 0 || this.temporal.low > i.timestamp) {
|
|
||||||
this.temporal.low = i.timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.temporal.high === 0 || this.temporal.high < i.timestamp) {
|
|
||||||
this.temporal.high = i.timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _occupancy = this.findOccupancy(i.timestamp, events.occupancy);
|
|
||||||
|
|
||||||
tempCollection.add({
|
tempCollection.add({
|
||||||
dt: i.timestamp,
|
dt: Date.create(i.timestamp).addHours(1),
|
||||||
lux: i.lux,
|
lux: i.lux,
|
||||||
temp: i.temp,
|
temp: i.temp,
|
||||||
co2: i.co2,
|
co2: i.co2,
|
||||||
@ -115,16 +79,10 @@
|
|||||||
});
|
});
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
/* _(events.occupancy).each(function(item) {
|
|
||||||
|
|
||||||
occupancy = occupancy.concat(this.splitOccupancy(item));
|
|
||||||
|
|
||||||
}, this);*/
|
|
||||||
|
|
||||||
console.log('occupancy:', occupancy);
|
console.log('occupancy:', occupancy);
|
||||||
|
|
||||||
DeviceCollection.temporal = this.temporal;
|
DeviceCollection.temporal = this.temporal;
|
||||||
//DeviceCollection.occupancy = occupancy;
|
|
||||||
|
|
||||||
DeviceCollection.models = tempCollection.models;
|
DeviceCollection.models = tempCollection.models;
|
||||||
|
|
||||||
@ -166,7 +124,7 @@
|
|||||||
url: 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/',
|
url: 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.on('update', function() {
|
this.on('update', function() {
|
||||||
// Console.log('Collection:update',this);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +134,6 @@
|
|||||||
tagName: 'div', className: 'item mui-container', initialize: function() {
|
tagName: 'div', className: 'item mui-container', initialize: function() {
|
||||||
this.template = _.template($('#item-template').html());
|
this.template = _.template($('#item-template').html());
|
||||||
console.log('ItemView:Init');
|
console.log('ItemView:Init');
|
||||||
// This.render();
|
|
||||||
}, render: function() {
|
}, render: function() {
|
||||||
|
|
||||||
console.log('ItemView:Render');
|
console.log('ItemView:Render');
|
||||||
@ -197,9 +154,7 @@
|
|||||||
_.bindAll(this, 'render', 'refresh', 'update');
|
_.bindAll(this, 'render', 'refresh', 'update');
|
||||||
this.collection.bind('change reset add remove', this.render, this);
|
this.collection.bind('change reset add remove', this.render, this);
|
||||||
|
|
||||||
//This.template = _.template($('#list-template').html());
|
|
||||||
this.template = _.template($('#loaded-template').html());
|
this.template = _.template($('#loaded-template').html());
|
||||||
//This.render();
|
|
||||||
}, refresh: function() {
|
}, refresh: function() {
|
||||||
|
|
||||||
}, update: function() {
|
}, update: function() {
|
||||||
@ -209,10 +164,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
}, render: function() {
|
}, render: function() {
|
||||||
|
var that = this;
|
||||||
|
|
||||||
console.log('MDOT:render');
|
console.log('MDOT:render');
|
||||||
$('#output').empty();
|
$('#output').empty();
|
||||||
var that = this;
|
|
||||||
// that.$el.append(this.template);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -246,11 +201,7 @@
|
|||||||
console.log('MainView:Updatedevice');
|
console.log('MainView:Updatedevice');
|
||||||
notification.clearAll();
|
notification.clearAll();
|
||||||
if (this.model.has('device')) {
|
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');
|
|
||||||
// this.collection.url = '/api/mdot/' + this.model.get('device');
|
|
||||||
this.collection.url = '/apiv2/mdot/' + this.model.get('device');
|
this.collection.url = '/apiv2/mdot/' + this.model.get('device');
|
||||||
// this.collection.url = 'http://127.0.0.1:5984/mdot/_design/getDevice/_view/getDevice';
|
|
||||||
|
|
||||||
$('#output').empty();
|
$('#output').empty();
|
||||||
this.collection.fetch(fetchObj);
|
this.collection.fetch(fetchObj);
|
||||||
@ -277,13 +228,12 @@
|
|||||||
this.dataSet = new AmCharts.DataSet();
|
this.dataSet = new AmCharts.DataSet();
|
||||||
|
|
||||||
console.log('GraphView!');
|
console.log('GraphView!');
|
||||||
_.bindAll(this, 'render', 'updateGraph', 'setupChart');
|
_.bindAll(this, 'render', 'updateGraphV2', 'setupChart');
|
||||||
this.collection.on('update', function(d) {
|
this.collection.on('update', function(d) {
|
||||||
console.log('GraphView Collection update trigger!!');
|
console.log('GraphView Collection update trigger!!');
|
||||||
this.updateGraphV2();
|
this.updateGraphV2();
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
// This.setupChart();
|
|
||||||
}, events: {
|
}, events: {
|
||||||
'change select#displaymode': 'changeMode'
|
'change select#displaymode': 'changeMode'
|
||||||
}, setupChart: function() {
|
}, setupChart: function() {
|
||||||
@ -295,7 +245,6 @@
|
|||||||
this.dataSet.color = '#b0de09';
|
this.dataSet.color = '#b0de09';
|
||||||
|
|
||||||
this.chart.dataSets = [this.dataSet];
|
this.chart.dataSets = [this.dataSet];
|
||||||
// This.chart.write('chartdiv');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
doChartV2: function(chartData) {
|
doChartV2: function(chartData) {
|
||||||
@ -309,7 +258,9 @@
|
|||||||
],
|
],
|
||||||
|
|
||||||
legend: {
|
legend: {
|
||||||
useGraphSettings: true
|
useGraphSettings: true,
|
||||||
|
color: '#fff',
|
||||||
|
switchColor: '#556374'
|
||||||
},
|
},
|
||||||
color: '#ffffff',
|
color: '#ffffff',
|
||||||
dataProvider: chartData,
|
dataProvider: chartData,
|
||||||
@ -321,14 +272,16 @@
|
|||||||
axisColor: '#FFC802',
|
axisColor: '#FFC802',
|
||||||
axisThickness: 2,
|
axisThickness: 2,
|
||||||
axisAlpha: 1,
|
axisAlpha: 1,
|
||||||
position: 'left'
|
position: 'left',
|
||||||
|
gridColor: '#556374'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'co2',
|
id: 'co2',
|
||||||
axisColor: 'rgba(0,191,255,1)',
|
axisColor: 'rgba(0,191,255,1)',
|
||||||
axisThickness: 2,
|
axisThickness: 2,
|
||||||
axisAlpha: 1,
|
axisAlpha: 1,
|
||||||
position: 'right'
|
position: 'right',
|
||||||
|
gridColor: '#556374'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'temp',
|
id: 'temp',
|
||||||
@ -337,7 +290,8 @@
|
|||||||
gridAlpha: 0,
|
gridAlpha: 0,
|
||||||
offset: 50,
|
offset: 50,
|
||||||
axisAlpha: 1,
|
axisAlpha: 1,
|
||||||
position: 'left'
|
position: 'left',
|
||||||
|
gridColor: '#556374'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'humid',
|
id: 'humid',
|
||||||
@ -345,7 +299,8 @@
|
|||||||
axisThickness: 2,
|
axisThickness: 2,
|
||||||
axisAlpha: 1,
|
axisAlpha: 1,
|
||||||
offset: 50,
|
offset: 50,
|
||||||
position: 'right'
|
position: 'right',
|
||||||
|
gridColor: '#556374'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'noise',
|
id: 'noise',
|
||||||
@ -354,7 +309,8 @@
|
|||||||
gridAlpha: 0,
|
gridAlpha: 0,
|
||||||
offset: 100,
|
offset: 100,
|
||||||
axisAlpha: 1,
|
axisAlpha: 1,
|
||||||
position: 'left'
|
position: 'left',
|
||||||
|
gridColor: '#556374'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
graphs: [
|
graphs: [
|
||||||
@ -396,14 +352,17 @@
|
|||||||
],
|
],
|
||||||
chartScrollbar: {},
|
chartScrollbar: {},
|
||||||
chartCursor: {
|
chartCursor: {
|
||||||
cursorPosition: 'mouse'
|
cursorPosition: 'mouse',
|
||||||
|
cursorColor: '#14bfff',
|
||||||
|
color: '#000'
|
||||||
},
|
},
|
||||||
categoryField: 'date',
|
categoryField: 'date',
|
||||||
categoryAxis: {
|
categoryAxis: {
|
||||||
minPeriod: 'mm',
|
minPeriod: 'mm',
|
||||||
parseDates: true,
|
parseDates: true,
|
||||||
axisColor: '#ff0000',
|
axisColor: 'rgba(255,255,255,0.8)',
|
||||||
minorGridEnabled: true
|
minorGridEnabled: true,
|
||||||
|
gridColor: '#556374'
|
||||||
},
|
},
|
||||||
export: {
|
export: {
|
||||||
enabled: true, position: 'bottom-right'
|
enabled: true, position: 'bottom-right'
|
||||||
@ -426,63 +385,7 @@
|
|||||||
temp: i.get('temp')
|
temp: i.get('temp')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Console.log(chartData);
|
|
||||||
self.doChartV2(chartData);
|
self.doChartV2(chartData);
|
||||||
}, updateGraph: function() {
|
|
||||||
var self = this;
|
|
||||||
let getMode = this.modes[this.mode];
|
|
||||||
|
|
||||||
var chartData = [];
|
|
||||||
|
|
||||||
var temporal = {high: 0, low: 0};
|
|
||||||
var HL = {high: 0, low: 0};
|
|
||||||
|
|
||||||
var mode = parseInt(this.mode);
|
|
||||||
console.log('mode:', mode, this.mode);
|
|
||||||
|
|
||||||
_(this.collection.models).each(function(i) {
|
|
||||||
var dt = i.get('dt');
|
|
||||||
var obj;
|
|
||||||
var value, valueB;
|
|
||||||
if (mode < 6) {
|
|
||||||
value = i.get(getMode);
|
|
||||||
} else {
|
|
||||||
if (mode === 6) {
|
|
||||||
value = i.get(this.modes[1]);
|
|
||||||
valueB = i.get(this.modes[3]);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
value = i.get(this.modes[2]);
|
|
||||||
valueB = i.get(this.modes[4]);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temporal.low === 0 || dt < temporal.low) {
|
|
||||||
temporal.low = dt;
|
|
||||||
}
|
|
||||||
if (temporal.high === 0 || dt > temporal.high) {
|
|
||||||
temporal.high = dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HL.low === 0 || value < HL.low) {
|
|
||||||
HL.low = value;
|
|
||||||
}
|
|
||||||
if (HL.high === 0 || value > HL.high) {
|
|
||||||
HL.high = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = {date: dt, value: value};
|
|
||||||
|
|
||||||
if (mode => 6) {
|
|
||||||
obj.valueB = valueB;
|
|
||||||
}
|
|
||||||
chartData.push(obj);
|
|
||||||
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
self.doChartV2(mode, chartData);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
83
mdot/mdot_server/mdot_server/filler.js
Normal file
83
mdot/mdot_server/mdot_server/filler.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
var log4js = require('log4js');
|
||||||
|
var logger = log4js.getLogger();
|
||||||
|
|
||||||
|
|
||||||
|
var db = require('./lib/server/db-connector').dbConnection;
|
||||||
|
var dbSave = require('./lib/server/db-save')(db);
|
||||||
|
|
||||||
|
var Sugar = require('sugar-date');
|
||||||
|
|
||||||
|
var mdot = require('./lib/mdot/mdot.js');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(
|
||||||
|
function() {
|
||||||
|
|
||||||
|
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 device = 3;
|
||||||
|
var ids = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','HIE-demo','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 data = {id: ids[device]};
|
||||||
|
|
||||||
|
var startTs = Sugar.Date.create('2016-08-19 14:46:48');
|
||||||
|
var endTs = Sugar.Date.create('2016-08-21 10:03:39');
|
||||||
|
logger.debug(startTs, endTs);
|
||||||
|
logger.debug(startTs.getTime(), endTs.getTime());
|
||||||
|
|
||||||
|
data.start = startTs.getTime();
|
||||||
|
data.end = endTs.getTime();
|
||||||
|
|
||||||
|
|
||||||
|
mdot.doGet(data)
|
||||||
|
.then(function(d) {
|
||||||
|
'use strict';
|
||||||
|
//Logger.debug(d);
|
||||||
|
for (var item in d.events) {
|
||||||
|
var newItem = d.events[item].evt;
|
||||||
|
newItem.topic=['','','','',ids[device]].join('/');
|
||||||
|
logger.debug(newItem);
|
||||||
|
var gwTime = new Date(newItem.gateway_info['0'].gw_time);
|
||||||
|
if ((gwTime > startTs) && (gwTime < endTs)) {
|
||||||
|
doInsertEntry(newItem);
|
||||||
|
} else {
|
||||||
|
logger.warn('Out of range...');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
'use strict';
|
||||||
|
logger.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)();
|
@ -26,6 +26,8 @@ module.exports = function(db) {
|
|||||||
let _data = data;
|
let _data = data;
|
||||||
|
|
||||||
console.log('sqlInsertDecoded', _data.deviceid, _data.timestamp);
|
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) {
|
return new Promise(function(resolve, reject) {
|
||||||
db.func('insert_decoded',
|
db.func('insert_decoded',
|
||||||
[_data.deviceid, _data.timestamp, _data.lux, _data.co2, _data.temp, _data.humidity, _data.sound])
|
[_data.deviceid, _data.timestamp, _data.lux, _data.co2, _data.temp, _data.humidity, _data.sound])
|
||||||
@ -66,6 +68,8 @@ module.exports = function(db) {
|
|||||||
|
|
||||||
let _data = self.rawBreaker(data);
|
let _data = self.rawBreaker(data);
|
||||||
|
|
||||||
|
console.log(_data);
|
||||||
|
|
||||||
self.sqlInsertDecoded(_data)
|
self.sqlInsertDecoded(_data)
|
||||||
.then((d)=> {
|
.then((d)=> {
|
||||||
console.log('Postgres returns', d);
|
console.log('Postgres returns', d);
|
||||||
@ -100,9 +104,7 @@ module.exports = function(db) {
|
|||||||
var workObj = {};
|
var workObj = {};
|
||||||
|
|
||||||
var device_name = data.topic.split('/')[4];
|
var device_name = data.topic.split('/')[4];
|
||||||
console.log('Device_name', device_name);
|
|
||||||
workObj.deviceid = self.deviceIds.indexOf(device_name);
|
workObj.deviceid = self.deviceIds.indexOf(device_name);
|
||||||
|
|
||||||
if (data.hasOwnProperty('data')) {
|
if (data.hasOwnProperty('data')) {
|
||||||
|
|
||||||
var _data = self.decoder(data.data);
|
var _data = self.decoder(data.data);
|
||||||
@ -112,7 +114,7 @@ module.exports = function(db) {
|
|||||||
workObj.temp = _data.temp;
|
workObj.temp = _data.temp;
|
||||||
workObj.humidity = _data.humid;
|
workObj.humidity = _data.humid;
|
||||||
workObj.sound = _data.noise;
|
workObj.sound = _data.noise;
|
||||||
workObj.timestamp = new Date();
|
workObj.timestamp = new Date(data.gateway_info['0'].gw_time);
|
||||||
|
|
||||||
return workObj;
|
return workObj;
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"atob": "^2.0.3",
|
||||||
"body-parser": "^1.15.1",
|
"body-parser": "^1.15.1",
|
||||||
"btoa": "^1.1.2",
|
"btoa": "^1.1.2",
|
||||||
"cookie-parser": "*",
|
"cookie-parser": "*",
|
||||||
@ -63,7 +64,7 @@
|
|||||||
"mqtt-ws": "^0.2.0",
|
"mqtt-ws": "^0.2.0",
|
||||||
"node-cron": "^1.1.1",
|
"node-cron": "^1.1.1",
|
||||||
"require-dir": "^0.3.0",
|
"require-dir": "^0.3.0",
|
||||||
"should": "^10.0.0",
|
"should": "^11.0.0",
|
||||||
"string": "^3.3.1",
|
"string": "^3.3.1",
|
||||||
"sugar": "^2.0.1",
|
"sugar": "^2.0.1",
|
||||||
"sugar-date": "^2.0.0",
|
"sugar-date": "^2.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user