Datasheet

MikroNode
89
chan3.write(['/interface/set','=disabled=yes','=.id=ether1'],function(chan) {
chan.on('done',function(d,chan) {
// We do this here, 'cause we want channel 4 to write after channel 3 is done.
var chan4=conn.openChannel(4); // We'll use this later.
chan4.closeOnDone(true);
chan4.write(['/interface/set','=disabled=no','=.id=ether1'],function() {
var chan5=conn.openChannel(5);
chan5.closeOnDone(true);
chan5.write('/interface/getall',function(chan) {
chan.on('done',function(data) {
packets=api.parseItems(data);
packets.forEach(function(packet) {
console.log('Interface: '+JSON.stringify(packet));
});
chan2.close(); // This should call the /cancel command to stop the listen.
});
});
})
});
});
});
Simplifying the above by reducing the number of channels.
Notice how the callback embedding is not needed using the syncronous capability.
var api = require('mikronode');
var connection = new api('192.168.0.1','admin','password');
connection.connect(function(conn) {
conn.closeOnDone(true); // All channels need to complete before the connection will close.
var listenChannel=conn.openChannel();
listenChannel.write('/interface/listen',function(chan) {
chan.on('read',function(data) {
packet=api.parseItems([data])[0];
console.log('Interface change: '+JSON.stringify(packet));
});
});
var actionChannel=conn.openChannel();
// These will run synchronsously
actionChannel.write(['/interface/set','=disabled=yes','=.id=ether1']); // don't care to do anything after it's done.
actionChannel.write(['/interface/set','=disabled=no','=.id=ether1']); // don't care to do anything after it's done.
actionChannel.write('/interface/getall',function(chan) {
chan.on('done',function(data) {
packets=api.parseItems(data);
packets.forEach(function(packet) {