Monday, 21 October 2013

3G Dongle, the Pi and Staying Alive

Task 3: Establish a 3G Connection on Boot and Stay Connected

Setting up a 3G connection and keeping it live hasn't been an easy task and remains largely unsolved. The principle hurdles are listed below. I've drawn quite a bit of inspiration from forums and blogs, one particularly good source is the Big Cow Pi.

Ensure you have a command line text editor installed before you go any further. I can't remeber if its installed as default in Wheezy, but I use nano:

sudo apt-get install nano

You can read most text files usign the following commands (sudo used only to access files requiring root user priviledges, i.e. most system files.

sudo nano path/of/file 
  • Ensuring the dongle is compatible with the Pi (website here: )
The Huawei 353 seems fine, but there may be a number of issues with other dongles. Rule of thumb should be to keep to  tried and tested list. I picked a used 353 up from ebay for £20, unlocked. This dongle has a connection for an external aerial, hence my choice. You can unlock yourself it you want to save a few quid but the cost difference between used and locked vs used and unlocked was not worth the risk.
  • Power 
The power draw from a 3G dongle can't be sustained, reliably atleast, from the Pi itself. Once more I want to add one or more Wifi dongles. So I bought a 2.1mA 5.5v adaptor with two USB power outlets, allowing a powered USB hub and  Pi to be connected to a single plug, neater. If  your having problems getting the dongle to register as a device at all than this may be your problem.

  • Ensuring the device is recognised and operates as modem rather than a usb storage device
Most dongles, including the 353 have a port for a mini SD card. Mine didn't have a card in it from the seler but the first time I plugged it in it was recognised as a storage device. You can tell what mode its currently in by looking at the output from:

lsusb

Example output:

Bus 001 Device 007: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard

There is a program specifcally designed to manage this situation called 'usb-modeswitch'. Some say its already included in Wheezy but didn't seem to be in my case. There is quite alot information out there on configuring usb-modeswitch but it seemed, on face value atleast, to work out of the box for me. I may however need to revisit it later as I understand more of how it works as there are some niggling issues I haven't resolved yet. To install and setup with minimal configuration here's what you do:

sudo apt-get install usb-modeswitch

Once installed the device and vendor codes as well as the description of the device should be roughly correct. If not you need to find the correct profile for your device and edit the /etc/usb-modeswitch.config file, pasting in an entry such as this:

sudo nano /etc/usb-modeswitch.config

DefaultVendor= 0x12d1
DefaultProduct=0x1f01
TargetVendor= 0x12d1
TargetProduct= 0x14db
CheckSuccess=20
MessageContent="55534243123456780000000000000a11062000000000000100000000000000"


(profile for the Huawei 353 from the usb-modeswitch forum)
  • Establishing a connection from the command line

There are various means of doing this. Some work better than others, but the software of choice for alot of people appears to be 'sakis3G'.  Unfortunately the website is currently down and from what I can gather has been for sometime. I downloaded it from alterative link and setup for the giffgaff network as follows.

In order to keep the connection live you also need to use utmskeeper. This is essentially a script that keeps (I think) checking and refreshing the connection. 

There are a few prerequisites packages you also need to install. All commands assuming your in the pi home directory (/home/pi):
  
sudo apt-get install ppp wget 

sudo mkdir /usr/local/lib/3GSoftware/

cd /usr/local/lib/3GSoftware/

sudo wget "http://downloads.sourceforge.net/project/vim-n4n0/sakis3g.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fvim-n4n0%2Ffiles%2F&ts=1363537696&use_mirror=tene~t" -O sakis3g.tar.gz

sudo tar -zxvf sakis36.tar.gz

sudo chmod +x sakis3g

sudo ./sakis3g --interactive --no-probe

sudo wget "http://zool33.uni-graz.at/petz/umtskeeper/src/umtskeeper.tar.gz"

sudo tar -zxvf umtskeeper.tar.gz

sudo chmod +x utmskeeper

sudo ./umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='CUSTOM_TTY' CUSTOM_TTY='ttyUSB3' APN='CUSTOM_APN' CUSTOM_APN='giffgaff.com' APN_USER='giffgaff' APN_PASS='password'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 8 --nat 'no'

 


Sunday, 20 October 2013

Pi Setup and Optimise

Task 2: Install Wheezy and Optimise

Now I'm not sure which distro (distribution of Linux) would be best suited for this task but I decided to go with what I knew, Raspian Wheezy. This is a permeation of the Debian OS compliled for the Pi and carries alot of similarities with Ubuntu

I bought a Sandisk Extreme II a while ago from PC World (not ebay, too many fakes out there). Has a fast read/write rate so hoepfully will see a little extra performance.

NOTE: My regular laptop is installed with Linux Mint, another Debian system. So all instructions outside of based on linux.

Install Wheezy from Linux Terminal (taken from here: Link)


cd /home/pi

mkdir RaspbianImage

cd RaspianImage 

wget "http://downloads.raspberrypi.org/raspbian_latest -O raspbian.zip"

unzip raspbian.zip

ls

Note the filename of the .img file.

df

Identify which device the SD is mounted on (e.g. /media/mysdcard) and its filesystem (e.g. /dev/sdc1)


umount /media/mysdcard

sudo mkdosfs -F 32 -v /dev/sdc1

sudo dd bs=1M if="/home/linux/2013-02-09-wheezy-raspbian.img" of=/dev/sdc1
 
Insert your SD card into your Pi and powerup. Assuming your pi is plugged into to ethernet use SSH to access it via a Terminal.

ssh -l pi 192.168.1.xx
 

The default password, required to login, for the raspbian root user (equivalent to the adminstrator in windows for those that are completely new) is "raspberry". 

As I'm not planning to connect to any form of display I changed the memory usage to free up what is available for other operations. I also changed the admin password and made sure that raspbian was making use of all available space on the sdcard. There is a configuration program built into raspbian to do all this (and more). You access as follows:


sudo raspi-config

The one last thing I did was give the pi a static ip address for the ethernet connection in my BT Home Hub. This was not 100% necessary but I did it anyway to save me trouble down the line.

Hopefully all is well and you can move onto the next step, getting 3G going and stay connected to the network from boot.

Saturday, 19 October 2013

3G Antenna

Task 1: 3G Atenna & 3G Dongle


I got a giffgaff pay as you go sim card a while back. I've setup it up on a rolling £12 goodybag giving me Unlimited' internet usage, something I barely use. So I got thinking. How could I use this to my benefit. If I could combine the bandwidth and usage of of my BT landline and 3G connection for a faster connection that may  worthwhile.

A little digging around and I came to the conclusion that bridging a number of connections may be possible whilst sharing that connection using my Pi.

One snag though, the reception at my house is rubbish, except if you wonder out into the garden and point it towards the nearest O2 (which I assume GiffGaff rents).

So I needed a bigger antenna, a means of getting into my house and a port to connect it too.

I bought one of these as the result:

http://www.ebay.co.uk/itm/271135661223?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649

and one of these to go with it:

http://www.ebay.co.uk/itm/290967760274?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649

This of course means the SIM card and therefore phone, my personal phone, are no longer usable (unless I keep switching the SIM). This isn't necessarily a problem for calls as can be automatically forwarded to another number through most phone software at the base station, which I did, sending everything to my business phone (which had pretty much placed my personal phone anyway). However for SMS and MMS you would have to had the SIM in a phone with an application for text forwarding installed, acting like a SMS gateway. This is where Gammu comes in to the equation, but I talk over this later.

So I've aligned the anttena on a pole in my back garden to the nearest O2 3G mast (they have a website showing base stations). I calculated an angle of 49degrees north as the correct angle, and luckily our house if about 20-30m above the antenna so no need to mount on roof. I would have prefered to mount on our TV aerial on the roof but someone quoted me £70 to put it up there (I don't have the stuff to do it myself).

Signal is sound, achieving 500 kb/s to 1500 kb/s most days occasionally more. My BT line is about 1500 kb/s so is a good result. Of course those on fibre optic are smug at this point but I live in sticks so no chance for now.

Time to fire up the Pi!






PiPoint with Bonded Internet Connections


Aim



Share the Pi's internet connection making it wireless router with a boosted bandwidth making for a faster internet connection .

Objectives (not necessarily in order)

 

  • Fix an external 3G aerial and feed into house (via existing hole created for TV aerial) for more reliable 3G connection
  • Install Raspbian Wheezy 
  • Optimise the Pi for use over SSH only, maximising memory usage
  • Get an unlocked 3G dongle compatible with the Pi for use on giffgaff network
  • Get 3G dongle to connect and stay connected (stay alive) on boot
  • Create Wireless Access Point
  • Forward internet connection
  • Make sure reliable whilst sharing Ethernet first
  • Setup Gammu and Gammu daemon to forward and recieve any text messages to/from other model device. Message database to be managed via php on localhost (requires setting up pi as webserver on localhost, extends to later tasks)
  • Test to see if conflicts between Gammu and internet connection
  • Bridge Ethernet and 3G connection
  • Bridge Ethernet, 3G and second wireless connection (on separate dongle) if my neighbour agrees to BT Fon
  • Share USB printer using PiPoint
  • Manage internet connection via PHP
  • Project 2: .... TBC

MyHumblePi

Raspberry Pi programming projects


I've been playing around with ubuntu for a few years now.  Its safer, more flexible,  more exposable, has a massive user base for support and for the most part is free! Windows however remains as my working environment, where you just need it to work out of the box. However if your willing to take the time to manoeuvre past dead ends and learn more about how that the little black box works, then linux is the place to be.

The Raspberry Pi is exclusively  designed for linux. It is probably the one of most versatile computers currently available. The possibilities are endless as long as you've the time and a willingness to learn then is hard to match.

I've decided to put this blog together to document step by step procedures for some of the projects I'm attempting with my Pi, mainly so I can remember the steps I've taken, share my experiences and hopefully get some feedback from other more experienced users and professionals.

Best of luck and hope what I've written is of use to someone.

Cheers
Mike