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')
|
||||
, Helper = require('../Adawim/helper')
|
||||
, Log = require('../Adawim/logging')
|
||||
, http = require('http')
|
||||
, ws = require("nodejs-websocket");
|
||||
, http = require('http');
|
||||
|
||||
|
||||
Helper.each(Conf.items, function(item) {
|
||||
@ -46,7 +45,8 @@ Helper.each(Conf.items, function(item) {
|
||||
// Callback function for motion detected callback
|
||||
function () {
|
||||
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 */
|
||||
function doHoBuDoorBellCall(options) {
|
||||
function doMotionCall(options) {
|
||||
callback = function(response) {
|
||||
var str = '';
|
||||
|
||||
@ -74,24 +74,13 @@ function doHoBuDoorBellCall(options) {
|
||||
});
|
||||
}
|
||||
|
||||
http.request(options, callback).end();
|
||||
}
|
||||
|
||||
/* private */
|
||||
function sendToHoBu(data) {
|
||||
Log.debug('Send data to ' + Conf.hobu.webservice);
|
||||
|
||||
try {
|
||||
ws.connect(Conf.hobu.webservice, null, function(conn) {
|
||||
if(Helper.isDefinedAndNotNull(conn)) {
|
||||
conn.send(data, null);
|
||||
} else {
|
||||
Log.error('Connection is NULL.');
|
||||
}
|
||||
|
||||
//TODO: disconnect!!
|
||||
var req = http.request(options, function(res) {
|
||||
//Log.inspect('Result', res);
|
||||
});
|
||||
} catch(err) {
|
||||
Log.error(err.message);
|
||||
}
|
||||
|
||||
req.on('error', function(err) {
|
||||
Log.error(err);
|
||||
});
|
||||
|
||||
req.end();
|
||||
}
|
||||
@ -1,12 +1,19 @@
|
||||
{
|
||||
"hobu": {
|
||||
"webservice": "ws://192.168.2.111:8000/"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"host": "192.168.2.125",
|
||||
"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