Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Neato Botvac Charge Data logger
{
"timestamp": "2019-12-03T00:01:01.274Z",
"Label": "Value",
"FuelPercent": "21",
"BatteryOverTemp": "0",
"ChargingActive": "0",
"ChargingEnabled": "1",
"ConfidentOnFuel": "0",
"OnReservedFuel": "0",
"EmptyFuel": "0",
"BatteryFailure": "1",
"ExtPwrPresent": "1",
"ThermistorPresent": "1",
"BattTempCAvg": "27",
"VBattV": "14.41",
"VExtV": "17.60",
"Charger_mAH": "0",
"Discharge_mAH": "0"
}
const SerialPort = require("serialport");
const Readline = require("@serialport/parser-readline");
const DATA_TIMEOUT = 5000;
const INTERVAL = 30000;
const PORT = "/dev/tty.usbmodemxxxx_xxxx_xxxx1";
const port = new SerialPort(PORT, { baudRate: 115200 })
const parser = new Readline()
port.pipe(parser)
// Pattern: Label,Value\n
const matcher = /^(?<label>.+),(?<value>.+)\n?$/
function logChargerValues() {
const output = {
timestamp: new Date()
};
const listener = (data) => {
const res = matcher.exec(data.trim());
if (res) {
const { groups: { label, value }} = res;
output[label] = value;
}
};
const finish = () => {
parser.off("data", listener);
console.log(JSON.stringify(output));
};
parser.on("data", listener);
setTimeout(finish, DATA_TIMEOUT);
port.write("GetCharger\n");
}
setInterval(logChargerValues, INTERVAL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.