So more recently I have been playing around with cloud technologies, namely building a cloud based hosting platform to replace an ageing home-based server solution. Don’t get me wrong my little Mac Mini server has been phenomenal, but the more recent releases of Mac OS X Server have left me wanting a bit more control and a bit less hardware.

Enter Digital Ocean (shameless referral plug: https://www.digitalocean.com/?refcode=8dc34df963c1 ) who allow you to build a very quick virtual machine capable of handling mail, HTTP and other web service based systems (that I have now retired and / or moved to the cloud).

One of the more recent projects I have wanted to build is a private branch exchange (PBX (Phone network)) so that I can adopt a singular 1 number per country approach, i.e. have a US based number that people can call and SMS, a UK based number that people can call and SMS, etc. This would save giving people a whole lot of different numbers – when Im in the UK ring a local uk number when I’m in the US ring a local us number..

Following lots of sniffing around for how to install PBX software onto a hosted platform I stumbled across this document: https://www.digitalocean.com/community/articles/how-to-install-freepbx-on-centos-6-4

I’m not going to copy and paste the guide word for word as its fairly self explanatory. If you have any problems following the guide, check out the comments at the bottom of the page as they helped.

From here we need to configure three things; Trunks (Calling in and Out), Extensions (Phones to answer the calls) and Routing (What calls go where based on logic).

First lets get extensions setup, its the quickest way to test your PBX is working correctly.

Navigate to your server and login to the FreePBX login it should be something like: YOURDOMAIN.com/admin/config.php

From here you want ‘Applications’ drop down menu and then ‘Extensions’

We are going to add 2 SIP based devices so select the option for ‘Generic SIP Device’ and then click submit.

As this is a private PBX I don’t foresee needing a lot of numbers, however a good organisational setup is still good idea. – Don’t go charging ahead into making your first extension ‘1’ and your second extension ‘2’.

I use the two hundred block for all my extensions, IE the first extension is 201 and the second extension is 202. As I need to add more extensions to the PBX they will become 203, 204, 205, etc.

The three main values we need to set here, are the user extension, Display Name and secret (password).  If you follow my convention you should setup ‘201’, ‘Mathew’ and ‘mysupersecretpassword’. Once you have setup your first user, do the same again so you have a second user (appending the next extension, username and password).  – Now we can test our PBX. If you have an iPhone – I recommend downloading any of the open VOIP Clients, my fav is ‘LinPhone‘. Its simple, easy to use and you can turn on the debugger if you need to.

If you have more than 1 phone you can download Linphone to that as well (Or another VOIP client) and try to ring each other. Or if you have 1 phone and your computer look at downloading x-lite (X-Lite)

To ring another IP phone on your PBX just punch in the extension number, 202 to ring the second phone from the first and 201 to ring the first phone from the second.

Once you have established that your phones are working we can begin to get calls into the PBX from the outside world.

Inbound Calling

First we need to organise inbound calling from Twilio.

Head over to Twilio.com and sign up for a trial account, you will need an email address and a mobile / cell phone to validate yourself against. Once you signed up you will need to provision a telephone number, you can do this in your account at: https://www.twilio.com/user/account/phone-numbers/available/local

Next we need to configure what we want to happen with that number when someone calls it, as Twilio uses TWiML (an extremely well documented type of XML) we can set Twillio to make a sip call to our PBX and connect the call over. On a hosted platform place a new xml document. Something like: www.yourdomain.com/twilio.xml

Our XML needs to look like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<Response>
<Dial>
<Sip>sip:[email protected]</Sip>
</Dial>
</Response>

We can also use a Twimlet to perform the same thing (except it doesn’t look as nice as the above XML:

http://twimlets.com/echo?Twiml=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3CResponse%3E%3CDial%3E%3CSip%3Esip%3A201%40YourDomain.com%3C%2FSip%3E%3C%2FDial%3E%3C%2FResponse%3E&

As you can see, the XML very easy to read, should anyone now dial our newly provisioned number, Twilio will transfer the call to our 201 extension on the PBX. (Almost – we have a bit more setup to do first!).

Login to your PBX via a root terminal and navigate to /etc/asterisk/ by typing

cd /etc/asterisk/

Here we need to edit the sip.conf by typing:

nano -w sip.conf

Here we are going to add all the known IP addresses of Twilio so that when one of the gateways makes a request to our PBX the PBX will answer the call and route it accordingly.

The SIP document held at: https://www.twilio.com/docs/sip contains the list of IP addresses used by Twilio for connections via SIP. To add them to sip.conf we need to add the following to the document:

[twiliocaller](!)
context = fromtwilio
type = peer
qualify=no
allowguest=yes

[twilioip-1](twiliocaller)
host=107.21.222.153

[twilioip-2](twiliocaller)
host=107.21.211.20

[twilioip-3](twiliocaller)
host=107.21.231.147

[twilioip-4](twiliocaller)
host=54.236.81.101

[twilioip-5](twiliocaller)
host=54.236.96.128

[twilioip-6](twiliocaller)
host=54.236.97.29

[twilioip-7](twiliocaller)
host=54.236.97.135

[twilioip-8](twiliocaller)
host=54.232.85.81

[twilioip-9](twiliocaller)
host=54.232.85.82

[twilioip-10](twiliocaller)
host=54.232.85.84

[twilioip-11](twiliocaller)
host=54.232.85.85

[twilioip-12](twiliocaller)
host=54.228.219.168

[twilioip-13](twiliocaller)
host=54.228.233.229

[twilioip-14](twiliocaller)
host=176.34.236.224

[twilioip-15](twiliocaller)
host=176.34.236.247

[twilioip-16](twiliocaller)
host=46.137.219.1

[twilioip-17](twiliocaller)
host=46.137.219.3

[twilioip-18](twiliocaller)
host=46.137.219.35

[twilioip-19](twiliocaller)
host=46.137.219.135

[twilioip-20](twiliocaller)
host=54.249.244.21

[twilioip-21](twiliocaller)
host=54.249.244.24

[twilioip-22](twiliocaller)
host=54.249.244.27

[twilioip-23](twiliocaller)
host=54.249.244.28

 

Save the file and now either reboot asterisk or the server. As the server takes seconds to reboot I tend to follow the save command with just

Sudo reboot

which reboots the whole thing, as this server is for my own use; I’m less worried about the number of users who I will be kicking off when I do this.

Once your back up and working again, if you navigate to: FreePBX system status, it should tell you that 20+ gateways are online. With your backup phone or laptop logged in as your SIP extension we set the look up (201 in the above case) you should be able to call your number and your VOIP phone should ring! (Take 5 mins to strut around the room looking proud and ring yourself a few times!)

Outbound Calling: 

Outbound calling allows you to make call from your VOIP client via your PBX to the real world using Twilio as the gateway. In short we are going to get Twilio to connect the VOIP client to the rest of the world using the callerID we already provisioned.

There is a lot of reference material regarding SIP on the SIP Twilio Page (https://www.twilio.com/docs/sip/sending-sip-how-it-works)

The basics of it include, we need to make a SIP endpoint on Twilio, then when your SIP route references this endpoint, Twilio will make a URL request back to your server to get TwiML to decide what to do with the call.

Head over to: https://www.twilio.com/user/account/sip/domains and click the button ‘Create SIP Domain’

We need to create a Twilio SIP domain, pick something nice and unique such as mypbxservername  – Twilio will append .sip.twilio.com onto this so you will end up with a complete string that looks like this: mypbxservername.sip.twilio.com

Next we need to give it a friendly name, this is just so you can remember what it’s called.

In voice URL, please fill in:

http://twimlets.com/message?Message%5B0%5D=Congratulations!%20You%20just%20made%20your%20first%20call%20with%20Twilio%20SIP.

This will give us a nice uncomplicated message, indicating our success from going from FreePBX to Twilio.

Next we need to generate a way to protect our SIP endpoint.  As Im using a static IP server I can add this to a white list. Click ‘CreateIP Access Control List’ and a new drop down will appear. Here we want to add the IP address of our server and then give it a friendly name.

Save all the changes and then save the domain to Twilio.

Move over to your FreePBX server and add a trunk in the usual fashion: Connectivity > Trunks. 

Here we need to make a new SIP Trunk; so click ‘Add SIP Trunk’

Call the Trunk something like ‘Twilio’ and then move down to the next trunk name (again, Twilio). In Peer details we need to add the three points:

type=peer
host=mypbxservername.sip.twilio.com
qualify=no

Then click submit changes – Ignore an errors you get.

Then we need to add in outbound route, setting it so that when we dial a number on our extensions, FreePBX knows to route the call to our Twilio Trunk.

So, lets add a outbound route; Connectivity > Outbound Routes.

Here, I have set the route name to be ‘Twilio’, now scroll down to ‘Dial Patterns that will use this Route’. We need to configure the PBX so that when we dial a certain prefix, FreePBX will pick up this prefix, remove the prefix and then hand the call over to Twilio to be dialled and connected.

The window is broken up into three boxes, ‘Prepend’, ‘Prefix’ and ‘Match Pattern’. We do not need to worry about ‘Prepend’ so the next bit we need to add a dial prefix so that the PBX knows we want to use this route. I have chosen the prefix of 71, so if I wanted to dial a phone number of 1 415123 1234 I would dial 7114151231234. Here FreePBX will pick up the 71, remove those digits from the string and then hand the 14151231234 to Twilio for dialling. The last part ‘match pattern’ is used to match we have the right numbers dialled. For example in the US, a long distance number would be 1-415-123-1234 so the match pattern would be 1XXXXXXXXXX as we only want +1 numbers to be routed this way. You could also narrow this down do only a certain area code could be called by doing this: 1901XXXXXXX – where 901 is the area code only accepted.

To dial the UK on this dial pattern you would need to setup: 44XXXXXXXXXX, again if you wanted to setup only landlines you could do: 441XXXXXXXXX and 442XXXXXXXXX which would limit numbers to only 441 and 442 (as in 44 1895 and 44 208).

You should now be able to dial a real number from your PBX extensions and you should hear ‘Congratulations, You just Made your first call with Twilio SIP’. PERFECT! This means that your FreePBX box was able to hand over a call to Twilio, and Twilio was able to execute the message we predefined earlier!

Now we need to modify our Twilio URL so that it points to a file we can use to dial our actual end point. On an internet facing server create a new file called asterisk.PHP

to which we need to add:

<?xml version=”1.0″ encoding=”UTF-8″?>
<Response>
<Dial callerId=”+YOURCALLERID”>
<Number><?php preg_match(‘/:([0-9]+)@/’, $_POST[‘To’], $matches); echo $matches[1]; ?></Number>
</Dial>
</Response>

You need to append YOURCALLERID with a caller ID from your account, either a verified number or one of your Twilio numbers. This will be the caller ID used when your PBX dials out via Twilio.

Now take the internet facing location of this file. I’m going to assume: http://domain.com/asterisk.php  – Just update the URL location that was Twimlets message of congratulations with your URL. This should now setup your PBX so that when it makes a request to Twilio, Twilio looks up the URL and injects the TO number into the TwiML, followed up by dialling that number.

Tada!! That should be it! You should now be able to dial your PSTN number and have it call your PBX extensions and you should now be able to dial out from your PBX to PSTN lines using Twilio!

With the PCB now built and soldered, my attention can turn to the software that powers the BeeSafe and the cloud API that it runs on.

The software is broken down into two parts; software run locally on each BeeSafe and software run in the cloud that manages all inputs, requests, alerts and data.

This post will focus on the software, hosted locally on the Raspberry Pi – the brain of each BeeSafe.

The focus of Raspberry Pi is to help teach people (children) the basics via Python (for more information visit: http://www.raspberrypi.org), so that is the language I have chosen to use on the Pi.

While the BeeSafe PCB has a variety of sensors (Temperature, GPS, Trip Switch and Accelerometer) the main one this post will focus on is temperature. On the board itself I have included a ds18b20 temperature sensor which uses the 1-wire thermal probe. Information on this can be found at: http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/ and http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/hardware

Once we have a powered and working Pi, we need to activate the 1-Wire probes, in the command line of your Pi type in :

sudo modprobe w1-gpio

then

sudo modprobe w1-therm

then

cd /sys/bus/w1/devices/

ls

On the page now you should have something that looks like:

w1_bus_master1 and another that looks like “28-000004bb8e9b“. The “28-000004bb8e9b” will be the serial number of the thermal probe, if you have more than one then, they should all be presented alongside each other.

You can directly interface with the thermal probe by typing in

cd /28-000004bb8e9b

and then

cat w1_slave

This will present you with a 2 line read out of data from the thermal probe, it should look something like:

19 01 4b 46 7f ff 07 10 eb : crc=eb YES

19 01 4b 46 7f ff 07 10 eb t=17562

From the output you can see a value called t=17562 which is the temperature but presented raw format, The actual value here is 17.562C. What we need is some code to read this temperature device and give us a useful temperature value.

The code found on the tutorial page at Cambridge (http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/) is a perfect starting point for building out with. A copy of the code is below:

# Open the file that we viewed earlier so that python can see what is in it. Replace the serial number as before.
tfile = open(“/sys/bus/w1/devices/YOURW1PROBE/w1_slave”)
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split(“\n”)[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(” “)[9]
# The first two characters are “t=”, so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
temperature = temperature / 1000
print temperature

Change to your user directory folder by:

cd ~

and open a new file by typing in:

sudo nano read_temp.py

Copy and paste the above code into the nano editor and be sure to change YOURW1PROBE to the serial number of your probe. If you saved this file as read_temp.py you can run it by typing in:

sudo python ./read_temp.py

it will read the thermal probe for data and print out the temperature in the correct format.. i.e. 17.562C not 17562

Now we can read real world temperature into our software! The next step is to install the libraries to allow us to send this data in an SMS message to our phones!

In your command line update APT using the following commands:

sudo apt-get update

sudo apt-get upgrade

Next we need to install PIP, this is done by:

sudo apt-get install python-pip python-dev build-essential
sudo pip install –upgrade pip
sudo pip install –upgrade virtualenv

and then

sudo pip install twilio

Twilio is a global voice and SMS API provider, they allow you to make & receive voice and SMS (as well as MMS) messages to and from phones to and web services. For this post we are particularly interested in the Sending SMS API which will allow us to send SMS messages from our local device to a cloud service to our mobile phone.

Twilio can be found online at: http://www.twilio.com

If you haven’t already done so, sign up for a trial account. You get $30 of credit to play with the Twilio system. Once you have signed up, you will need to buy a number (these cost $1 per calendar month, but will come out from the trial credit) and verify a phone number that you currently have (such as your mobile).

Once your signed up, in your account page you will need to note down your account SID and auth token. These can be found on the top of:  https://www.twilio.com/user/account

Now we need to start to form a more complex python code, fortunately we can build onto of the code we have written before! To maintain a logical evolution of our files we are going to make a copy of read_temp.py by typing in:

sudo cp ./read_temp.py ./send_sms_temp.py

This will make a copy of our read temp file and save it as send_sms_temp.py

Open up your text editor by typing:

sudo nano send_sms_temp.py

You should see an identical copy of the code we have written before; now we are going to modify this file so that it can assemble an SMS message from our temperature data.

Start by adding:

from twilio.rest import TwilioRestClient

to the top of the page, this will call the Twilio REST API client when the file loads.

Underneath the temperature code, we need to add the following lines:

account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create(to="+12316851234", from_="+15555555555",
body="Hello there! The temperature is: " + srt(temperature) + "c")
Substitute the account SID and auth tokens with the ones you wrote down from your user account page: https://www.twilio.com/user/account, then you will need to adjust the ‘to’ value to be a number you wish to SMS. Twilio uses international number standards, so a number in the United States would be ‘+14155555555’ and one from the UK would be ‘+447971234567’.
You will also have to adjust the ‘from’ variable to be the number you have provisioned when you signed up for your trial account. A word of warning, not all numbers from Twilio support SMS messages, particularly SMS messages across geographic locations.
To check which counties can receive messages from which number, check out: https://www.twilio.com/international – when you have signed up test your number works by sending yourself a message from your account portal  (https://www.twilio.com/user/account/developer-tools/api-explorer#POST/2010-04-01/Accounts/{AccountSid}/SMS/Messages.{format})
The srt(temperature) is us telling python to convert the numerical value of temperature into a string value so that it can be added to our outgoing SMS message. Strings and Strings go together, Numbers and Numbers go together, Strings and Numbers do not.
By now your code should look something like this:

from twilio.rest import TwilioRestClient

# Open the file that we viewed earlier so that python can see what is in it. Replace the serial number as before.
tfile = open(“/sys/bus/w1/devices/YOURW1PROBE/w1_slave”)
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split(“\n”)[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(” “)[9]
# The first two characters are “t=”, so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
temperature = temperature / 1000
print temperature

account_sid = “ACXXXXXXXXXXXXXXXXX” #Replace this with your account SID
auth_token = “YYYYYYYYYYYYYYYYYY” # Replace this with your auth token
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(to=”+12316851234″, from_=”+15555555555″,
body=”Hello there! The temperature is: ” + srt(temperature) + “c”)

This is our complete SMS temperature application!

You should now be able to send yourself a temperature based SMS message by typing in:

sudo python ./send_sms_temp.py

Tada! If all has gone according to plan you should have sent yourself an SMS with the temperature your Raspberry Pi has read from the thermal probe.

How. Cool. Is. That!

Now that you have the basics, the world is your oyster. Imagine being sent a text message when your house is getting too cold. Or a morning message of the temperature outside before you leave the house. Or sending data from an SMS device into a database.. But thats another post..

After many (many!) attempts and learning’s.

Everything from PCB design via software, PCB manufacture via toner transfer and ensuring your board is soldered correctly has had to be designed, re-engineered and put into practice on almost a production line state of mind.

Finally the initial board is ready to rock!

Completed BeeSafe Board, Version 1

Completed BeeSafe Board, Version 1

This board features, 5 LED’s; 4 of which are configurable. 3 Temperature Sensors, input for a switch and an I2C based accelerometer. *NB* The board above only has 1 of the three temperature sensors attached as at time of writing the other two sensors were in the post.

This board connects into a Raspberry Pi via the large 26 Pin header in the top left. Connected to the Pi is a USB GPS and USB 3G Data stick. *NB* the Pi’s on board USB ports aren’t able to provide enough power to support the 3G Data stick so an additional hub or secondary PCB will have to be provided should 3G be needed (Which I suspect it will!).

In total the BeeSafe project has the following sensors and communication gateways:

Circuit Temperature BeeSafe Board
Brood Temperature BeeSafe Board
External Environmental Temperature BeeSafe Board
XYZ Accelerometer BeeSafe Board
5 x Status LED’s BeeSafe Board
Switch Sensor BeeSafe Board
GPS Raspberry Pi
3G Data Modem Raspberry Pi
Ethernet Connection Raspberry Pi

With the hardware now complete (for the moment!); my attention has turned to the software to power BeeSafe. This is comprised of two parts: Software localised on the device and software hosted in the cloud to collect, store and interpret all the data.

A lot of people have asked why I chose to use the Raspberry Pi to power this device, a micro-controller such as Arduino would have been more than capable of reading temperature sensors, XYZ data, parsing GPS data and submitting it all via a comm’s device to the cloud. But the Pi stands out as a standalone computer. It’s capable of hosting its on database, serve pages and data to other computers and networks. An Arduino works in a single hive, but a Pi could work with many.

An Example; quite often bee hives are clustered together and are known as apiaries. If each beehive had a 1-2-1 connection to the internet that would mean each hive would require a 3G stick, its own sim card and data plan. Quickly the costs of keeping an apiary online would rack up.

Using a Raspberry Pi you could create a star network, one device could become a host. Using a USB WiFi stick to create a local WiFi access point (like your WiFi at home, one hub serves many users with an internet connection). This could keep costs and maintenance down as each apiary would only need one connection to the internet.

Additionally, if there is no cell signal, a Raspberry Pi could be used as a localised storage option for all the data collected. While this means you would loose some of the advantages of monitoring your Bee Hive remotely, the data is still invaluable and could be downloaded at a later point.

The next steps for BeeSafe include a start up program that will scan the hardware and configure everything into appropriate sections. For the moment I am doing this manually using a mix of python scrips to test the internet connection, GPS data, LED’s, temperature and XYZ position.

My ultimate goal is to produce a initial start up script that will on boot, self-test the LED’s, check for internet connection, scan for temperature sensors, check for the presence of an Accelerometer and then store all this data within an XML file to be used by the default BeeSafe program.

An example of the XML configuration file is below:

<?xml version=”1.0″?>
<BeeSafe>
<BeeSafeDeviceID></BeeSafeDeviceID> #Unique Serial Number used to identify the BeeSafe
<RedLED><RedLED> #GPIO Pin number for Red LED
<AmberLED></AmberLED> #GPIO Pin number for AmberLED
<GreenLED0></GreenLED0> #GPIO Pin number for First Green LED
<GreenLED1></GreenLED1> #GPIO Pin number for Second GreenLED
<BoardTemp></BoardTemp> #Identifier for Board Temp Sensor
<BroodTemp></BroodTemp> #Identifier for BroodTemp Sensor
<EnvironmentTemp></EnvironmentTemp> #Identifier for External Temp Sensor
<MagSwitch></MagSwitch> #GPIO Pin number for Magnetic Switch
<XYZ></XYZ> #Identifier for I2C Accelerometer
</BeeSafe>


The BeeSafe Device ID is used to track and log the data submitted by a BeeSafe device, my initial thoughts were that I could use the serial number from the Raspberry Pi attached, but this quickly led to issues as should a user wish to swap out the Pi for another one, the serial number would change and the data would be lost. Additionally I did not want to tie a BeeSafe device to a specific email address as should an individual user have more than one BeeSafe active, managing each device this way could prove to be problematic.

So whats the solution?
A BeeSafe’s Device ID will be generated on demand from the cloud, as a new device comes online and communicates with the cloud for the first time, it will be assigned a device ID which will be saved to the XML config file. While this ID will not be dependent on the PI it is connected to, the Pi’s serial number will be submitted so that should the worst occur and the SD card with the config file be lost, if the same Pi attempts to reconnect to the cloud, as a new user, it will be assigned the same device ID.

From a human perspective; one user can be in control of many BeeSafe devices.
Should the worst occur and the user need to be contacted, if more than one device has an alert status (such as a whole apiary) the user would be alerted once rather than receiving multiple alerts for a cluster of hives suffering the same issue. For example, if a cluster of BeeHives have collapsed, a single alert would be sent out stating that X number of hives currently need attention, rather than bombarding the user with an alert for each individual hive.

Manufacturing PCB’s in a small scale is often expensive, time consuming and inconvenient for the hobby engineer. Setting time aside to design a PCB, sending the design off to be manufactured and the getting it back to realise its the wrong size or worse that a pin is in the wrong place is often a costly process.

I have for a number of years been building PCB’s at home using various bits of software and manufacturing techniques. These boards were very simple and usually designed to convert DC to DC power from batteries or other sources into another voltage – usually to power a 3rd party circuit or in a pinch my iPhone.

My tried and traditional method of PCB manufacture has been to design the part using Adobe Illustrator, flip the board and print it onto ‘PCB’ toner transfer paper, iron the transfer onto a copper clad board and then etch the board using PCB etchant.

While this has worked great, it has a number of limitations; the level of detail I can work with on illustrator isn’t quite setup for PCB designing, everything is a manual process, the iron on transfer often didn’t work (well) completely and so I had to use a pen to fill in the gaps – making for a messy PCB.

Attending a MakerFair in Brighton (South Coast of England) in the summer, I got chatting to a number of people who represented ‘Build Brighton’ – http://www.buildbrighton.com

Seeing the quality of the PCB’s they had designed and made using gloss paper and a laminator inspired my to change my process.

Deciding to start from the beginning I have throw away all the old processes that didn’t work and refreshed them with new.

PCB Design software:

I evaluated a number of bits of PCB software, the list including:

  • EaglePCB
  • FreePCB
  • ExpressPCB
  • OsmondPCB (Mac only)

I finally settled on FreePCB, I was looking for something that would allow me to build without needing a schematic first. With the software it was very easy to define a PCB board size / shape and then add parts from a pre-defined library. If the part you needed didnt exist, it was very easy to add the part to your own custom library and then import it to your design.

Its worth noting that FreePCB allows the use of multiple layers per board – this is something new to me and I am keen to find a project that will allow me to build a circuit board with both top and bottom tracks & components.

Once I had a basic grasp of FreePCB, I began the redesign of my latest project dubbed ‘BeeSafe’; you can read more on that here http://www.mathewjenkinson.co.uk/beesafe-pcb-initial-thoughts-and-feedback/

Using predefined parts, I was able to define the board size (adjusted to the same size as the Raspberry Pi) move the GPIO cable to a more suitable location, place LED’s and switches and locate the 3xAxis accelerometer. The process itself was straight forward and easy to follow, I was able to adjust the track sizes and route all the connections with ease.

As the board itself was now positioned the right way around, I did not have to flip the image. Exporting to a super high resolution tiff file means that the image coming out from the printer was super crisp. The paper used in the printer is super high quality gloss paper, it has a plastic feel to the coated sheet and the toner doesn’t bleed or blur.

PCB Image printed on to Gloss paper.

To transfer the image to the PCB board is a two step process. One part cleaning and one part heat. Its important to ensure that the copper clad board is 100% clean and free from oils and finger prints as this will reduce the contact the toner has with the board and ultimately effect the end result.

To clean the board, I start with dish soap and a coarse sponge. Scrubbing the board to remove grime, oils and finger prints gets the top layer off and a final buff is done using steel wool, which brings the board up in a nice shine – removing the copper oxide layer.

From here I need to apply heat. Using a laminator and a laminator pouch I run the board through the laminator flipping and turning the board to ensure constant heat distribution along the surfaces. The end goal being that the toner melts off the gloss paper and adheres to the surface of the (now clean) PCB. I have found that that using a laminator pouch acts to prevent the paper + PCB from slipping and keeps the overall temperature stable for longer.

*NB* After a weekend of making PCB’s I can confirm there is a SIGNIFICANT difference between toner transfer with and without a lamination pouch. With the pouch returns a near 100% transfer of toner and pattern while without  can be incredibly hit and miss.

Track transfer via laminator

Track transfer via laminator

Once the board has cooled and can be handled, I cut it from the plastic surround and then submerge it in water to help dissolve the paper. This doesn’t usually take long as the paper is thin and soon falls off the board.

The next step is etching. This is a chemical milling process where the board is submersed in a liquid solution that will dissolve away the copper, any part covered by the toner will be protected and after 20 mins or so (depending on the strength of solution, temp etc) the board will be finished and can be removed from the solution. NB – do not tip the waste down the sink / toilet as it is still quite toxic and may corrode your pipes!

PCB after etching - before drilling

PCB after etching – before drilling

While the toner is still attached to the board, I drill the holes. I have found that the drill travels less and tends to protect the track below.

Finally you need to remove the toner from the board, this can be done in a number of ways. Nail polish works well, as does a quick scrub under a hot tap with a brillo pad.

PCB Being soldered

PCB Being soldered

The final step is to solder your components and test your board!

Happy Making!

For a number of years I have been manufacturing PCB’s at home.

Nothing complex, small voltage converters  or easy to solder projects to either teach myself how to use LED’s or sensors on technology such as Arduino.

 

Homemade Power Converter PCB

Homemade Power Converter PCB

In the past I have always started my design on graph paper, marking out where the physical components need to go and then fitting tracks to them. Which at a basic level works, and works well. You know if you have enough space, where the tracks will go and what overlaps / jumps you need where.

From graphing paper the design is transferred to a digital form and is mapped out using a graphical editor – I use Adobe Illustrator. I know its not designed for PCB layout’s but when you need something simple and quick its fits the bill perfectly!

A single sided board awaiting PCB transfer. The blue sheet is the design on 'Press n Peel' transfer sheet.

A single sided board awaiting PCB transfer. The blue sheet is the design on ‘Press n Peel’ transfer sheet.

Once I have a digital copy of the layout, I invert the image and print onto ‘Press n Peel’ toner transfer paper. Traditionally from here I have used an iron (no steam setting) to melt the toner onto the copper-board, however after speaking with plenty of people at a recent MakerFair, I purchased a laminator and haven’t looked back!

Track transfer via laminator

Track transfer via laminator

Embedding the board and template in a laminator sheet seemed to work very well to retain the heat and ensured even temperature distribution across the panel.

Single PCB and a whole sheet ready to be etched.

Single PCB and a whole sheet ready to be etched.

As you can see from above the process works exceptionally well when you need to scale up from one (single) board to a multiple set.

PCB board ready for drilling

PCB board ready for drilling

Things to note.. PCB Etchant is dangerous stuff!! Its sole purpose is to dissolve metal! There fore when your done do not tip the waste down the sink..

I’ve found that being able to produce a quick and simple circuit for a project / fix it around the house has been a great help. Granted, I’ve prob not saved money over all (after chemicals, board, laminator etc) but its great to know the things I have built are being used every day in my household.

Continuing again with my Raspberry Pi adventures and further developing my ‘BeeSafe’ project. One of the components I need to integrate is GPS module that would allow me to track the BeeHive / box should someone decide to move it.. To this end I purchased a few GPS units from ebay. This guide should get you up to speed on how to access GPS data via your Raspberry Pi / linux setup.

USB GPS with magnetic base

USB GPS with magnetic base

Plug the USB GPS into the pi, you should be able to see it detected in

sudo lsusb

Mine came up as: Bus 001 Device 004: ID 1546:01a6 U-Blox AG

Using:

dmesg | grep -i usb

I worked out that my USB GPS was paired to ttyACM0

At this point you can test your GPS device is functional and sending data by:

sudo cat /dev/ttyACM0

The next thing we need to do is pipe the GPS feed into GPSD (the gps demon) for it to interpret the data and hopefully give us something useful to use later.

sudo gpsd /dev/ttyACM0 -n -F /var/run/gpsd.sock

this command connects the output of ttyACM0 to the gpsd socket

NB: I had to ensure that the -n flag was present in this command, as trying without the flag resulted in a time out.

You should now be able to test the GPS using

cgps -s

Which will bring up a small window showing the GPS data.

Things to note; If you have any problems and cgps always displays ‘NO FIX’ under status and then aborts after a few seconds, you may need to restart the gpsd service you may have to kill and reboot the gps demon by typing

sudo killall gpsd

and then

sudo gpsd /dev/ttyACM0 -n -F /var/run/gpsd.sock

 

which will restart the gpsd service and pick up the new settings.

Now you should be able to use the GPS data for whatever your project needs; in my case I want to build a GPS fence so that if my beehive is detected leaving a known area (such as a field) then it will alert me and provide me with a GPS co-ordinate feed.

I used the Lady Ada guide on how to setup GPS devices to help me; the link is:

http://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi/setting-everything-up

Following on my project to develop a Bee monitoring tool dubbed ‘Bee Safe’.

The next part of my project is to provide the remote raspberry pi with access to the internet via a USB 3G dongle.

Fortunately in the world we live in now; finding old / used 3G dongles is very easy to do. The one I’m using was purchased from Cex for the pricey sum of £6.

£6 3G Dongle

Newly purchased 3G Dongle

While cellular data speeds and modems have vastly improved over the recent years this project only requires sending small snippets of text with the occasional photo so high speed isn’t a priority on this project.

To pair a USB dongle with a Raspberry Pi (the computer used to power Bee Safe) you need to download and install some packages; PPPD & sakis3g

To start with download PPPD via APT-GET:

sudo apt-get install ppp

Then download sakis3g:

wget "http://www.sakis3g.org/versions/latest/armv4t/sakis3g.gz"

Unpack and make the file executable:

gunzip sakis3g.gz
chmod +x sakis3g

Then execute the script which will run with a basic GUI within terminal:

sudo ./sakis3g --interactive

Sakis has a fairly comprehensive list of connections available.

Once you have been through the setup guide the modem *fingers crossed* should be online and operational. You can now exit sakis. You will stay connected.

You can check your connection and details with this command:

sudo ./sakis3g connect info

This post was pulled together from various sources, the main two being:

http://shkspr.mobi/blog/2012/07/3g-internet-on-raspberry-pi-success/

and

http://raspberry-at-home.com/installing-3g-modem/

Mac OS  Security ships fully locked down. The idea being to protect servers and vulnerable users from malicious attacks from the get-go.

Permalinks make use of .htaccess files to allow URL’s to point directly to a specific blog post while making reference to the title of the blog; so in this case : http://www.mathewjenkinson.co.uk/getting-permal…rk-in-mac-os-x rather than http://www.mathewjenkinson.co.uk/?postid=123456. This for users is considerably easier to read and to navigate to.

To get Permalinks to work on your Mac (or other Unix / Linux box) you need to give your web server access to write the .htaccess file for that site.

On Mac OS; the steps are:

1) Load terminal and navigate to the root folder of your website; usually: ‘/Library/WebServer/Documents/Domain.com’

2) Change the ownership of the file to the www group by ‘sudo chmod _www .htaccess’

3) Navigate to ‘/Private/etc/apache2/sites’ and open (nano) the file connected to your site. It will be something like: ‘0001_any_80_domain.com.conf’

4) In the conf file; find the reference “AllowOverride” and switch it from “None” to “All”. Save the file

5) At this point you can reload Apache or the whole server; I tend to reboot the server using ‘Sudo Reboot’ as it only takes a few seconds to reboot.

So more recently I have started to make use of Cloud based systems, VPN’s, Web Services / Servers etc. One of the things I have wanted to build for a while is a portable Router / WiFi hub that can support a VPN connection.

There has recently been a lot of published warnings about people being exposed while surfing the internet at cafes or other public WiFi hot spots.

The idea of this project is to make use of a Raspberry PI, a second Ethernet Dongle, a Wifi Dongle and a VPN connection. One of the Raspberry Pi’s Ethernet sockets plugs into the public internet while the other (and soon to come WiFi Access Point) acts as its own private network, tunneling all data to the internet via a VPN connection.

Below are some of my notes about how I have build a Raspberry PI, VPN secured Router:

Raspberry Pi VPN Router Config

eth0 (on the PI) connected to the internal network
eth1 (USB to Ethernet) connected to the internet / network
tun0 The VPN Tunnel created when the PI connects to the VPN server
wlan0 (Usb to Wifi) Not Configured

Start with a NEW blank image of Raspberry ArmHF from http://www.raspberrypi.org/downloads

The first thing you should do is run:

sudo apt-get update && sudo apt-get install ca-certificates

which will update and upgrade your PI’s base image and also install certificates information

Once all the updates and installs have taken place we need to reboot the pi:

Sudo shutdown now -r

From here we need to configure all the network interfaces 1st
Then configure the VPN, test the vpn, and then install all the packages to make the Pi into a VPN’ed Router

To configure the network interfaces we need to edit the following file:

/etc/network/interfaces to do this we will use nano:

sudo nano /etc/network/interfaces

To keep things flexible and easy to manage we will want the INTERNET facing ethernet socket to be a DHCP Client, remember this is the USB to Ethernet port (eth1). We want the INTERNAL facing Ethernet socket (On the Pi, eth0) to be static and issue out IP addresses to connected computers. When the VPN connection goes live we will link the Eth0 to Tun0 so that all data traffic from Eth0 goes via the VPN connection.

Inside /etc/network/interfaces we need to add the following (removing the old data):


# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo
iface lo inet loopback

#Onboard NIC connecting to the Internal Network
auto eth0
iface eth0 inet static
address 192.168.50.1
netmask 255.255.255.0
network 192.168.50.0
broadcast 192.168.50.255
gateway 192.168.50.1
#USB NIC serving as internet gateway
auto eth1
iface eth1 inet dhcp

Save the file and close the editor, as it stands now, your file has been saved but not loaded. You can load the file by either rebooting the PI or rebooting networking interfaces:

sudo /etc/init.d/networking restart

You can either do this now or in my case, wait and install all packages needed and then give the system a reboot to load everything in one go.
From here we need to install the following tools:

bind9 isc-dhcp-server perl libnet-ssleay-perl openssl openvpn libauthen-pam-perl libpam-runtime libio-pty-perl libdigest-md5-perl apt-show-versions libapt-pkg-perl this is done by:

sudo apt-get install bind9 isc-dhcp-server perl libnet-ssleay-perl openssl openvpn libauthen-pam-perl libpam-runtime libio-pty-perl libdigest-md5-perl apt-show-versions libapt-pkg-perl

Installing the VPN Tunnel:
With OpenVPN installed we can load our provided .OVPN file. This will have been generated (or provided from your VPN provider) by your server and needs to be loaded into:

/etc/openvpn/

In my case, i have the file loaded on an internal webserver so I just issue the commands:

cd /etc/openvpn/

sudo wget http://server.local/files/PI_VPN.ovpn

This downloads the .ovpn file to the directory, now we need to edit the file’s name so that OpenVPN picks it up on the next reload.

sudo mv PI_VPN.ovpn openvpn.conf

Now you need to reboot the VPN Server to pick up the new settings:

sudo /etc/init.d/openvpn restart

Installing the Router section:
Now we need to edit the DHCP server config details so that when users connect to the PI it will issue a DHCP address and resolve DNS Queries.

sudo nano /etc/dhcp/dhcpd.conf

As we want this DHCP server to have command of the IP network we need to make it authoritative, so you need to find and remove the # uncommenting out the following line:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Now we need to add a new subnet to the network:

subnet 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.10 192.168.50.250;
option broadcast-address 192.168.50.255;
option routers 192.168.50.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name “local”;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

This sets the reference IP range from 192.168.50.10 to 192.168.50.250 – more than enough for a small local network.
The networks domain is called ‘local’ you can also change this to anything you want ie home

Ive also appended the DNS Settings for Google’s Domain servers to this note, this means any DNS lookups perfomed by the PI will resolve against Google and not your ISP. If your using a custom DNS Server this is the place to change the information to reflect this.

Now Save the file and exit.

You can reboot the DHCP Service by typing in:

sudo /etc/init.d/isc-dhcp-server restart

You should recieve two OK messages.

If you have more than one device connected to your (new) internal network you should be able to ping them by typing in:

Ping 192.168.50. 55 (assuming your ping’ing device has an IP of 192.168.50.55) but it wont allow you to connect out to the wider world just yet.

Now we need to edit the IP Tables of the PI, to allow the forwarding of traffic from the VPN gateway into the internal network.

To do this type:

sudo echo 1 > /proc/sys/net/ipv4/ip_forward

which will allow the forwarding of IPV4 IP traffic, we also need to edit:

sudo nano /etc/sysctl.conf

and uncomment out (remove the #) around the line:

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Save the file and exit.

Now we need to edit the IP Tables rules to allow for traffic. Type in:

iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Unfortunately, due to the nature of IP Tables if the PI looses power, it will reset it the IP tables back, loosing all your settings (not handy if you plan on moving the PI about) so we need to now backup and save your new settings.
This is done by saving your IP Tables as a rule file:

sudo iptables-save > /etc/iptables.up.rules

You can call the saved file anything you like, but it helps to keep things organised.
Now we need to create and edit a script to load the IP Tables Rule file:

sudo nano /etc/network/if-pre-up.d/iptables

and insert:

#!/bin/sh
#This script restores iptables upon reboot

iptables-restore < /etc/iptables.up.rules

exit 0

Now we need to edit the ownership & permissions of this file so it will run on boot:

sudo chown root:root /etc/network/if-pre-up.d/iptables && sudo chmod +x /etc/network/if-pre-up.d/iptables && sudo chmod 755 /etc/network/if-pre-up.d/iptables

You should now be able to reboot your PI as much as you like and it will retain all your data settings! (YaY).

Its worth giving your PI a reboot now, Given all the things you have now loaded onto the PI you will need to give it a reboot to get it going properly.

Following on from my previous post (see post), concerning the unboxing of an Android based Mini GPS tracker, I’ve finally cracked how it works and what you need to do, the below is a review and how-to on my successes with the device so far;

For starters the Tracker is tiny:

Operation is relatively simple; I’m using a prepaid SIM card which you simply slot into the SIM card slot, once fully inserted the Tracker activates and a red light illuminates for about 10 seconds.

Initially my tracker did nothing, I spent the morning trying to see if it was a SIM card fault, the number not being activated or the tracker itself. Eventually I came to the conclusion that all things network related were fine and began to lose confidence in the Tracker.

THEN: It sprung into life. Out of no-where the tracker started responding to SMS commands and if I were to ring the device it would answer and I could hear the surrounding – very interesting.

Points to note:

‘GPS’ & ‘DW’ commands appear to do the same thing, but not what I was expecting.

I was expecting a raw output of GPS Lat and Long Co-ordinates from the Tracker, something in a raw easy to use format would have been nice… but alas I was presented with this:

Not being able to read the Chinese I don’t know what it says but a quick copy and paste of the characters into Google Translate reveals ‘View image URL’ so now we know that the device is using some kind of 3rd party mechanism to present the users with a picture of a map centered around the GPS co-ordinates.

It would have been nice to have raw GPS data, particularly as the URL your forwarded too doesn’t seem to work and auto directs to another web server which isn’t currently working.  Given that this device is (hopefully) Android based their might be an option to reprogram the tracker? –don’t hold your breath.

A quick few Google searches reveal a few others are having the same issues – both with the web server as well as the lack of any kind of good quality support from the sellers. Below is a link to a seller who appears to be communicating:

http://club.dx.com/forums/forums.dx/threadid.1261336