Search This Blog

Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Monday, 17 October 2016

Using a USB Serial cable on Ubuntu (without needing to sudo)

For those who know me, my views on using Windows as a desktop environment are well known. I wouldn't say it was necessarily a bad thing, it works for a great number of people, but for those of us in the world who care about freedom, choice and the greater good, then there are numerous alternatives.

My house is filled with precisely one laptop, and that's a Chromebook. I'm fairly well invested in the Google ecosystem, and it works well for me.  My company however have provided me with two laptops, one for doing my company business (e-mails, documentation, and the like), and one for conducting business on customer sites (networking tasks mainly).

My networking laptop was handed to me with Windows 8.1, as was the company standard at the time, and I subsequently (read very quickly) removed Windows and installed Ubuntu Gnome. I love Ubuntu Gnome, I find it to be a very clean, efficient and fast operating system, and works perfectly for my needs. When there is a need to do anything "Windows-ish", I have a VirtualBox VM running Windows 10.

Now, I'm a networking man, and my terminal emulator of choice has always been PuTTY. One of the annoyances I find with PuTTY is that as a user or administrator on an Ubuntu system, you need to run PuTTY using a sudo command to avoid the application showing the error message "Putty Fatal Error: Unable to open connection to: Unable to open serial port" when PuTTY tries to interact with the USB Serial Port. This can be worked around by launching a terminal window within Ubuntu, and running the following command:

sudo putty

This is all well and good, and will get you round the issue without any problems.  However, for me, this always seemed like an unnecessary obstacle to me getting my work done.

After a little investigation, I found that when I connect my USB Serial port to my laptop, it gets installed on Ubuntu as a device called /dev/ttyUSB0, and this device is a member of a group called "dialout", as shown in the screenshot below:



This theoretically meant that if my user account were a member of the "dialout" group, it would have the relevant permissions to access the port.  I checked my group membership be running the command "groups"



As I suspected, there is no reference to the group "dialout" in my list of groups.  By running the following command, I was able to add the "dialout" group to my list of groups.

sudo usermod -a -G dialout david

You need to log out and then back in to apply the changes.  When you the run the command "groups", you will see that "dialout" in the list of groups.




This too should work for you, if you substitute my username above "david" for your own username on the system.

Just for your information, the above command is broken down to illustrate what is happening:

sudo: run the following with highest privileges
usermod: invoke the user modification program
-a: specifies that usermod should be adding an entry
-G (note the capital G): specifies that what follows is an addition to an existing group
dialout: this is the group to which a user should be added
david: is the user who should be added to the above group

I hope this helps someone
Have a nice day
Dave

Wednesday, 3 June 2015

Xperia Z3 Compact Tethering Problems



I have been using Android now for many years now. Since Genesis, if you will. My first Android handset was the first Android handset; the T-Mobile G1 (A.K.A. the HTC Dream) I still to this day have fond memories of that old chunky device, with it's flip out screen, and little rollerball.

Times change, hardware fails and software is updated, and I find myself today using a Sony Xperia Z3 Compact (D5803) running Android 5.0.2 (Lollipop), this is build number 23.1.A.1.28. This originally shipped with Android 4.4.4 (KitKat), and was upgraded earlier this year. I am also on the Three UK network.

Since the upgrade, I have had troubles with the Tethering functions on the phone. When I enable the Tethering (via WiFi or USB), I received an error message stating "An error occurred during tethering". No further explanation or error, just nothing. The service is enabled, and my laptop can obtain an IP Address via DHCP, however when trying to browse the web, no DNS names are resolved. I tried all manner of things to try to work around this; manually specifying DNS entries, manually specifying IP Addresses, using third party apps from the Google Play Store, but nothing would fix the issues.

ThreeUK have been unable to provide any sensible support, and Sony have confirmed that there is some sort of issue which they would fix in a future update. However, tethering is a very useful function, which I tend to rely on when travelling.

After much frustration, and hours of trawling the Internet, I came upon a couple of posts, which in combination have fixed this issue for me, and I can now tether my phone. In fact, I'm writing this blog post whilst travelling into London on a train.

DISCLAIMER: The steps below fixed my issue, however I am an impatient sod, who doesn't mind getting my hands dirty and risk "bricking" my phone. If you are uncertain of the steps you are taking, and if you are more risk averse, then please do not follow these steps. I am listing them here in the hopes that some other people out there the world wide web will benefit from them. Please do not approach me if your phone does not function after following these steps, I can not be held accountable.

Now, on with the story...

I used an Ubuntu based distribution installed on my laptop to complete these steps, if you are a Windows user, you will need to obtain the Android SDK from the Android Developers site in order to conduct this fix. The steps for obtaining this are well documented and LifeHacker have a great article about this, you'll also need the relevant drivers for your Xperia phone, which you can obtain from the Sony Developers website (links will open in a new browser window).


OK, so for Linux, you firstly need to launch a Terminal window. This can be done from the Applications Menu, or on some distributions, by pressing CTRL+ALT+T.
type the following command into the Terminal window to install the tools:

sudo apt-get update
sudo apt-get install android-tools-adb

Enter your current user account password to authorise the install, you may also need to type Y to accept the installation.

Once the software installation is complete, grab your phone and enable USB Debugging:

This can be found in Settings > Developer Options > tick USB Debugging

If you don't see "Developer Options" in your settings menu, go to Settings > About Phone, find the entry for "Build Number", and the tap on it repeatedly until you see a message stating that you are now a developer. Head back a page to your Settings menu, and you should now have Developer Options available to you.

Plug your phone into your PC/Laptop, and if prompted, accept any pop-up messages on your phones screen relating to debugging connections from your PC/Laptop.

Now head back to the terminal, and type the following command:

adb devices -l

This should show you an android device connected to your PC/Laptop and look something along the lines of:

user@laptop:~$ adb device -l
0123456ab789 device usb:2-1.1 product: Sony model: D5803


Next, type the following to enter the Shell Prompt for ADB:

adb shell

Once in the Shell, we need to alter a setting within Android itself. This is the point of no return. If you're unsteady or nervous, quit the ADB shell now.

Type the following command to make the required change:


settings put global tether_dun_required 0

That should be that. Now reboot your phone by typing the following command into the ADB Shell:

reboot

Your phone will now reboot, and you can now quit the ADB Shell and close the Terminal window.

Once your phone has rebooted (if indeed it has), go to your Settings menu, and enable tethering. You should find that everything is now working as it should be.

If you have any questions or comments, please leave them in the section below, and I'll do my utmost to answer them.

Thanks go to:
conceptxo on Reddit, and also to the good folks at tamingthedroid.com