Minor fixes to MeshCtrl.

Ylian Saint-Hilaire committed Apr 20, 2020 at 13:31 UTC 469211f803800b9c77c25fc2080d65027d8ba45f
1 file changed +7 -3
meshctrl.js
+7 -3
@@ -43,7 +43,7 @@ if (args['_'].length == 0) {
43 console.log(" --token [number] - 2nd factor authentication token.");
44 console.log(" --loginkey [hex] - Server login key in hex.");
45 console.log(" --loginkeyfile [file] - File containing server login key in hex.");
46 - console.log(" --domain [domainid] - Domain id, default is empty.");
46 + console.log(" --domain [domainid] - Domain id, default is empty, only used with loginkey.");
47 console.log(" --proxy [http://proxy:1] - Specify an HTTP proxy.");
48 return;
49 } else {
@@ -552,10 +552,12 @@ function serverConnect() {
552 if (args.domain != null) { domainid = args.domain; }
553 if (args.loginuser != null) { username = args.loginuser; }
554 url += '?auth=' + encodeCookie({ userid: 'user/' + domainid + '/' + username, domainid: domainid }, ckey);
555 + } else {
556 + if (args.domain != null) { console.log("--domain can only be used along with --loginkey."); process.exit(); return; }
557 }
558
559 const ws = new WebSocket(url, options);
558 - //console.log('Connecting...');
560 + //console.log('Connecting to ' + url);
561
562 ws.on('open', function open() {
563 //console.log('Connected.');
@@ -706,7 +708,6 @@ function serverConnect() {
708 });
709
710 ws.on('message', function incoming(rawdata) {
709 - //console.log(rawdata);
711 var data = null;
712 try { data = JSON.parse(rawdata); } catch (ex) { }
713 if (data == null) { console.log('Unable to parse data: ' + rawdata); }
@@ -809,15 +810,18 @@ function serverConnect() {
810 console.log(JSON.stringify(nodes, ' ', 2));
811 } else {
812 // Display the list of nodes in text format
813 + var nodecount = 0;
814 for (var i in data.nodes) {
815 var devicesInMesh = data.nodes[i];
816 if (settings.xmeshes) { console.log('\r\nDevice group: \"' + settings.xmeshes[i].name + '\"'); }
817 console.log('id, name, icon, conn, pwr, ip\r\n-----------------------------');
818 for (var j in devicesInMesh) {
819 var n = devicesInMesh[j];
820 + nodecount++;
821 console.log(n._id.split('/')[2] + ', \"' + n.name + '\", ' + (n.icon ? n.icon : 0) + ', ' + (n.conn ? n.conn : 0) + ', ' + (n.pwr ? n.pwr : 0));
822 }
823 }
824 + if (nodecount == 0) { console.log('None'); }
825 }
826 }
827 process.exit();