-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cc3a97
commit c9c4164
Showing
5 changed files
with
108 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
node_modules | ||
dist | ||
examples | ||
test | ||
.vscode | ||
.jshintrc | ||
jsconfig.json | ||
webpack.config.babel.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
var MikroNode = require('../dist/mikronode.js'); | ||
|
||
// Create API link to host. No connection yet.. | ||
var device = new MikroNode('10.10.10.10'); | ||
|
||
// Debug level is "DEBUG" | ||
// device.setDebug(MikroNode.DEBUG); | ||
|
||
var removeId=[]; | ||
// Connect to the MikroTik device. | ||
device.connect() | ||
.then(([login])=>login('username','password')) | ||
.then(function(conn) { | ||
|
||
console.log("Connected") | ||
// var channel=conn.openChannel('all_addresses'); | ||
// channel.closeOnDone(true); // only use this channel for one command. | ||
var listener=conn.openChannel('address_changes'); | ||
listener.closeOnDone(true); // only use this channel for one command. | ||
|
||
// channel.write('/ip/address/print'); | ||
listener.write('/log/listen'); | ||
// channel.write('/ip/firewall/filter/print'); | ||
|
||
listener.data.filter(d=>d.data[d.data.length-1].field!=='.dead').subscribe(d=>{ | ||
const data = MikroNode.resultsToObj(d.data.filter(col=>["time","topics","message"].indexOf(col.field)!=-1)); | ||
console.log("Log:",JSON.stringify(data)); | ||
}); | ||
|
||
// in 5 seconds, stop listening for address changes. | ||
setTimeout(function() { | ||
console.log("Closing out listener"); | ||
listener.write('/cancel'); /* cancel listen */ | ||
},500000); | ||
}).catch(function(err) { | ||
console.log("Failed to connect. ",err); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters