Skip to content

Commit

Permalink
fixes tessel#395
Browse files Browse the repository at this point in the history
  • Loading branch information
Frijol authored and HipsterBrown committed Dec 3, 2015
1 parent 4eaee1d commit d80cab0
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions lib/tessel/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,41 @@ Tessel.prototype.setWiFiState = function(enable) {
.then(() => this.simpleExec(commands.ubusListen())
.then((remoteProcess) => {
if (enable) {
this.receive(remoteProcess)
.then(function(data) {
if (data.indexOf('ifup') > -1) {
logs.info('Successfully connected!');
}
})
.catch(function(error) {
logs.err('Error connecting:', error);
});
setTimeout(() => {
logs.info("Timed out waiting to verify connection. Run `t2 wifi` to manually verify connection. If not connected, ensure you have entered the correct network credentials.");
var result = {};
var timeout = setTimeout(function() {
result = {
type: 'reject',
message: 'Timed out waiting to verify connection. Run `t2 wifi` to manually verify connection. If not connected, ensure you have entered the correct network credentials.'
};
// End the connection
return this.connection.end();
remoteProcess.close();
}, 10000);
remoteProcess.stdout.on('data', function(data) {
if (data.indexOf('ifup') > -1) {
logs.info('Successfully connected!');
clearTimeout(timeout);
result = {
type: 'resolve',
message: '' // resolve doesn't report messages
};
remoteProcess.close();
}
});
remoteProcess.stderr.on('data', function(error) {
clearTimeout(timeout);
result = {
type: 'reject',
message: error
};
remoteProcess.close();
});
remoteProcess.on('close', function() {
if (result.type === 'reject') {
Promise.reject(result.message);
} else {
Promise.resolve();
}
});
} else {
return this.connection.end();
}
Expand Down

0 comments on commit d80cab0

Please sign in to comment.