Skip to content

Commit

Permalink
Merge 90428e6 into 73739db
Browse files Browse the repository at this point in the history
  • Loading branch information
bart committed Jan 6, 2019
2 parents 73739db + 90428e6 commit f08373b
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,46 @@ makeCommand('reboot')
})
.help('Reboot your Tessel');

makeCommand('3g')
.callback(options => {
log.level(options.loglevel);

callControllerWith('setup3g', options);
})
.option('apn', {
default: 'internet',
help: 'Access point name of your mobile provider'
})
.option('dialnumber', {
default: '*99#',
help: 'Dialnumber provided by your provider, e.g. *99#'
})
.option('username', {
default: '',
help: 'Username provided by your provider'
})
.option('password', {
default: '',
help: 'Password provided by your provider'
})
.option('config', {
flag,
help: 'Change 3G config with parameters from above'
})
.option('on', {
flag,
help: 'Enable 3G connection'
})
.option('off', {
flag,
help: 'Disable 3G connection'
})
.option('status', {
flag,
help: 'Show 3G connection status information'
})
.help('3G USB dongle setup');

makeCommand('run')
.callback(options => {
log.level(options.loglevel);
Expand Down
11 changes: 11 additions & 0 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,17 @@ controller.reboot = opts => {
});
};

controller.setup3g = opts => {
opts.authorized = true;
return controller.standardTesselCommand(opts, tessel => {
return new Promise((resolve, reject) => {
tessel.setup3g(opts).then(() => {
resolve();
}).catch(error => reject(error));
});
});
};

controller.createNewProject = init.createNewProject;

controller.crashReporter = function(options) {
Expand Down
119 changes: 119 additions & 0 deletions lib/tessel/setup-3g.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
var Tessel = require('./tessel');
var log = require('../log');

Tessel.prototype.setup3g = function(options) {

var apn = options.apn;
var dialnumber = options.dialnumber;
var username = options.username;
var password = options.password;
var config = options.config;
var on = options.on;
var off = options.off;
var status = options.status;

if (config) {
return this.simpleExec(['uci', 'get', 'network.wan']).then(() => {
// If dongle already exists remove it and store new configuration
return this.simpleExec(['uci', 'delete', 'network.wan']).then(() => {
return this.configure3gDongle(apn, dialnumber, username, password);
});
}).catch(() => {
return this.configure3gDongle(apn. dialnumber, username, password);
});
}

if (on) {
return this.enable3gConnection();
}

if (off) {
return this.disable3gConnection();
}

if (status) {
return this.show3gConnectionStatus();
}

};

Tessel.prototype.configure3gDongle = function(apn, dialnumber, username, password) {
return this.add3gDongle()
.then(() => this.set3gDongleName())
.then(() => this.set3gDongleIfname())
.then(() => this.set3gDongleDevice())
.then(() => this.set3gDongleApn(apn))
.then(() => this.set3gDongleService())
.then(() => this.set3gDongleProto())
.then(() => this.set3gDongleDialnumber(dialnumber))
.then(() => this.set3gDongleUsername(username))
.then(() => this.set3gDonglePassword(password))
.then(() => this.storeNew3gDongle())
.then(() => this.enable3gConnection())
.then(() => this.print3gSetupMessage());
};

Tessel.prototype.add3gDongle = function() {
return this.simpleExec(['uci', 'add', 'network', 'interface']);
};

Tessel.prototype.set3gDongleName = function() {
return this.simpleExec(['uci', 'rename', 'network.@interface[-1]=wan']);
};

Tessel.prototype.set3gDongleIfname = function() {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].ifname=ppp0']);
};

Tessel.prototype.set3gDongleDevice = function() {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].device=/dev/ttyUSB0']);
};

Tessel.prototype.set3gDongleApn = function(apn) {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].apn=' + apn]);
};

Tessel.prototype.set3gDongleService = function() {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].service=umts']);
};

Tessel.prototype.set3gDongleProto = function() {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].proto=3g']);
};

Tessel.prototype.set3gDongleDialnumber = function(dialnumber) {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].dialnumber=' + dialnumber]);
};

Tessel.prototype.set3gDongleUsername = function(username) {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].username=' + username]);
};

Tessel.prototype.set3gDonglePassword = function(password) {
return this.simpleExec(['uci', 'set', 'network.@interface[-1].password=' + password]);
};

Tessel.prototype.storeNew3gDongle = function() {
return this.simpleExec(['uci', 'commit']);
};

Tessel.prototype.enable3gConnection = function() {
return this.simpleExec(['ifup', 'wan']);
};

Tessel.prototype.disable3gConnection = function() {
return this.simpleExec(['ifdown', 'wan']);
};

Tessel.prototype.show3gConnectionStatus = function() {
return this.simpleExec(['ifstatus', 'wan']).then(data => {
log.info(data);
}).catch(() => {
log.info('Connection data not available');
});
};

Tessel.prototype.print3gSetupMessage = function() {
log.info('3G USB dongle has been configured successfully.');
log.info('It should connect automatically to the internet.');
};
1 change: 1 addition & 0 deletions lib/tessel/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ require('./version');
require('./wifi');
require('./restore');
require('./reboot');
require('./setup-3g');

0 comments on commit f08373b

Please sign in to comment.