Skip to content

Commit

Permalink
feat(access-point): adds ability to enable/disable AP
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Nov 16, 2015
1 parent a4af351 commit af1d41d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
12 changes: 10 additions & 2 deletions bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,20 @@ makeCommand('ap')
help: 'Encryption to use on network (i.e. WEP, WPA, PSK).'
})
.option('trigger', {
position: 0,
position: 1,
help: 'Trigger, i.e. on OR off, the access point'
})
.help('Configure the Tessel as an access point')
.callback(function(opts) {
callControllerWith('createAccessPoint', opts);
if (opts.trigger) {
if (opts.trigger === 'on') {
callControllerWith('enableAccessPoint', opts);
} else {
callControllerWith('disableAccessPoint', opts);
}
} else {
callControllerWith('createAccessPoint', opts);
}
});


Expand Down
14 changes: 14 additions & 0 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,20 @@ controller.createAccessPoint = function(opts) {
});
};

controller.enableAccessPoint = function(opts) {
opts.authorized = true;
return controller.standardTesselCommand(opts, function(tessel) {
return tessel.enableAccessPoint();
});
};

controller.disableAccessPoint = function(opts) {
opts.authorized = true;
return controller.standardTesselCommand(opts, function(tessel) {
return tessel.disableAccessPoint();
});
};

controller.printAvailableUpdates = function() {
return updates.requestBuildList().then(function(builds) {
logs.info('Latest builds:');
Expand Down
22 changes: 22 additions & 0 deletions lib/tessel/access-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ function commitAndClose(self, resolve) {
});
}

Tessel.prototype.enableAccessPoint = function () {
var self = this;

return new Promise(function(resolve, reject) {
return self.connection.exec(commands.turnAccessPointOn())
.then(function() {
return commitAndClose(self, resolve);
});
});
}

Tessel.prototype.disableAccessPoint = function () {
var self = this;

return new Promise(function(resolve, reject) {
return self.connection.exec(commands.turnAccessPointOff())
.then(function() {
return commitAndClose(self, resolve);
});
});
}

Tessel.prototype.createAccessPoint = function(opts) {
var self = this;
var ssid = opts.ssid;
Expand Down
7 changes: 5 additions & 2 deletions lib/tessel/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ module.exports.setAccessPointPassword = function(password) {
module.exports.setAccessPointSecurity = function(security) {
return ['uci', 'set', 'wireless.@wifi-iface[1].encryption=' + security];
};
module.exports.turnAccessPointOn = function(enabled) {
return ['uci', 'set', 'wireless.@wifi-iface[1].disabled=' + Number(enabled ? 0 : 1).toString()];
module.exports.turnAccessPointOn = function() {
return ['uci', 'set', 'wireless.@wifi-iface[1].disabled=0'];
};
module.exports.turnAccessPointOff = function() {
return ['uci', 'set', 'wireless.@wifi-iface[1].disabled=1'];
};
module.exports.reconnectDnsmasq = function() {
return ['/etc/init.d/dnsmasq', 'restart'];
Expand Down

0 comments on commit af1d41d

Please sign in to comment.