diff --git a/bin/tessel-2.js b/bin/tessel-2.js index ec373f4f..f1d69e56 100755 --- a/bin/tessel-2.js +++ b/bin/tessel-2.js @@ -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); + } }); diff --git a/lib/controller.js b/lib/controller.js index 018f340f..13484463 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -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:'); diff --git a/lib/tessel/access-point.js b/lib/tessel/access-point.js index 72bee859..a4ffbc9b 100644 --- a/lib/tessel/access-point.js +++ b/lib/tessel/access-point.js @@ -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; diff --git a/lib/tessel/commands.js b/lib/tessel/commands.js index 09f4191e..662a098a 100644 --- a/lib/tessel/commands.js +++ b/lib/tessel/commands.js @@ -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'];