Route static files for BottlePy web framework

I have been using BottlePy on my Raspberry Pi for quite some time. I really like the simplicity of the framework and the ease at which you can get something up and running. The one issue I had, was that you could not load static css or js files. 
There are ways around this, like placing your files in Gist and linking to the raw code, but this can be an issue when you want to run your webserver ‘offline’. The documentation is not very clear on how to do this, so here is what I did to get it working properly. 
This is the template that I use to route the static files. This is part of my main python code that runs the server.
Then all you need to do is add your file names in the .tpl file. By doing this, your css, or js files can be stored locally so they can still be served if you are offline. 
That is about it. I hope this helps because I really find this framework great to use and works flawlessly on my Raspberry Pi.

Raspberry Pi: Direct connection to Windows 7

This is something I have been wanting to try for quite some time but never really found much info on how to do it. Well I sat down the other day to get it done and realised that it is MUCH easier than I expected.
My objective is to directly connect my Raspberry Pi to my laptop using an ethernet cable. In the next few months I am going to be away from a decent internet connection but I still wanted to do some work on my RasPi. So my Google searching started, finished and here is what to do.
The process uses a built-in feature of Windows 7 called Internet Connection Sharing (ICS). In a nutshell, you can use any Windows computer with more than one network connection, WiFi and LAN, and share the connection to other computers. 
Firstly you need to set up the settings on Windows. You need to go to the properties of your disconnected LAN connection and click on the sharing tab. Then check the box to allow other network users to connect through this internet connection.

The tricky thing to set up is the IP address that you are going to give the RasPi. You need to check the TCP/IPv4 settings under the Networking Tab. I picked an IP address and gave my RasPi a static address so that I know what it is when ever I use this connection.
Next you need to power up your Raspberry Pi and connect to it some way. Either use a WiFi connection that is already set up, an ethernet connection to your router or using the serial port on the GPIO.
You then need to set up the IP address by editing the interfaces file.

sudo nano /etc/network/interfaces

Change the part of the file that refers to your eth0 connection to look similar to below. You might have other settings in there like WiFi IP addresses and passwords but just leave those alone.

iface eth0 inet static 



Once you have saved the interfaces file, send the shutdown command so that you can change over the connections. Once powered off, directly connect your RasPi ethernet port to your Windows ethernet port. You should be able to use both straight-through and cross-over cables. Now power up the RasPi.
Once booted up, you should be able to log in with Putty to the static IP address that you set above. 
And that is pretty much it. Another cool thing by connecting this way is that you should be able to power your Raspberry Pi from your computer USB port. This makes transport really easy as all you need is an ethernet cable and a USB cable to get up and running. 
Hope this helps and if you have comments or questions, please leave them below and I’ll get back to you as soon as I can.

Raspberry Pi: NAS server

I have been wanting to set up my Raspberry Pi as a Network Attached Storage (NAS) drive for quite some time. I eventually got a chance yesterday to give it a go. Unfortunately the Raspberry Pi USB port can’t power my external hard drive and I don’t have a USB hub at the moment, so I just used a 16GB flash drive.
First you need to format your external drive with NTFS. Then place a file on it. Any file will do. I chose a text document so that I can open it and view it on the Pi. Once you have set up your drive, turn off your RasPi, plug the drive into the USB port and then turn on the RasPi. It is safer to plug the USB in when the RasPi is off because some versions don’t have poly fuses on the USB ports.
Once booted up, log in and check to see if the drive is connected.
  • sudo fdisk -l

You can see that my connected drive is right at the bottom. The drive is called sda and because there is only one partition, it is called sda1.
Next you need to create a folder where your drive is going to be mounted into. I called mine myHadrDrive. You also need to give the folder root access so that when you connect to it you are able to read from it and write to it.
  • sudo mkdir /mnt/myHardDrive
  • sudo chmod 0777 myHardDrive
Next you need to mount the hard drive to the folder that has just been created. Open fstab and add the following line to the bottom of the file where it reflects your setup.
  • sudo nano /etc/fstab

Mount the drive
  • sudo mount -a
Now we need to install and set up the Samba server. This will allow a windows machine to connect to the RasPi over the network. Start by installing the following packages using apt-get.
  • sudo apt-get install samba
  • sudo apt-get install samba-common-bin
  • sudo apt-get install ntfs-config
  • sudo apt-get install ntfs-3g
Once all of those packages are installed, edit the Samba configuration file. It took me a while to get this right but with the help of this video, I managed to get it. 
  • sudo nano /etc/samba/smb.conf
Replace the entire file with the following:

#======================= Global Settings =======================
workgroup = WORKGROUP
server string = raspnas server
netbios name = raspnas
dns proxy = no
### Logging
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
panic action = /usr/share/samba/panic-action %d
### Authentication
security = user
map to guest = pi
#======================= Sharered Folders =======================
path = /mnt/myHardDrive
guest ok = yes
guest account = ftp
browseable = yes
read only = no
create mask = 0777
directory mask = 0777
writeable = yes
admin users = everyone

A few points to note:
  • WORKGROUP is the workgroup that the drive will be connected to
  • raspnas is the name of he drive on the network
  • path is the folder that you set up earlier
  • Change the file according to your setup
Lastly you need to restart the Samba service and add the user to the Samba database
  • sudo service samba restart
  • sudo smbpasswd -a pi
Now your Samba server is set up. You still need to do one last thing. You need to make sure that the drive gets connected at startup.
  • sudo apt-get install autofs
Add the following line to the bottom of the config file
  • sudo nano /etc/auto.master

Reboot your RasPi and then you should be able to log on to the shared drive using your Windows machine.
I hope this has helped anyone who was stuck. If you still have any problems leave a message in the comments and I’ll try help as best I can.

Raspberry Pi meets TI LaunchPad MSP430

A few weeks ago I got a TI LaunchPad. With the help of a few tutorials I managed to get the basic input, output and UART working. As most of the examples that I could find are for CCS, I decided to go that route instead of IAR.

My next step was to get my LaunchPad working with my Raspberry Pi via the USB port. After a bit of playing around and installing a few programs, I managed to get it to work. Below is how I got a program  written, compiled and programmed onto the LaunchPad from the Raspberry Pi.

First you have to install a few programs with apt-get.

$sudo apt-get install binutils-msp430
$sudo apt-get install gcc-msp430

$sudo apt-get install msp430mcu

$sudo apt-get install mspdebug

$sudo apt-get install msp430-libc

You might have to run

$sudo apt-get update

before installing the modules.

Next run mspdebug to make sure that there are no errors. If there are no errors type exit to close the debugger.

$sudo mspdebug rf2500

Now that you have everything installed, we need to create the program. I use nano text editor to write my program.

$sudo nano button_ISR.c

This program uses the two LED’s and one push button on the LaunchPad. When the button is pressed, an interrupt is generated and then the LED’s are toggled.

Close nano saving the changes.

The program then needs to be compiled.

$sudo msp430-gcc -mmcu=msp430g2553 -g -o BUTTON_ISR button_ISR.c

The program should compile without any errors and now you are able to run the debugger.

$sudo mspdebug rf2500

Now program the device


and run the program


CTRL+c will stop the program running and exit will close the debugger.

In the next post I will show you how to communicate between the TI LaunchPad and Raspberry Pi via hardware UART and the USB connection.


Raspberry Pi: Edimax EW-7811UN WiFi Dongle

I recently bought myself an Edimax Wifi dongle to use with my Raspberry Pi. My router is hidden away so I got tired of running a network cable to my Raspberry Pi. The Edimax WiFi dongle was ideal as it is really inexpensive and very small.
It took a while for me to get it set up correctly but eventually I got there. To set up the WiFi connection, you either need a ethernet cable plugged into your Raspberry Pi or you need to connect via the serial port. I connected via the serial port with a FTDI USB to UART converter as this made it much easier to know when the network was connected. 
First of all plug the dongle into one of the USB ports and then reboot.I have not tested this in a USB hub but I am sure it will work the same. To make sure that the dongle has been started, run 


and make sure that wlan0 can be seen.

The next step is to see if your Raspberry Pi can see your wireless network. Run the following command and look for your network.

sudo iwlist wlan0 scan

Under ‘Cell 01’ I can see my network. Take not of your ESSID and you will also need your network password.
Once you have established that your Raspberry Pi can see your wireless network, you will need to edit the network interfaces file.

sudo nano /etc/network/interfaces

You will need to add the following:

  auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid ‘your ESSID’
wpa-psk ‘your password’

Your interfaces file should now look like this. Note that I have set a static IP address so if you still use DHCP then you will not need the static IP address settings like I have.

Restart your network connection by running

sudo /etc/init.d.networking restart

and then run


and you should notice an IP address assigned to wlan0.

Now reboot your Raspberry Pi to make sure that everything is working in order.

sudo reboot

If your connection is up and running after the reboot, then you are all set to go wireless.