Hi there.
I've created a NodeJS Module for communication with Robonect enabled mowers.
The project has just started and it can be found at https://github.com/allan-gam/node-robonect-api
The purpose is to constantly watch the Status of the mower and send event updates to your home automation system. In my case I use Domoticz but it can be used for any home automation system that has a web API.
Currently the script polls the Robonect Status every 5 seconds. It might happen that it can be done in a better way. Ideally there would be an even stream in Roboconect API to connect to.
My project is just a start and it's my first NodeJS app. Maybe there are some experienced guys among you who'd like to improve it. In such case, collaborators/co developers are warmly welcomed.
Below is a script example how I use it to send events to Domoticz.
Code: Alles auswählen
#!/usr/bin/nodejs
var STATUS = new Array();
STATUS[0] = "Status is determined";
STATUS[1] = "Parked";
STATUS[2] = "Moving";
STATUS[3] = "Looking";
STATUS[4] = "Loading";
STATUS[5] = "Searching";
STATUS[7] = "Error";
STATUS[8] = "Lost signal";
STATUS[16] = "Switched off";
STATUS[17] = "Sleeping";
var TIMERSTATUS = new Array();
TIMERSTATUS[0] = "Disabled";
TIMERSTATUS[1] = "Active";
TIMERSTATUS[2] = "Stand by";
var mower = require('node-robonect-api');
var request = require("request");
// Options:
var options = {
host : '192.168.1.111',
port : '80',
user : 'john',
pass : 'smith',
log : false,
};
var robonect = new mower.robonect(options);
// Monitor Glenn, the lawn mower
robonect.on('mowerEvent', function(mowerName, category, eventType, eventValue) {
//console.log(mowerName, category, eventType, eventValue);
if (category === 'status' && eventType === 'status') setDomoDevice(mowerName, eventType, 568, STATUS[eventValue])
if (category === 'timer' && eventType === 'status') setDomoDevice(mowerName, eventType, 569, TIMERSTATUS[eventValue])
if (category === 'status' && eventType === 'battery') setDomoDevice(mowerName, eventType, 570, eventValue)
});
function getDateTime() {
var date = new Date();
var hour = date.getHours();
hour = (hour < 10 ? "0" : "") + hour;
var min = date.getMinutes();
min = (min < 10 ? "0" : "") + min;
var sec = date.getSeconds();
sec = (sec < 10 ? "0" : "") + sec;
var year = date.getFullYear();
var month = date.getMonth() + 1;
month = (month < 10 ? "0" : "") + month;
var day = date.getDate();
day = (day < 10 ? "0" : "") + day;
return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
}
function setDomoDevice(mowername, eventType, idx, sValue) {
request("http://domoticzhost:8080/json.htm?type=command¶m=udevice&nvalue=0&idx=" + idx + "&svalue=" + sValue, function(error, response, body) {
console.log(getDateTime() + ' ' + mowername + ' ' + eventType + ' ' + idx + ' ' + sValue);
})
}
function printOut(mowername, eventType, idx, sValue) {
console.log(getDateTime() + ' ' + mowername + ' ' + eventType + ' ' + idx + ' ' + sValue);
}
Cheers!