-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add neutral wifi command to list Tessel Wifi Information #282
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -451,6 +451,48 @@ controller.printAvailableNetworks = function(opts) { | |
}); | ||
}; | ||
|
||
controller.getWifiInfo = function(opts) { | ||
return Tessel.get(opts) | ||
.then(function(selectedTessel) { | ||
return selectedTessel.getWifiInfo() | ||
.then(function(network) { | ||
// Grab inet lines, flatmap them, remove empty | ||
var ips = network.ips.filter(function(item) { | ||
return /inet/.exec(item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the Tessel isn't connected to WiFi? |
||
}) | ||
.map(function(line) { | ||
return line.split(' '); | ||
}) | ||
.reduce(function(a, b) { | ||
return a.concat(b); | ||
}) | ||
.filter(function(item) { | ||
return /addr/.exec(item); | ||
}) | ||
.map(function(chunk) { | ||
return chunk.split(':')[1]; | ||
}) | ||
.filter(function(addr) { | ||
return addr.length; | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see this consolidated. The last three could be a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the intent of the code is clear, why consolidate I can replace the last three with the following .reduce(function(list, ip) {
if (/addr/.exec(item)) {
var ip = chunk.split(':')[1];
if (ip.length) list.push[ip];
}
return list;
}); But it doesn't make it more clear (to me) what is happening. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :/ This is what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change it if that's wanted, but I don't think it's clearer. On Tue, Sep 8, 2015 at 10:08 AM, Rick Waldron notifications@github.com
|
||
logs.info('Connected to "' + network.ssid + '"'); | ||
ips.forEach(function(ip) { | ||
logs.info('IP Address: ' + ip); | ||
}); | ||
logs.info('Signal Strength: (' + network.quality + '/' + network.quality_max + ')'); | ||
logs.info('Bitrate: ' + Math.round(network.bitrate / 1000) + 'mbps'); | ||
}) | ||
.catch(function(err) { | ||
// Handle no Wi-Fi | ||
logs.err(err.message); | ||
}) | ||
.finally(function() { | ||
return controller.closeTesselConnections(selectedTessel); | ||
}); | ||
}); | ||
}; | ||
|
||
controller.connectToNetwork = function(opts) { | ||
// Grab the preferred Tessel | ||
return Tessel.get(opts) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move the SSID and Password check here (which makes sense so you don't have to wait for it to connect to a Tessel) we might as well remove the check that already exists here: https://github.com/tessel/t2-cli/pull/282/files#diff-ad1c3af214118b233a97e4dd4f67d729R127
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MrNice On second thought, I take this back. Once we make this CLI more usable from other Node programs, it would be great if we could export functions so having this extra check doesn't hurt. In fact, because this check is removed they are causing this test and this test to fail right now.