diff --git a/hobu_alert_system_motion/app.js b/hobu_alert_system_motion/app.js index ea3414e..7a3e166 100644 --- a/hobu_alert_system_motion/app.js +++ b/hobu_alert_system_motion/app.js @@ -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(); } \ No newline at end of file diff --git a/hobu_alert_system_motion/config.json b/hobu_alert_system_motion/config.json index ba83c6b..20107a5 100644 --- a/hobu_alert_system_motion/config.json +++ b/hobu_alert_system_motion/config.json @@ -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/" + } + } + } } ] } diff --git a/hobu_distance_switch/app.js b/hobu_distance_switch/app.js index 38372a1..f9b4f20 100644 --- a/hobu_distance_switch/app.js +++ b/hobu_distance_switch/app.js @@ -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(); } \ No newline at end of file diff --git a/hobu_doorbell/app.js b/hobu_doorbell/app.js index 878ae41..a44a264 100644 --- a/hobu_doorbell/app.js +++ b/hobu_doorbell/app.js @@ -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(); } \ No newline at end of file