Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for FW version 3 and Braava m6 #103

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function cloud (username, password, version) {
return cloudV2(username, password);
}

function local (username, password, ip, version, interval) {
function local (username, password, ip, version, interval, model) {
if (version === 1) return localV1(username, password, ip);
return localV2(username, password, ip, interval);
return localV2(username, password, ip, interval, version, model);
}

module.exports = {
Expand Down
44 changes: 38 additions & 6 deletions lib/v2/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

const mqtt = require('mqtt');

var dorita980 = function localV2 (user, password, host, emitIntervalTime) {
var dorita980 = function localV2 (user, password, host, emitIntervalTime, version, model) {
if (!user) throw new Error('robotID is required.');
if (!password) throw new Error('password is required.');
if (!host) throw new Error('host is required.');

const posibleCap = ['pose', 'ota', 'multiPass', 'carpetBoost', 'pp', 'binFullDetect', 'langOta', 'maps', 'edge', 'eco', 'svcConf'];
const versionProps = {
2: ['audio', 'soundVer', 'cleanSchedule', 'uiSwVer', 'navSwVer', 'wifiSwVer', 'mobilityVer', 'bootloaderVer', 'umiVer'],
3: ['subModSwVer', 'cleanSchedule2']
};
const modelProps = {
'roomba': ['bin'],
'braava': ['detectedPad', 'mopReady', 'padWetness']
};
version = version || 2;
emitIntervalTime = emitIntervalTime || 800;
var robotState = {};
var cap = null;
Expand Down Expand Up @@ -45,17 +54,29 @@ var dorita980 = function localV2 (user, password, host, emitIntervalTime) {
clearInterval(missionInterval);
});

const defaultPose = { 'theta': 0, 'point': { 'x': 0, 'y': 0 } };

client.on('packetreceive', function (packet) {
if (packet.payload) {
try {
const msg = JSON.parse(packet.payload.toString());
robotState = Object.assign(robotState, msg.state.reported);
if (!robotState.pose) {
robotState.pose = defaultPose;
}
client.emit('update', msg);
client.emit('state', robotState);
if (robotState.cap) {
cap = {};
cap = Object.assign(cap, robotState.cap);
}
if (!model && robotState.sku) {
if (robotState.sku.toLowerCase().startsWith('m6')) {
model = 'braava';
} else {
model = 'roomba';
}
}
} catch (e) {}
}
});
Expand All @@ -81,6 +102,16 @@ var dorita980 = function localV2 (user, password, host, emitIntervalTime) {
if (posibleCap.indexOf(properties[p]) > -1 && cap && Object.keys(cap).indexOf(properties[p]) === -1) {
obj[properties[p]] = undefined; // asking for a non available capability, just set to undefined
}
for (var ver in versionProps) {
if (ver !== version && versionProps[ver].indexOf(properties[p]) > -1) {
obj[properties[p]] = undefined; // this is a property for a different version of API
}
}
for (var mod in modelProps) {
if (mod !== model && modelProps[mod].indexOf(properties[p]) > -1) {
obj[properties[p]] = undefined; // this is a property for a different model
}
}
if (!obj.hasOwnProperty(properties[p])) {
return false;
}
Expand Down Expand Up @@ -113,15 +144,16 @@ var dorita980 = function localV2 (user, password, host, emitIntervalTime) {
getTime: () => waitPreferences(false, ['utctime'], true),
getBbrun: () => waitPreferences(false, ['bbrun'], true),
getLangs: () => waitPreferences(false, ['langs'], true),
getSys: () => waitPreferences(false, ['bbrstinfo', 'cap', 'sku', 'batteryType', 'soundVer', 'uiSwVer', 'navSwVer', 'wifiSwVer', 'mobilityVer', 'bootloaderVer', 'umiVer', 'softwareVer', 'audio', 'bin'], true),
getSys: () => waitPreferences(false, ['bbrstinfo', 'cap', 'sku', 'batteryType', 'soundVer', 'uiSwVer', 'navSwVer', 'wifiSwVer', 'mobilityVer', 'bootloaderVer', 'umiVer', 'softwareVer', 'audio', 'bin', 'subModSwVer', 'secureBoot', 'detectedPad'], true),
getWirelessLastStatus: () => waitPreferences(false, ['wifistat', 'wlcfg'], true),
getWeek: () => waitPreferences(false, ['cleanSchedule'], true),
getPreferences: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'cleanSchedule', 'name', 'vacHigh', 'signal'], false),
getWeek: () => waitPreferences(false, ['cleanSchedule', 'cleanSchedule2'], true),
getPreferences: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'cleanSchedule', 'cleanSchedule2', 'name', 'vacHigh', 'signal'], false),
getRobotState: (fields) => waitPreferences(false, fields, false),
getMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'pose', 'bin', 'batPct'], true),
getBasicMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'bin', 'batPct'], true),
getMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'pose', 'bin', 'batPct', 'detectedPad', 'mopReady', 'padWetness'], true),
getBasicMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'bin', 'batPct', 'detectedPad', 'mopReady', 'padWetness'], true),
getWirelessConfig: () => waitPreferences(false, ['wlcfg', 'netinfo'], true),
getWirelessStatus: () => waitPreferences(false, ['wifistat', 'netinfo'], true),
getModel: () => new Promise((resolve) => resolve(model)),
getCloudConfig: () => waitPreferences(false, ['cloudEnv'], true),
getSKU: () => waitPreferences(false, ['sku'], true),
start: () => _apiCall('cmd', 'start'),
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dorita980",
"version": "3.1.8",
"version": "3.2.0",
"description": "Unofficial iRobot Roomba 980 and wifi other enabled series library sdk",
"main": "./index.js",
"directories": {
Expand Down Expand Up @@ -39,13 +39,15 @@
"unofficial",
"iRobot",
"Roomba",
"Braava",
"980",
"wifi",
"i7",
"e5",
"960",
"690",
"675",
"m6",
"library",
"sdk",
"robot",
Expand Down