-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
38 lines (30 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const http = require("http");
const dorita980 = require("dorita980");
const promClient = require("prom-client");
const irobotStatusGuage = new promClient.Gauge({
name: "roomba_state",
help: "The current state of the Roomba",
labelNames: ["ip"]
});
const roombaStatus = {
charging: 1
};
function isCharging(data) {
return data && data["cleanMissionStatus"] && data["cleanMissionStatus"]["phase"] === "charge";
}
const robot = new dorita980.Local(process.env.USERNAME, process.env.PASSWORD, process.env.ROOMBA_IP_ADDRESS);
robot.on("connect", () => {
console.log(`Connected to Roomba with IP: ${process.env.ROOMBA_IP_ADDRESS}`);
});
robot.on("mission", (data) => {
if (isCharging(data)) {
irobotStatusGuage.labels(process.env.ROOMBA_IP_ADDRESS).set(roombaStatus.charging);
}
});
robot.on("close", () => {
console.log("connection to robot closed");
});
const server = http.createServer((req, res) => {
res.end(promClient.register.metrics());
});
server.listen(process.env.PORT || 7000);