From 469211f803800b9c77c25fc2080d65027d8ba45f Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 20 Apr 2020 13:31:01 -0700 Subject: [PATCH] Minor fixes to MeshCtrl. --- meshctrl.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/meshctrl.js b/meshctrl.js index 01328c72..8ebf4135 100644 --- a/meshctrl.js +++ b/meshctrl.js @@ -43,7 +43,7 @@ if (args['_'].length == 0) { console.log(" --token [number] - 2nd factor authentication token."); console.log(" --loginkey [hex] - Server login key in hex."); console.log(" --loginkeyfile [file] - File containing server login key in hex."); - console.log(" --domain [domainid] - Domain id, default is empty."); + console.log(" --domain [domainid] - Domain id, default is empty, only used with loginkey."); console.log(" --proxy [http://proxy:1] - Specify an HTTP proxy."); return; } else { @@ -552,10 +552,12 @@ function serverConnect() { if (args.domain != null) { domainid = args.domain; } if (args.loginuser != null) { username = args.loginuser; } url += '?auth=' + encodeCookie({ userid: 'user/' + domainid + '/' + username, domainid: domainid }, ckey); + } else { + if (args.domain != null) { console.log("--domain can only be used along with --loginkey."); process.exit(); return; } } const ws = new WebSocket(url, options); - //console.log('Connecting...'); + //console.log('Connecting to ' + url); ws.on('open', function open() { //console.log('Connected.'); @@ -706,7 +708,6 @@ function serverConnect() { }); ws.on('message', function incoming(rawdata) { - //console.log(rawdata); var data = null; try { data = JSON.parse(rawdata); } catch (ex) { } if (data == null) { console.log('Unable to parse data: ' + rawdata); } @@ -809,15 +810,18 @@ function serverConnect() { console.log(JSON.stringify(nodes, ' ', 2)); } else { // Display the list of nodes in text format + var nodecount = 0; for (var i in data.nodes) { var devicesInMesh = data.nodes[i]; if (settings.xmeshes) { console.log('\r\nDevice group: \"' + settings.xmeshes[i].name + '\"'); } console.log('id, name, icon, conn, pwr, ip\r\n-----------------------------'); for (var j in devicesInMesh) { var n = devicesInMesh[j]; + nodecount++; console.log(n._id.split('/')[2] + ', \"' + n.name + '\", ' + (n.icon ? n.icon : 0) + ', ' + (n.conn ? n.conn : 0) + ', ' + (n.pwr ? n.pwr : 0)); } } + if (nodecount == 0) { console.log('None'); } } } process.exit();