Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented 3G USB dongle setup CLI command #1597

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the use of var in this file to const? Those variables are never reassigned so we can optimize with the use of const.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the wifi and ap commands, I would expect configuration to be the default mode of the 3g command. For example:

t2 3g --apn="" --dialnumber="" --username="" --password=""

I would expect that command alone to configure the Tessel to connect to that 3g network and be enabled.

If none of those configuration options are passed in, i.e. t2 3g, I would expect to see the current configuration and status of 3g mode. Just like if you use t2 wifi, the cli will return the current details of the Tessel's wifi connection (if it is connected).

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a typo here.

Suggested change
return this.configure3gDongle(apn. dialnumber, username, password);
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');