mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-01-10 21:35:07 +00:00
”2016-10-07”
This commit is contained in:
parent
4ea3dde25d
commit
992ba791dc
@ -87,7 +87,6 @@ var watchDogTimeout = () => {
|
||||
'Watchdog timeout. Message has not been received for over 20 minutes.');
|
||||
logger.warn('Last received:' + lastReceived + 'Now:' + now);
|
||||
|
||||
|
||||
wdTimedOut = true;
|
||||
};
|
||||
|
||||
@ -104,7 +103,28 @@ var mqttClient = function() {
|
||||
|
||||
this.connected = false;
|
||||
|
||||
this.logged = [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}];
|
||||
this.logged = [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{}
|
||||
];
|
||||
|
||||
var options = {
|
||||
keepalive: 10,
|
||||
@ -116,7 +136,23 @@ var mqttClient = function() {
|
||||
|
||||
};
|
||||
|
||||
this.deviceIds = ['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'];
|
||||
this.deviceIds = [
|
||||
'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'
|
||||
];
|
||||
|
||||
logger.info('Connecting to ', connection);
|
||||
//this.client = mqtt.connect(connection, options);
|
||||
@ -126,7 +162,6 @@ var mqttClient = function() {
|
||||
// connected = true;
|
||||
logger.info('Connected to ', address);
|
||||
|
||||
pusher.push('Connected to ' + address);
|
||||
clearTimeout(watchDog);
|
||||
watchDog = setTimeout(watchDogTimeout, 1200000);
|
||||
lastReceived = new Date();
|
||||
@ -173,18 +208,22 @@ var mqttClient = function() {
|
||||
json.device = topicArray[4];
|
||||
json.event = topicArray[6];
|
||||
|
||||
var did = this.deviceIds.indexOf(json.device);
|
||||
console.log('DdeviceID',did);
|
||||
|
||||
logger.info('Dif?:', this.logged[did].data !== json.data);
|
||||
|
||||
|
||||
// busEmitter.emit('saveData', json);
|
||||
this.logged[did] = json;
|
||||
// logger.info('current:', this.logged[did]);
|
||||
//console.log(json.type);
|
||||
//logger.debug(topic);
|
||||
if (json.type !== 'Ti-CC3200') {
|
||||
// console.log(json);
|
||||
var did = this.deviceIds.indexOf(json.device);
|
||||
if (typeof this.logged[did].data === 'undefined' || this.logged[did].data !== json.data) {
|
||||
// logger.debug('Dif?', did, 'Yes');
|
||||
busEmitter.emit('saveData', json);
|
||||
}
|
||||
this.logged[did] = json;
|
||||
}
|
||||
else {
|
||||
busEmitter.emit('saveData', json);
|
||||
}
|
||||
|
||||
if (json.type !== 'Ti-CC3200') {
|
||||
|
||||
clearTimeout(watchDog);
|
||||
watchDog = setTimeout(watchDogTimeout, 1200000);
|
||||
if (wdTimedOut) {
|
||||
@ -208,7 +247,7 @@ var mqttClient = function() {
|
||||
this.getCount = function() {
|
||||
'use strict';
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
@ -19,15 +19,24 @@ var localCN = {
|
||||
|
||||
// ElephantSql settings
|
||||
|
||||
var remoteCN = {
|
||||
/*var remoteCN = {
|
||||
host: 'jumbo.db.elephantsql.com',
|
||||
port: 5432,
|
||||
database: 'vmlcokon',
|
||||
user: 'vmlcokon',
|
||||
password: 'PQUYLiIW4M6r7SWyZevrES_rRAULYFkp'
|
||||
};*/
|
||||
|
||||
var amazonCN = {
|
||||
dbinstance:'CensisMDot',
|
||||
host: 'censis.cew5a5td5ukl.eu-west-1.rds.amazonaws.com',
|
||||
port: 5432,
|
||||
database: 'mdot',
|
||||
user: 'censis_Lm5zt9BYD',
|
||||
password: '1bR9nJoC5cFRcO84lu5mzmA7MeKyRW'
|
||||
};
|
||||
|
||||
const cn = process.env.NODE_ENV === 'production' ? remoteCN : localCN;
|
||||
const cn = process.env.NODE_ENV === 'production' ? amazonCN : localCN;
|
||||
|
||||
|
||||
exports.dbConnection = pgp(cn);
|
||||
|
@ -6,7 +6,8 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"production": "NODE_ENV=production node app.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"atob": "^2.0.3",
|
||||
|
@ -34,10 +34,6 @@ 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
|
||||
@ -263,9 +259,6 @@ app.post('/api/v1/extend', function(req, res) {
|
||||
|
||||
});
|
||||
|
||||
mdotApi(app);
|
||||
|
||||
//app.get('/api/mdot/:id', mDot.getData);
|
||||
|
||||
app.listen(3002, function() {
|
||||
logger.info('Express listening on 3000');
|
||||
|
Loading…
Reference in New Issue
Block a user