-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
35 lines (32 loc) · 1 KB
/
app.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
const LCD = require("raspberrypi-liquid-crystal");
const cp = require("child_process");
//Init display
const lcd = new LCD(1, 0x27, 16, 2);
lcd.beginSync();
async function getDetails() {
try {
// Get Switch info from command line
const lldpcli = await cp.spawnSync("lldpcli", ["sh", "nei", "-f", "json"]);
const output = lldpcli.stdout.toString();
const outputJSON = JSON.parse(output);
const port = outputJSON.lldp.interface.eth0.port.id.value;
const sw = Object.keys(outputJSON.lldp.interface.eth0.chassis);
const swname = sw[0];
// Clear any previously displayed content
lcd.clearSync();
// Write to LCD
lcd.printLineSync(0, swname.slice(-16));
lcd.printLineSync(1, port);
//Write to command line
console.log(swname.slice(16), port);
return;
} catch (error) {
//if no connection then display waiting
lcd.clearSync();
lcd.printLineSync(0, "Waiting...");
}
}
//Run above function every 5 seconds
setInterval(() => {
getDetails();
}, 5000);