Thursday, 23 May 2013

Enterprise Week at Henley College Coventry Playing with the Raspberry Pi and Asterisk

Just want to say a massive thank you to Henley College Coventry for inviting me to their Enterprise Week. It gave me an opportunity to demonstrate the single SSR switching circuitry along with the ability for Asterisk to control lighting remotely using an iPad.

The students were great, asked lots of questions. These inquisitive minds is what makes the UK so great at bringing innovation to the masses. I turned a new leaf yesterday. Standing in front of students, helping young minds develop and understand the world of computing, I realised a sense of job satisfaction teachers must get every day. 


The rest of this post is dedicated to these students who attended the class and those who missed out but really wanted to be there.....

Guys and Gals, The star of the show is YOU because YOU are the Future of UK TECH.
I have two messages for you, the first is, as Gary says:



I don't want to dwell on there being only one girl in the room so... I wont...But I will say this...Girls, YOU NEED TO get involved, the UK silicon Valley needs ya, end of! 

Gary Vaynerchuk is a massive inspiration to me and many many hackers, entrepreneurs, inventors and visionaries, so if you do nothing today, please please check him out on YouTube, my favorite vid here:

My second message to you is plane and simple, Get out there and hack, there are million, and I mean millions of problems to solve. Start with solving the simple ones you see and hear around you. A lot of people will say I don't know where to start so from here on, am going to dedicate this blog to helping you all get started. Ask me anything, you will get a reply. Email me directly at mohammed at coventryprinting dot com. You have my address now so you have no excuse.

To get you started, I suggested Python as a great language to learn however, if you have a Raspberry PI and just want to kick off with basic programming skills I would start playing with Scratch. Here is a cool set of Labs to get you going...

If you want to get in to the kind of stuff we looked at in the presentation yesterday, have a look at the links in the following text:

The place to get the latest news in hacking, it's the only place to be every day:

The Open Source Telephony system created by Mark Spencer at Digium called Asterisk:

Turning the Raspberry Pi Into an FM Transmitter:

One of the students asked me to explain how to connect LED's. She planned to use this for mood lighting, I would love to see this project develop, blog it out, the world can't wait to see what YOU can do with a PI.

All work and no play is not fun so here are the labs above, ready to play.....Games

Hope you enjoyed the post, leave me your comments...have fun and happy hacking!


Other cool links:
One of my Top Inspirations, Soichiro Honda, who's that you ask?

Sunday, 29 July 2012

Home Automation For Under £30 - Part 2

PART 2 of the Home automation project. Again, using my limited knowledge, I have sellotaped together a Raspberry PI with the using of the GPIO pins to automate the process of switching home lighting (or LED in this case to emulate home lighting).

The Idea here is to emulate the upstairs and downstairs landing lighting which works in a process where either one can be switched.

 Additionally, we will use the Asterisk PBX ( and a Softphone client ( on the Android to control the relay circuit. All instructions will be available on the here soon....

Saturday, 23 June 2012

Friday, 8 June 2012

Carputer or CarPC using a Raspberry PI, RaspbMC beta - XMBC

Friday, 1 June 2012

Setup And Run Asterisk and FreeBPX on A Raspberry PI

Finally recieved the Raspberry PI on Friday (25th May 2012) after a two and half year wait! My plan, which I had all that time to think about, discuss with others and have ready is still not concrete but initially, I have order 3 devices to play with.

As a Asterisk Engineer, one of the first things I wanted to tackle was to install the latest Asterisk and FreePBX on it. I build Asterisk based PBX systems for a living, so this shouldn't be that difficult. I responded on to say I was going to attempt this and report back but so far the Admin has not got back to me on how I can add there so I have written this up here.

This guide is for complete newbies in getting the Raspberry PI to get set-up and run as a IP PBX using Asterisk and FreePBX

I intended to install Asterisk and FreePBX 2.9 (this is a matter of choice as I am accustomed to the layout before 2.10). I purchased a 8GB SD card instead of 2GB, which is sufficient for just Asterisk 1.8 but not enough for FreePBX. Here's the install process....

Install Squeeze - Get The PI Ready
Anyone with a Raspberry PI in their hands should first go though the following process and set up Debian Squeeze. For my setup, I had an 8GB SD Card. I downloaded Debian Squeeze for the PI from here and the Win32DiskImager from here, Stuck my SD card in to my windows laptop and fired up Win32 Disk Imager. Next, Unzipped the debian file and browsed to it in Win32 Disk Imager, select the correct drive letter in the drop down and let the imaging start. This is by far the quickest and dirtiest way to get Squeeze on to the SD.

After completion, I launched a Live CD of GParted, which is an amazing tool to partition disks. I increased the swap partition to 300Mb and moved it to the end of the drive. I then rezised the rootfs partition to used all the unallocated space on the drive.

Alternatively, you can follow the information on this great guide to go through and set up the drive properly and learn how to do the GParted stuff I mentioned above. 

Internet Access on the Raspberry PI

If you connect the PI to your local network which has a ADSL/CABLE router or mode, then it should have DHCP on. DHCP will provide it an IP address and this will be displayed on-screen when the PI boots up before the log in screen. If it doesnt, you need to get an IP and add this in manually. To do this, log in to the PI using the default username: pi and password: Raspberry and type the following command:

sudo vi /etc/network/interfaces

Using VI : Edit the file using by pressing 'a' to insert text. Once editied, press escape to come out of editing mode.

The IP parameters should be as follows with your specific IP address information:

iface eth0 inet static

NOTE: Dont forget to comment/remove line stating:  

iface eth0 inet dhcp

Additionally you will need to set up DNS in order to get out on the internet. This setting should be done in the resolve.conf file as follows:

sudo vim /etc/resolv.conf

This should say something like:


to test network connectivity, at the command line, type in

ping <your favourite serach>

Press CTRL+C to stop pinging.

Update Asterisk Install Pre-requisites

To start with, update the system and install the required componants by copying the command below:

sudo apt-get update

sudo apt-get -y install make gcc g++ libxml2 libxml2-dev ssh libncurses5 libncursesw5 libncurses5-dev libncursesw5-dev linux-libc-dev sqlite libnewt-dev libusb-dev zlib1g-dev libmysqlclient15-dev libsqlite0 libsqlite0-dev bison openssl libssl-dev libeditline0 libeditline-dev libedit-dev mc sox libedit2 libedit-dev curl libcurl4-gnutls-dev apache2 libapache2-mod-php5 php-pear openssh-server build-essential openssh-client zlib1g zlib1g-dev libtiff4 libtiff4-dev libnet-telnet-perl mime-construct libipc-signal-perl libmime-types-perl libproc-waitstat-perl mpg123 libiksemel-dev php5 php5-cli mysql-server php5-mysql php-db libapache2-mod-php5 php5-gd php5-curl mysql-client vim

Dowload and Extract Asterisk

To Download and Extract asterisk, enter the commands as below:

cd /usr/src 
sudo wget 
sudo tar xvfz asterisk-1.8-current.tar.gz 
cd asterisk-1.8*

Set Up Correct Compilation For ARM Platform
Using your favorite editor, make the change below. I prefer VIM, an enhanced version of the popular VI command line editor:

sudo vim

Search for the word "proc=" in the file and change this to read "proc=arm". For those new to VIM, move to the end of this line using the arrow keys and press 'a', then remove all the chractors before the = sign using back space and type in 'arm'. Finally press escape to come out of editing mode. Then press SHIFT+Z+Z to save and exit the file.

Compile and Install Asterisk
Using the following commands:

sudo ./configure
sudo make
sudo make install
sudo make samples
sudo make config

Finally, restart the PI by typing the fillowing command:

sudo init 6

Congratulations - Asterisk installed is now installed

To test the install, log in to the PI and type the following command:

sudo asterisk -r

If this all works, great...lets move on to installing FreePBX.

Create And Setup Asterisk Users And Groups Permissions

sudo useradd -c "Asterisk PBX" -d /var/lib/asterisk asterisksudo chown -R asterisk:asterisk /var/run/asterisksudo chown -R asterisk:asterisk /var/log/asterisksudo chown -R asterisk:asterisk /var/lib/php/session/

Install Pear and DB
FreePBX uses the php pear repository and specifically requires the database repositor. Enter the commands below to install them:

sudo apt-get install php-pear
sudo pear install db

Download And Extract FreePBX

To Download and Extract FreePBX, enter the commands as below:

cd /usr/src/
sudo wget
tar zxvf freepbx*

Start The MySQL Server And Import In The FreePBX Data
Lets start the database server and import in the tables FreePBX will require using th following commands:

sudo service mysql start
cd /usr/src/freepbx*

sudo mysqladmin create asterisk
sudo mysqladmin create asteriskcdrdb
sudo mysql asterisk < SQL/newinstall.sql
sudo mysql asteriskcdrdb < SQL/cdr_mysql_table.sql
sudo mysql

Lets add the mysql user and give it the correct permissions under the MySQL prompt:

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY '******';
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY '******';

flush privileges;

NOTE where I have put '******', replace with your own password. Please keep a log of this as it will be required later. The password should secure (aplhanumeric with symbols) and in single speech marks as seen above

Now lets secure MySQL with a root password of your choice (See note above).

sudo mysqladmin -u root password '******'

Restart Asterisk With Correct Permissions

cd /use/src/freepbx*
sudo service asterisk stop
sudo ./start_asterisk start

Set The Correct Timezone for PHP
Open the PHP Configuration file:

sudo vim /etc/php5/apache2/php.ini

Under Module Settings, change the timezone accordingly:

; Module Settings ;

; Defines the default timezone used by the date functions

Uncomment date.timezone and set to the correct setting according to the link above. In my case, this was as follows:

date.timezone = Europe/London

To do this, move over the first charactor in the line, press 'a' the backspace to uncomment the line. Then move to the end of the line and type in your timezone after the '='. Press escape to come out of editing mode and save the file using the SHIFT+Z+Z combination.

Setup Apache For FreePBX and Asterisk
Apache user and group will need to be set to asterisk. To do this, run the following command to open the Apache configuration file:

sudo vim /etc/apache2/apache.conf

Find the line that states:

User www-data
Group www-data

Change these to read:

User asterisk
Group asterisk

For those new to VIM, move to the end of this line using the arrow keys and press 'a', then remove all the charactors before the user or group using back space and type in 'asterisk'. Finally press escape to come out of editing mode. Then press SHIFT+Z+Z to save and exit the file.

Additionally, change the default sites settings by:

sudo vim /etc/apache2/sites-available/default

Under tags "<Directory />" and "<Directory /var/www/>" change the following settings:

Options FollowSymLinks
AllowOverride All

For those new to VIM, follow the origional instuction on editing above using the 'a' to go in to editing mode and escape key to come out of editing mode. Remember to save the file using SHIF+Z+Z.

Finally restart apache using the following command:

sudo service apache2 restart

Install FreePBX
To install FreePBX, you will need to specify the username and password to the database we setup earlier, start by typing in the following command:

sudo ./install_amp --username=asteriskuser --password=******

For each of the prompts, just hit enter except when prompted for

Enter the path to use for your AMP web root:

in this case type the following:


Then hit enter. You should see something like this :

Checking for PEAR DB..OK
Checking for PEAR Console::Getopt..OK
Checking user..OK
Checking if Asterisk is running..running with PID: 2591..OK
Checking for /etc/amportal.conf../etc/amportal.conf does not exist, copying default
Creating new /etc/amportal.conf

Enter the hostname of the 'asterisk' database:

Enter a USERNAME to connect to the Asterisk Manager interface:
Enter a PASSWORD to connect to the Asterisk Manager interface:
Enter the path to use for your AMP web root:
 [/var/www/html] /var/www

Enter the IP ADDRESS or hostname used to access the AMP web-admin:
Enter a PASSWORD to perform call transfers with the Flash Operator Panel:
Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]?
Enter directory in which to store AMP executable scripts:
Created /var/lib/asterisk/bin
Enter directory in which to store super-user scripts:

One this is complete, lets set the file permissions for FreePBX to be accessable to apache users:

sudo chmod 777 /var/www/* -R

Finally Restart all services
Although in a lot of the cases, service restart is not required, I have had issues in previous versions of FreePBX, therefore as a final step, restart all the service to ensure they start with the correct permissions:

sudo amportal stop
sudo service apache2 stop
sudo service mysql stop

sudo service apache2 start
sudo service mysql start
sudo amportal start

Congratulations - Free PBX is now installed.

 To test the install, open your favourite browser on another PC and browse to the address of your PI