NodeJS MikroTik PoE status query example
This example builds on our previous posts NodeJS Mikrotik API minimal example and MikroTik RouterOS: How to power-cycle PoE using the terminal.
The following code will print the PoE statuson Port ether5
on the given MikroTik device using the MikroTik API.
import * as MikroNode from 'mikrotik' ;
const host = "192.168.88.1";
const username = "admin";
const password = "admin1234"; // Hope that's not your real password ;)
const connection = MikroNode.getConnection(host, username, password, {
closeOnDone : true
});
connection.getConnectPromise().then(function(conn) {
conn.getCommandPromise(['/interface/ethernet/poe/print', '?name=ether5']).then(values => {
console.log(values);
}, reason => {
console.log('Error while running command: ' + JSON.stringify(reason));
});
}).catch(reason => {
console.log('Error while connecting: ' + JSON.stringify(reason));
});
Example output:
[
{
'.id': '*5',
name: 'ether5',
'poe-out': 'forced-on',
'poe-priority': '10',
'poe-lldp-enabled': 'false',
'power-cycle-ping-enabled': 'false',
'power-cycle-interval': 'none',
'.about': 'poe-out status: power_reset'
}
]
If the PoE is currently being power-cycled, this will print:
[
{
'.id': '*5',
name: 'ether5',
'poe-out': 'forced-on',
'poe-priority': '10',
'poe-lldp-enabled': 'false',
'power-cycle-ping-enabled': 'false',
'power-cycle-interval': 'none',
'.about': 'poe-out status: power_reset'
}
]