Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
CleanOMat980Platform.prototype.command = function (command) {
// send command to the robot
var that = this
let cred = this.credentials()
if (cred != undefined) {
this.myRobotViaLocal = new dorita980.Local(cred.blid, cred.pwd, cred.ip); // robot IP address
this.myRobotViaLocal.on('connect', function () {
that.log.debug('connected to robot')
switch (command) {
case 'start':
setTimeout(function(){
that.log.debug('start command')
that.myRobotViaLocal.start().then(() => {
that.log.debug('end connection')
that.myRobotViaLocal.end();
}).catch((err) => {
that.log.error(err);
});
}, 500);
function connect(user, password, ip)
{
adapter.log.info('Connecting to Roomba (' + ip + ')..');
try
{
return new _dorita980.Local(user, password, ip);
}
catch(err)
{
adapter.log.error('Could not connect to Roomba! See debug for more details.');
adapter.log.debug(err.message); // this will not be trigged due to an issue in dorita980 library (see https://github.com/koalazak/dorita980/issues/75 )
return false;
}
}
function connect(user, password, ip)
{
adapter.log.info('Connecting to Roomba..');
try
{
return new _dorita980.Local(user, password, ip);
}
catch(err)
{
adapter.log.warn(err.message); // this will not be trigged due to an issue in dorita980 library (see https://github.com/koalazak/dorita980/issues/75)
}
}
var knownIP = robotIP;
var firmwareVersion = parseInt((process.env.FIRMWARE_VERSION || config.firmwareVersion || 1), 10);
var enableLocal = process.env.ENABLE_LOCAL || config.enableLocal || 'yes';
var enableCloud = process.env.ENABLE_CLOUD || config.enableCloud || 'yes';
var keepAlive = process.env.KEEP_ALIVE || config.keepAlive || 'yes';
// Temporal:
if (firmwareVersion === 2) enableCloud = 'no';
if (!blid || !password) {
throw new Error('Config not found. Please edit config/default.json file with your robot credentials. Or set BLID, PASSWORD and ROBOT_IP enviroment variables.');
}
var myRobot = {};
var handleIP = (robotIP || enableLocal === 'no') ? function (cb) { cb(null, robotIP); } : dorita980.getRobotIP;
handleIP(function (e, ip) {
if (e) throw e;
knownIP = ip;
if (enableLocal === 'yes') {
if (firmwareVersion === 1 || (keepAlive === 'yes')) myRobot.local = new dorita980.Local(blid, password, ip, firmwareVersion);
}
if (enableCloud === 'yes') myRobot.cloud = new dorita980.Cloud(blid, password, firmwareVersion);
});
router.get('/', function (req, res) {
res.send({
version: '1.0.' + firmwareVersion}
);
});
/*
function sendAndDisconnect (method, args, res, next) {
let client = new dorita980.Local(blid, password, knownIP, 2);
client.on('connect', function () {
client[method](args).then(function (resp) {
res.send(resp);
client.end();
}).catch(next);
});
}
handleIP(function (e, ip) {
if (e) throw e;
knownIP = ip;
if (enableLocal === 'yes') {
if (firmwareVersion === 1 || (keepAlive === 'yes')) myRobot.local = new dorita980.Local(blid, password, ip, firmwareVersion);
}
if (enableCloud === 'yes') myRobot.cloud = new dorita980.Cloud(blid, password, firmwareVersion);
});
break;
/*
case 'encrypt':
adapter.log.debug('Encrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {password: encryptor.encrypt(adapter.config.encryptionKey, msg.message.cleartext)}}, msg.callback);
break;
case 'decrypt':
adapter.log.debug('Decrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {cleartext: encryptor.decrypt(adapter.config.encryptionKey, msg.message.password)}}, msg.callback);
break;
*/
case 'getIp':
_dorita980.getRobotIP(function(err, ip)
{
adapter.log.debug('Retrieved IP address: ' + ip);
library.msg(msg.from, msg.command, err ? {result: false, error: err.message} : {result: true, data: {ip: ip}}, msg.callback);
});
break;
case 'getRobotData':
getRobotData(function(res)
{
adapter.log.debug('Retrieved robot data: ' + JSON.stringify(res));
library.msg(msg.from, msg.command, res, msg.callback);
}, msg.message !== null ? msg.message.ip : undefined);
break;
case 'getPassword':
msg.message.encryption = msg.message.encryption === undefined ? true : msg.message.encryption;
break;
/*
case 'encrypt':
adapter.log.debug('Encrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {password: encryptor.encrypt(adapter.config.encryptionKey, msg.message.cleartext)}}, msg.callback);
break;
case 'decrypt':
adapter.log.debug('Decrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {cleartext: encryptor.decrypt(adapter.config.encryptionKey, msg.message.password)}}, msg.callback);
break;
*/
case 'getIp':
_dorita980.getRobotIP(function(err, ip)
{
adapter.log.debug('Retrieved IP address: ' + ip);
library.msg(msg.from, msg.command, err ? {result: false, error: err.message} : {result: true, data: {ip: ip}}, msg.callback);
});
break;
case 'getRobotData':
getRobotData(function(res)
{
adapter.log.debug('Retrieved robot data: ' + JSON.stringify(res));
library.msg(msg.from, msg.command, res, msg.callback);
}, msg.message !== null ? msg.message.ip : undefined);
break;
case 'getPassword':
msg.message.encryption = msg.message.encryption === undefined ? true : msg.message.encryption;
handleIP(function (e, ip) {
if (e) throw e;
knownIP = ip;
if (enableLocal === 'yes') {
if (firmwareVersion === 1 || (keepAlive === 'yes')) myRobot.local = new dorita980.Local(blid, password, ip, firmwareVersion);
}
if (enableCloud === 'yes') myRobot.cloud = new dorita980.Cloud(blid, password, firmwareVersion);
});