prima versione qausi funzionante, non riconnette
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mikrotik-device',{
|
||||
RED.nodes.registerType('mikrotik-device-custom',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
host: { value: '192.168.0.1', required: true },
|
||||
@@ -12,11 +12,11 @@
|
||||
}
|
||||
});
|
||||
|
||||
RED.nodes.registerType('mikrotik',{
|
||||
RED.nodes.registerType('mikrotik-custom',{
|
||||
category: 'function',
|
||||
color: '#E9967A',
|
||||
defaults: {
|
||||
device: { value: '', type: "mikrotik-device" },
|
||||
device: { value: '', type: "mikrotik-device-custom" },
|
||||
name: {value:""},
|
||||
action: {value:"0"}
|
||||
},
|
||||
@@ -24,13 +24,13 @@
|
||||
outputs:1,
|
||||
icon: "feed.png",
|
||||
label: function() {
|
||||
return this.name||"mikrotik";
|
||||
return this.name||"mikrotik-custom";
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mikrotik-device">
|
||||
<script type="text/x-red" data-template-name="mikrotik-device-custom">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-host"><i class="fa fa-server"></i> Host</label>
|
||||
<input type="text" id="node-config-input-host">
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mikrotik">
|
||||
<script type="text/x-red" data-template-name="mikrotik-custom">
|
||||
<div class="form-row">
|
||||
<label for="node-input-device"><i class="fa fa-server"></i> Device</label>
|
||||
<select id="node-input-device"></select>
|
||||
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mikrotik">
|
||||
<script type="text/x-red" data-help-name="mikrotik-custom">
|
||||
<p>A node that work with Mikrotik WiFi routers.</p>
|
||||
<p>Read more about RouterOs API here: <a href="http://wiki.mikrotik.com/wiki/API_command_notes" target="_blank">http://wiki.mikrotik.com/wiki/API_command_notes</a>.</p>
|
||||
</script>
|
||||
@@ -1,7 +1,4 @@
|
||||
/**
|
||||
* Created by Bladerunner on 11/03/16.
|
||||
*/
|
||||
var mikrotik = require('mikronode-ng');
|
||||
var mikrotik = require('mikronode-ng2');
|
||||
|
||||
module.exports = function(RED) {
|
||||
function NodeMikrotikDevice(n) {
|
||||
@@ -11,7 +8,7 @@ module.exports = function(RED) {
|
||||
this.username = n.username;
|
||||
this.password = n.password;
|
||||
}
|
||||
RED.nodes.registerType("mikrotik-device", NodeMikrotikDevice);
|
||||
RED.nodes.registerType("mikrotik-device-custom", NodeMikrotikDevice);
|
||||
|
||||
|
||||
function NodeMikrotik(config) {
|
||||
@@ -25,7 +22,6 @@ module.exports = function(RED) {
|
||||
var port = this.device.port;
|
||||
var username = this.device.username;
|
||||
var password = this.device.password;
|
||||
|
||||
var command;
|
||||
|
||||
switch (parseInt(node.action)) {
|
||||
@@ -46,28 +42,30 @@ module.exports = function(RED) {
|
||||
break;
|
||||
}
|
||||
|
||||
var connection = null;
|
||||
connection = mikrotik.getConnection(host, username, password, {closeOnDone : false, port: port});
|
||||
var connection = mikrotik.getConnection(host, username, password, {closeOnDone : false, port: port});
|
||||
var conn = null;
|
||||
try {
|
||||
conn = connection.connect();
|
||||
} catch (error) {
|
||||
node.error(error);
|
||||
}
|
||||
|
||||
this.on('input', function(msg) {
|
||||
if (command == '') command = msg.payload;
|
||||
if (command == '') return false;
|
||||
connection.getConnectPromise().then(function resolve(conn) {
|
||||
conn.getCommandPromise(command).then(function resolved(values) {
|
||||
var parsed = mikrotik.parseItems(values);
|
||||
var pl = [];
|
||||
parsed.forEach(function(item) {
|
||||
pl.push(item);
|
||||
});
|
||||
msg.payload = values;
|
||||
node.send(msg);
|
||||
}, function rejected(reason) {
|
||||
node.error('Error executing cmd['+command+']: ' + JSON.stringify(reason));
|
||||
|
||||
conn.getCommandPromise(command).then(
|
||||
function resolved(values) { //promise resolved
|
||||
var parsed = mikrotik.parseItems(values);
|
||||
var pl = [];
|
||||
parsed.forEach(function(item) {
|
||||
pl.push(item);
|
||||
});
|
||||
msg.payload = values;
|
||||
node.send(msg);
|
||||
},
|
||||
function(err) {
|
||||
node.error("Connection error: " + err);
|
||||
function notresolved(reason) { //promise rejected
|
||||
node.error('Error executing cmd['+command+']: ' + JSON.stringify(reason));
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -77,7 +75,7 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("mikrotik", NodeMikrotik);
|
||||
RED.nodes.registerType("mikrotik-custom", NodeMikrotik);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "node-red-contrib-mikrotik3",
|
||||
"name": "node-red-contrib-mikrotik-custom",
|
||||
"version": "0.1.2",
|
||||
"description": "Node based on nodered-contrib-mikrotik to work with Mikrotik devices",
|
||||
"scripts": {
|
||||
@@ -14,7 +14,7 @@
|
||||
],
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"mikrotik": "mikrotik.js"
|
||||
"mikrotik": "mikrotik-custom.js"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
@@ -22,9 +22,9 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mikronode-ng": "^1.0.5"
|
||||
"mikronode-ng2": "^1.0.12"
|
||||
},
|
||||
"main": "mikrotik.js",
|
||||
"main": "mikrotik-custom.js",
|
||||
"devDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user