HCBASE-93, lost connection err fixed

This commit is contained in:
Gerrit Linnemann 2016-06-09 17:13:00 +02:00
parent 971495b393
commit 8a32eafad6
4 changed files with 42 additions and 30 deletions

View File

@ -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 = '';
@ -74,24 +74,13 @@ function doHoBuDoorBellCall(options) {
}); });
} }
http.request(options, callback).end(); var req = http.request(options, function(res) {
} //Log.inspect('Result', res);
});
/* private */
function sendToHoBu(data) { req.on('error', function(err) {
Log.debug('Send data to ' + Conf.hobu.webservice); Log.error(err);
});
try {
ws.connect(Conf.hobu.webservice, null, function(conn) { req.end();
if(Helper.isDefinedAndNotNull(conn)) {
conn.send(data, null);
} else {
Log.error('Connection is NULL.');
}
//TODO: disconnect!!
});
} catch(err) {
Log.error(err.message);
}
} }

View File

@ -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/"
}
}
}
} }
] ]
} }

View File

@ -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();
} }

View File

@ -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();
} }