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')
, 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 = '';
@ -73,25 +73,14 @@ function doHoBuDoorBellCall(options) {
Log.log(str);
});
}
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!!
});
} catch(err) {
Log.error(err.message);
}
var req = http.request(options, function(res) {
//Log.inspect('Result', res);
});
req.on('error', function(err) {
Log.error(err);
});
req.end();
}

View File

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

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