Created
December 3, 2019 00:05
-
-
Save stianeikeland/d4979d0e159cb8c280e4081150d020db to your computer and use it in GitHub Desktop.
Neato Botvac Charge Data logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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