HCBASE-93, lost connection err fixed
This commit is contained in:
parent
971495b393
commit
8a32eafad6
@ -2,8 +2,7 @@ var Tinkerforge = require('../Tinkerforge')
|
|||||||
, Conf = require('./config.json')
|
, Conf = require('./config.json')
|
||||||
, Helper = require('../Adawim/helper')
|
, Helper = require('../Adawim/helper')
|
||||||
, Log = require('../Adawim/logging')
|
, Log = require('../Adawim/logging')
|
||||||
, http = require('http')
|
, http = require('http');
|
||||||
, ws = require("nodejs-websocket");
|
|
||||||
|
|
||||||
|
|
||||||
Helper.each(Conf.items, function(item) {
|
Helper.each(Conf.items, function(item) {
|
||||||
@ -46,7 +45,8 @@ Helper.each(Conf.items, function(item) {
|
|||||||
// Callback function for motion detected callback
|
// Callback function for motion detected callback
|
||||||
function () {
|
function () {
|
||||||
Log.log('Motion detected');
|
Log.log('Motion detected');
|
||||||
sendToHoBu("ping");
|
var callOptions = item.on.motion.call;
|
||||||
|
doMotionCall(callOptions);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ Helper.each(Conf.items, function(item) {
|
|||||||
|
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
function doHoBuDoorBellCall(options) {
|
function doMotionCall(options) {
|
||||||
callback = function(response) {
|
callback = function(response) {
|
||||||
var str = '';
|
var str = '';
|
||||||
|
|
||||||
@ -73,25 +73,14 @@ function doHoBuDoorBellCall(options) {
|
|||||||
Log.log(str);
|
Log.log(str);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
http.request(options, callback).end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private */
|
|
||||||
function sendToHoBu(data) {
|
|
||||||
Log.debug('Send data to ' + Conf.hobu.webservice);
|
|
||||||
|
|
||||||
try {
|
var req = http.request(options, function(res) {
|
||||||
ws.connect(Conf.hobu.webservice, null, function(conn) {
|
//Log.inspect('Result', res);
|
||||||
if(Helper.isDefinedAndNotNull(conn)) {
|
});
|
||||||
conn.send(data, null);
|
|
||||||
} else {
|
req.on('error', function(err) {
|
||||||
Log.error('Connection is NULL.');
|
Log.error(err);
|
||||||
}
|
});
|
||||||
|
|
||||||
//TODO: disconnect!!
|
req.end();
|
||||||
});
|
|
||||||
} catch(err) {
|
|
||||||
Log.error(err.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,12 +1,19 @@
|
|||||||
{
|
{
|
||||||
"hobu": {
|
|
||||||
"webservice": "ws://192.168.2.111:8000/"
|
|
||||||
},
|
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"host": "192.168.2.125",
|
"host": "192.168.2.125",
|
||||||
"port": 4223,
|
"port": 4223,
|
||||||
"uid": "wsk"
|
"uid": "wsk",
|
||||||
|
"on": {
|
||||||
|
"motion": {
|
||||||
|
"call": {
|
||||||
|
"type": "web",
|
||||||
|
"host": "hobu",
|
||||||
|
"port": "2999",
|
||||||
|
"path": "/home/motion/detected/in/1/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,5 +76,13 @@ function doHoBuDoorBellCall(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
http.request(options, callback).end();
|
var req = http.request(options, function(res) {
|
||||||
|
//Log.inspect('Result', res);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', function(err) {
|
||||||
|
Log.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
}
|
}
|
||||||
@ -85,5 +85,13 @@ function doHoBuDoorBellCall() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
http.request(options, callback).end();
|
var req = http.request(options, function(res) {
|
||||||
|
//Log.inspect('Result', res);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', function(err) {
|
||||||
|
Log.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user