-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ap): initial access point creation implementation
- Loading branch information
1 parent
e7299f0
commit 8ccd1a0
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var Tessel = require('./tessel'), | ||
commands = require('./commands'), | ||
logs = require('../logs'); | ||
|
||
function commitAndClose(resolve) { | ||
var self = Tessel; | ||
|
||
return self.connection.exec(commands.commitWirelessCredentials()) | ||
.then(function(remoteProcess) { | ||
remoteProcess.once('close', function() { | ||
return self.connection.exec(commands.reconnectWifi()) | ||
.then(function(remoteProcess) { | ||
return self.receive(remoteProcess).then(function() { | ||
logs.info('Access Point credentials set!'); | ||
|
||
return self.connection.end() | ||
.then(resolve); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
Tessel.prototype.createAccessPoint = function(opts) { | ||
var self = this; | ||
var ssid = opts.ssid; | ||
var password = opts.password; | ||
var security = opts.security; | ||
|
||
return new Promise(function(resolve, reject) { | ||
if (!ssid) { | ||
return reject(new Error('Invalid credentials. Must set ssid')); | ||
} | ||
|
||
if (!password || !security) { | ||
if (!security) { | ||
logs.info('Setting Access Point with SSID:', ssid, 'and password:', password, 'and security mode:', security); | ||
} else { | ||
logs.info('Setting Access Point with SSID:', ssid, 'and password:', password); | ||
} | ||
} else { | ||
logs.info('Setting Access Point with SSID:', ssid); | ||
} | ||
|
||
return self.connection.exec(commands.setAccessPointSSID(ssid)) | ||
.then(function() { | ||
if (password) { | ||
return self.connection.exec(commands.setAccessPointPassword(password)); | ||
} else { | ||
return commitAndClose(resolve); | ||
} | ||
}) | ||
.then(function() { | ||
if (security) { | ||
return self.connection.exec(commands.setAccessPointSecurity(security)); | ||
} else { | ||
return commitAndClose(resolve); | ||
} | ||
}) | ||
.then(function() { | ||
return self.connection.exec(commands.turnAccessPointOn(true)) | ||
.then(commitAndClose.bind(null, resolve)); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters