Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions bin/tessel-wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var argv = require("nomnom")
})
.option('security', {
abbr: 's',
default: 'wpa2',
help: '[Tessel] Security type of the network, one of (wpa2|wpa|wep). Omit for unsecured networks.'
})
.option('timeout', {
Expand Down Expand Up @@ -98,7 +97,28 @@ common.controller({stop: false}, function (err, client) {
pass = new Buffer(String(pass));
}

var security = new Buffer((String(argv.security) || (pass ? 'wpa2' : 'unsecure')).toLowerCase());
var security = argv.security;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalize toLowerCase() here instead of multiple times later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argv.security can be undefined if its not specified

if (!pass.length) {
if (security && security.toLowerCase() != 'unsecure') {
// there is no password and security was specified
logs.err('A password is needed for', security);
client.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control flow won't stop here!

process.exit(1);
} else {
// if there isn't a password then assume security type is unsecure
security = new Buffer('unsecure');
}
} else if (!security) {
// if there is no security specified, default to wpa2
security = new Buffer('wpa2');
} else if (security.toLowerCase() == 'unsecure') {
logs.err('Cannot connect to an unsecure network with a password specified');
client.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control flow won't stop here!

process.exit(1);
} else {
// otherwise use chosen security type
security = new Buffer(security.toLowerCase());
}

client.configureWifi(ssid, pass, security, {
timeout: argv.timeout
Expand Down