reconnect
This commit is contained in:
@@ -6,9 +6,23 @@ var Tinkerforge = require('../Tinkerforge')
|
||||
|
||||
|
||||
Helper.each(Conf.items, function(item) {
|
||||
connect(item);
|
||||
});
|
||||
|
||||
|
||||
/* private */
|
||||
function reconnect(item) {
|
||||
Log.debug('Reconnect ' + item.host);
|
||||
setTimeout(connect(item), 10000);
|
||||
}
|
||||
|
||||
/* private */
|
||||
function connect(item) {
|
||||
var HOST = item.host;
|
||||
var PORT = item.port;
|
||||
var UID = item.uid;
|
||||
|
||||
Log.log('Init ' + UID + ' @' + HOST);
|
||||
|
||||
var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
|
||||
var md = new Tinkerforge.BrickletMotionDetector(UID, ipcon); // Create device object
|
||||
@@ -29,7 +43,12 @@ Helper.each(Conf.items, function(item) {
|
||||
IPConnection.ERROR_FUNCTION_NOT_SUPPORTED = 42
|
||||
IPConnection.ERROR_UNKNOWN_ERROR = 43
|
||||
*/
|
||||
Log.log('Error: ' + error);
|
||||
|
||||
Log.error('Error @'+HOST+': ' + error);
|
||||
|
||||
if(error === 13) {
|
||||
reconnect(item);
|
||||
}
|
||||
}
|
||||
); // Connect to brickd
|
||||
// Don't use device before ipcon is connected
|
||||
@@ -55,8 +74,7 @@ Helper.each(Conf.items, function(item) {
|
||||
ipcon.disconnect();
|
||||
process.exit( );
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* private */
|
||||
function doMotionCall(options) {
|
||||
@@ -70,7 +88,7 @@ function doMotionCall(options) {
|
||||
|
||||
//the whole response has been recieved, so we just print it out here
|
||||
response.on('end', function () {
|
||||
Log.log(str);
|
||||
Log.log(HOST + ': ' + str);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,7 +97,7 @@ function doMotionCall(options) {
|
||||
});
|
||||
|
||||
req.on('error', function(err) {
|
||||
Log.error(err);
|
||||
Log.error(HOST + ': ' + err);
|
||||
});
|
||||
|
||||
req.end();
|
||||
|
||||
Reference in New Issue
Block a user