mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-02-13 20:19:16 +00:00
”2016-10-04”
This commit is contained in:
parent
5b0bf4e9f7
commit
6859a772af
@ -11,14 +11,6 @@ var requestify = require('requestify');
|
|||||||
var db = require('../server/db-connector').dbConnection;
|
var db = require('../server/db-connector').dbConnection;
|
||||||
|
|
||||||
var dbSave = require('../server/db-save')(db);
|
var dbSave = require('../server/db-save')(db);
|
||||||
var pusher = require('../pusher');
|
|
||||||
|
|
||||||
//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';
|
//let remoteHost = process.env.NODE_ENV === 'production' ? 'http://mdotserver.mybluemix.net/apiv2/message' : 'http://localhost:3011/apiv2/message';
|
||||||
const remoteHost = process.env.NODE_ENV === 'production' ? 'http://ec2-52-211-111-57.eu-west-1.compute.amazonaws.com/apiv2/message' : 'http://localhost:3011/apiv2/message';
|
const remoteHost = process.env.NODE_ENV === 'production' ? 'http://ec2-52-211-111-57.eu-west-1.compute.amazonaws.com/apiv2/message' : 'http://localhost:3011/apiv2/message';
|
||||||
@ -95,8 +87,7 @@ var watchDogTimeout = () => {
|
|||||||
'Watchdog timeout. Message has not been received for over 20 minutes.');
|
'Watchdog timeout. Message has not been received for over 20 minutes.');
|
||||||
logger.warn('Last received:' + lastReceived + 'Now:' + now);
|
logger.warn('Last received:' + lastReceived + 'Now:' + now);
|
||||||
|
|
||||||
pusher.push(
|
|
||||||
'Watchdog timeout. Message has not been received for over 20 Minutes. \n\nLast received:' + lastReceived + 'Now:' + now);
|
|
||||||
wdTimedOut = true;
|
wdTimedOut = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -113,6 +104,8 @@ var mqttClient = function() {
|
|||||||
|
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
|
|
||||||
|
this.logged = [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}];
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
keepalive: 10,
|
keepalive: 10,
|
||||||
clientId: 'a:' + orgId + ':' + Date.now(),
|
clientId: 'a:' + orgId + ':' + Date.now(),
|
||||||
@ -123,6 +116,8 @@ 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'];
|
||||||
|
|
||||||
logger.info('Connecting to ', connection);
|
logger.info('Connecting to ', connection);
|
||||||
//this.client = mqtt.connect(connection, options);
|
//this.client = mqtt.connect(connection, options);
|
||||||
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
||||||
@ -178,17 +173,25 @@ var mqttClient = function() {
|
|||||||
json.device = topicArray[4];
|
json.device = topicArray[4];
|
||||||
json.event = topicArray[6];
|
json.event = topicArray[6];
|
||||||
|
|
||||||
busEmitter.emit('saveData', json);
|
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);
|
//console.log(json.type);
|
||||||
if (json.type !== 'Ti-CC3200') {
|
if (json.type !== 'Ti-CC3200') {
|
||||||
console.log(json);
|
// console.log(json);
|
||||||
clearTimeout(watchDog);
|
clearTimeout(watchDog);
|
||||||
watchDog = setTimeout(watchDogTimeout, 1200000);
|
watchDog = setTimeout(watchDogTimeout, 1200000);
|
||||||
if (wdTimedOut) {
|
if (wdTimedOut) {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var s = 'Receiving again :::\n\nLast received: ' + lastReceived + 'Now: ' + now + "\n\n" + message.toString();
|
var s = 'Receiving again :::\n\nLast received: ' + lastReceived + 'Now: ' + now + "\n\n" + message.toString();
|
||||||
logger.warn(s);
|
logger.warn(s);
|
||||||
pusher.push(s);
|
|
||||||
wdTimedOut = false;
|
wdTimedOut = false;
|
||||||
}
|
}
|
||||||
lastReceived = new Date();
|
lastReceived = new Date();
|
||||||
|
@ -104,6 +104,8 @@ var mqttClient = function() {
|
|||||||
|
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
|
|
||||||
|
this.logged = [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}];
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
keepalive: 10,
|
keepalive: 10,
|
||||||
clientId: 'a:' + orgId + ':' + Date.now(),
|
clientId: 'a:' + orgId + ':' + Date.now(),
|
||||||
@ -114,6 +116,8 @@ 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'];
|
||||||
|
|
||||||
logger.info('Connecting to ', connection);
|
logger.info('Connecting to ', connection);
|
||||||
//this.client = mqtt.connect(connection, options);
|
//this.client = mqtt.connect(connection, options);
|
||||||
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
this.client = mqtt.connect('mqtt://' + orgId + address, options);
|
||||||
@ -168,10 +172,18 @@ var mqttClient = function() {
|
|||||||
json.device = topicArray[4];
|
json.device = topicArray[4];
|
||||||
json.event = topicArray[6];
|
json.event = topicArray[6];
|
||||||
|
|
||||||
busEmitter.emit('saveData', json);
|
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);
|
//console.log(json.type);
|
||||||
if (json.type !== 'Ti-CC3200') {
|
if (json.type !== 'Ti-CC3200') {
|
||||||
console.log(json);
|
// console.log(json);
|
||||||
clearTimeout(watchDog);
|
clearTimeout(watchDog);
|
||||||
watchDog = setTimeout(watchDogTimeout, 1200000);
|
watchDog = setTimeout(watchDogTimeout, 1200000);
|
||||||
if (wdTimedOut) {
|
if (wdTimedOut) {
|
||||||
|
Loading…
Reference in New Issue
Block a user