HCBASE-93
Error code overview: IPConnection.ERROR_ALREADY_CONNECTED = 11 IPConnection.ERROR_NOT_CONNECTED = 12 IPConnection.ERROR_CONNECT_FAILED = 13 IPConnection.ERROR_INVALID_FUNCTION_ID = 21 IPConnection.ERROR_TIMEOUT = 31 IPConnection.ERROR_INVALID_PARAMETER = 41 IPConnection.ERROR_FUNCTION_NOT_SUPPORTED = 42 IPConnection.ERROR_UNKNOWN_ERROR = 43 http://www.tinkerforge.com/de/doc/Software/Bricklets/MotionDetector_Bricklet_JavaScript.html https://www.npmjs.com/package/nodejs-websocket https://devcenter.heroku.com/articles/node-websockets
This commit is contained in:
@@ -2,7 +2,8 @@ var Tinkerforge = require('../Tinkerforge')
|
||||
, Conf = require('./config.json')
|
||||
, Helper = require('../Adawim/helper')
|
||||
, Log = require('../Adawim/logging')
|
||||
, http = require('http');
|
||||
, http = require('http')
|
||||
, ws = require("nodejs-websocket");
|
||||
|
||||
|
||||
Helper.each(Conf.items, function(item) {
|
||||
@@ -42,14 +43,15 @@ Helper.each(Conf.items, function(item) {
|
||||
|
||||
// Register motion detected callback
|
||||
md.on(Tinkerforge.BrickletMotionDetector.CALLBACK_MOTION_DETECTED,
|
||||
// Callback function for motion detected callback
|
||||
function () {
|
||||
Log.log('Motion detected');
|
||||
}
|
||||
// Callback function for motion detected callback
|
||||
function () {
|
||||
Log.log('Motion detected');
|
||||
sendToHoBu("ping");
|
||||
}
|
||||
);
|
||||
|
||||
process.on( 'SIGINT', function() {
|
||||
console.log( "\nGracefully disconnect " + HOST );
|
||||
Log.log( "Gracefully disconnect " + HOST );
|
||||
ipcon.disconnect();
|
||||
process.exit( );
|
||||
});
|
||||
@@ -73,4 +75,23 @@ 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!!
|
||||
});
|
||||
} catch(err) {
|
||||
Log.error(err.message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user