Automated smartphone network connection with easytether
I have a first generation Motorola Droid. I bought the easytether app from the Android market. Tested it, liked it, and decided to try using easytether for my general internet connection. It's good for casual use (web, email, and even Hulu), but it's not so great for downloading huge files; for example, your connection is lost on an incoming call.
I know there are other alternatives out there, but other than pdanet, they require rooting your phone. I don't want to root my phone just yet, and I'm not going to change my mind anytime soon. :)
I managed to configure my system (Ubuntu-server 10.04) to (1) establish the network connection automatically when the phone is connected; (2) share the connection with other computers on my LAN; and (3) wrote a script to reconnect whenever a disconnect occurs.
Even though I could only test the scripts against my Droid, this approach ought to work for any Android phone with easytether installed.
To start, let me give the scripts I wrote. Perhaps someone smarter than me could merge them, but this works:
===== Scripts =====
You may want to replace all of this with a simple "sudo dhclient easytether0" depending on your setup.
===== Udev =====
Ok, so, the scripts by themselves are the bulk of the work. You can kick off easyconnect manually and be perfectly happy. If you want complete automation, you need udev. A quick-and-dirty guide to adding a udev rule can be found on this page.
Just follow their general process. I ended up with the following as my udev rule:
Note: (1) the serial number above is bogus because I'm paranoid about publishing such unique identifying info on the web; (2) You do not need the SYMLINK, but it could be useful if you mount your phone as storage regularly; (3) change the RUN attribute to point to easyconnect (or your equivalent)
Restart udev. At this point, your setup should automatically establish an internet connection whenever you plug your phone into a USB port for that machine.
===== Connection Sharing =====
If you want to set up connection sharing to allow all the computers on your home network share the phone's internet connection, then take a look at this page.
Anyway, using an almost-fresh Ubuntu server install, I did not have to mess with steps 3-6 on the linked instructions.
Now, to do this, two things need to be configured:
1. The computer that's sharing needs to have a static IP address on your network.
2. You need to know a bit about DNS.
I won't go into either of those guys very much. The static IP address is a fairly simple process and there should be tons of instruction on how to do it with a quick Google search.
Your knowledge of DNS will determine what your easydhcp script needs to do. Earlier, I pointed out that your easydhcp script might simply be changed to "sudo dhclient easytether0." If you do not run a DNS server, then that's probably what you should do. However, I DO run a DNS server on the machine that shares the internet connection. Running dhclient on that machine would interfere with the way I have my network set up. So that is why my easydhcp script is written the way it is.
Nice work. I also have a Droid and I may try your script later.
this is good stuff! I have no doubt that someone(s) will find this very handy. This tethering issue has been coming up more + more over the last year or two, but finding (good) information and knowing where to point an asker for more, are difficult at best.
Perhaps after some time for feedback, code improvements, or whatever, your posting could be made into an article for the LQ Wiki or Linux Tutorials.
Thanks for sharing it!
Thank you both!
I should point out two things about the easytether program:
1. There is a free version available in the Android market. The free version is fully functional except for https:// websites. You have to pay for the full app ($10) to access secure websites. So, anyone can give this solution a test-run if they like--without spending a dime.
2. The easytether program comes in two parts: one part that installs on the phone itself and a second part that runs on the host machine. The developers of easytether have a .deb package available (both 32 and 64-bit). This solution does not replace either part. You must install both parts. This solution simply automates the entry of the appropriate commands as soon as the device is connected.
You can download the packages here: Mobile Stream Easytether drivers
More info: these are not source packages--they are binaries. Also, if you inspect the easytether program, it is SUID root. If you leave it as SUID root, you don't need to worry about permissions quite so much. Personally, I cleared the SUID bit and sudo'd whenever I needed to run it.
I am just beginning to use Linux, and I have a quick question. I have the 2 scripts made, but they aren't in the correct directory. I can't make new folders/files or move files to /usr/local/bin/ because the options are dimmed. Can someone please explain how to put the scripts there? (In newbie terms please)
1. What distribution are you using?
2. Is this your personal computer, or does someone else own/manage it (e.g. a corporate/educational IT department)?
EDIT: Nevermind about the distribution. I noticed your post has an Ubuntu logo. So I'll assume that's what you're using. Second question still stands...
Its my personal laptop running ubuntu 10.10
Also I'm using a Motorola Droid 2, but that shouldn't matter for the scripts.
Ok, I'll walk you through it. (Please don't take offense if this is overly simplistic--I'm writing it from the perspective of a random Internet user coming across this post with 0 Linux knowledge).
We're going to use the command line rather than a GUI (because that's how I'm familiar with moving files into these types of places).
1. Start with the top menu:
Applications -> Accessories -> Terminal
You should have a new window with a command prompt. When I give you commands to enter, I'll prefix them with a '$' just to help indicate the end of the command prompt. Don't type the '$' on your end.
2. Now, before we get into the commands, find the script files with the normal window-based file manager. When you find them, there will be a path to the directory in the Location field of the file manager window. For instance, it might be: /home/santaclawz/Documents
3. In the terminal window, change directory to where the scripts are (note: you will need to update the directory based on what you saw in the Location field from step #2--and again, don't type the '$'):
5. Copy the files using the sudo command. I assume you used the same filenames I did (easyconnect and easydhcp). If you did not use those names, you'll need to modify the command to match what you used:
6. Now we make sure that the scripts are executable, by giving everyone permission to read and execute them:
7. Ok, the scripts are installed. If you need to create the directory for the log file, type this:
And again, you'll need to install the easytether drivers I linked to earlier. And you may want easydhcp to run "sudo dhclient easytether0" instead of what I have.
If you (or anybody else) gets it working, please let me know. The more people that get some use out of this, the more likely I'll spend more time refining it. I'm already kicking around the idea of a python script or a C program. But unless there's lots of interest, they'll remain when-I-have-time projects.
It seems to be working now, thanks :)
I'm working on connection sharing now, will do the udev tomorrow.
I'm trying to share the connection to my ps3 and I've almost got it.
Using EasyTether I've got these settings so far, but I've been unsuccessful
|All times are GMT -5. The time now is 06:25 AM.|