Skip to content

Commit

Permalink
fixes #395
Browse files Browse the repository at this point in the history
  • Loading branch information
Frijol committed Nov 26, 2015
1 parent 68cb254 commit 705ce1e
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions lib/tessel/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,48 @@ Tessel.prototype.connectToNetwork = function(opts) {
// Once the credentials have been comitted
remoteProcess.once('close', function() {
// Restart the wifi
return self.connection.exec(commands.reconnectWifi())
.then(function(remoteProcess) {
return self.simpleExec(commands.reconnectWifi())
.then(function() {
// Once the wifi restart process closes
return self.receive(remoteProcess).then(function() {
logs.info('Credentials set. Checking connection...');
self.connection.exec(commands.ubusListen())
.then(function(remoteProcess) {
self.receive(remoteProcess).then(function(data) {
if (data.indexOf('ifup') > -1) {
logs.info('Successfully connected!');
return resolve();
}
})
.catch(function(error) {
logs.err('Error connecting:', error);
return resolve();
});
setTimeout(function() {
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.');
// End the connection
return self.connection.end()
.then(resolve);
}, 10000);
logs.info('Credentials set. Checking connection...');
self.connection.exec(commands.ubusListen())
.then(function(remoteProcess) {
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
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') {
reject(result.message);
} else {
resolve();
}
});
});
});
});
});
Expand Down

0 comments on commit 705ce1e

Please sign in to comment.