Datasheet

MikroNode
88
unaltered.
channel.close(force)
Close the channel. If there are any commands still waiting to be executed, they will be completed before
closing the channel.
If force is TRUE, then the channel is immediately closed. If the channel is running, the cancel command
is sent to stop any running listen commands, or potentially long running output.
Examples
Connect to a Mikrotik, and add an address to ether1
var api = require('mikronode');
var connection = new api('192.168.0.1','admin','password');
connection.connect(function(conn) {
var chan=conn.openChannel();
chan.write(['/ip/address/add','=interface=ether1','=address=192.168.1.1'],function() {
chan.on('trap',function(data) {
console.log('Error setting IP: '+data);
});
chan.on('done',function(data) {
console.log('IP Set.');
});
chan.close();
conn.close();
});
});
Writing the program for the example API conversation on the Mikrotik Wiki
var api = require('mikronode');
var connection = new api('192.168.0.1','admin','password');
connection.connect(function(conn) {
conn.closeOnDone(true);
var chan2=conn.openChannel(2);
chan2.write('/interface/listen',function(chan) {
chan.on('read',function(data) {
packet=api.parseItems([data])[0];
console.log('Interface change: '+JSON.stringify(packet));
});
});
var chan3=conn.openChannel(3);
chan3.closeOnDone(true);