Programming and writing about it.

echo $RANDOM

Category: raspi

Raspberry Pi: Personal Perspectives

I have been playing around with the Raspberry Pi  (Pi) for two months now. I started by installing Raspbian on a spare 4 GB memory card. I also had a wireless Wifi dongle and a wireless keyboard-mouse lying around. I plugged the WiFi dongle and the dongle for the wireless keyboard-mouse in the two USB ports of the Pi and when I plugged in my spare mobile charger into the Pi’s power input, the Pi booted. I felt lucky to see the display on the TV without any hassles. So far all in all, out of the box experience and all I had bought was the Pi. I already had the other stuff lying around.  It was fun to see something on TV that I am used to seeing on a computer monitor.. The next thing I did was fire up the Python interpreter and tweeting the output of os.uname( ).

The Board by Amit Saha (amitsaha)) on 500px.com
The Board by Amit Saha

Next things I tried to do was like what I had seen most people do was trying to make a media centre out of the Pi. And few other things like setting up a audio server, etc came to my mind. But then, I thought to myself – I don’t have a huge media collection, nor do I play games, nor do I sit back a lot and watch stuff.  I think I am better off doing something else with the Pi. Its Linux in a more constrained environment after all. I fiddled around a bit with the Pi after that. Then, finally couple of weeks back, I installed the Fedora 17 ARM remix on the Pi. That was the point where I really started using the Pi.

Fedora 17 on the Pi

One of the first things I liked about the Fedora remix was that the SSH server was installed and enabled out of the box. Once I was done with firstboot, I plugged the TV jack out and work on the Pi by SSH-ing into it  (The Pi is connected to my home network via the Ethernet port).

I have been documenting my experiments with Fedora on the Pi here [1]. As you can see, most of the programming languages, frameworks and tools there is all the typical things you would be using on any Linux system – BASH, Python, Ruby, Flask – you name it. It was like – so it worked on Linux on the big machine, let’s say if its there on Pi and everything was pretty much so close to same that it started to seem like a chore – more about documenting what I was doing in the hope that it might be useful to some one and may be I can use them as a base for a book/article in the future. There in lies the essence of the awesome work done by the Fedora ARM team which made things a chore. Thank You folks! And of course to all the Python programmers who have made their packages available via PyPi. pip-python was indispensable.

No more a chore

Things changed a bit yesterday. I fiddled around with the GPIO pins for the first time. Using the WiringPi’s gpio command, it was as easy as it gets. I then used the Python package RPi to interact with the Pi pins from Python and it was quite dandy. As you can see from the documentation [2], among the two packages one of them was already installed and the other was installed from PyPi. Finally, that was something I can’t do so easily on my big Linux machines. That also meant, I do not have to use Arduino to fiddle around with some basic, hobbyist electronic stuff. In one of the coming days, I might hook up the Arduino with the Pi.

Role of Abstraction Layers

The most basic operating system course introduces it as an interface between the user and the hardware – an abstraction separating software from the hardware. I think the Pi is a great example for educators to show exactly what they mean. Have a traditional computer and a Pi side by side – write the same program and run it both the devices show them. That should be quite intuitive. The fact that I started finding things a chore was because the operating system was abstracting out the hardware from me.

Experimenting with C

The good thing (and the bad thing) about Python and Ruby (for example) is that you are one layer higher (than C) in the abstraction hierarchy. C is one layer close to the bare metal and hence should be an educational exercise to play with it on the Pi and compare it with an an Intel or AMD computer. That should help illustrating the differences you need to ponder about when you are programming in C (or C++) and intend your program to be also working on other architectures.

I touched on this in this article titled “Compilation and Interpretation in C and CPython“.

Conclusion

The experiments will continue.

Links

  1. Exploring the Raspberry Pi with Fedora Linux
  2. Tinkering around with GPIO Pins
Advertisement

Web based SSH access to your Raspberry Pi

See here for Fedora instructions.

Using wssh, you can setup a web based SSH access mechanism to your Raspberry Pi. This looks more attractive when you expose your Pi using a public IP address/hostname using a service like Pagekite. Let us see how (I am assuming your Raspberry Pi is running raspbian).

Installing wssh

wssh has a bunch of dependencies which you can install with a mix of apt-get and easy_install. Note that we will be using the in built wssh server, ‘wsshd’ which uses Flask for the Web application, hence we install Flask as well.

Install the dependencies:

pi@raspberrypi ~ $ sudo apt-get install python-dev libevent-dev
pi@raspberrypi ~ $ sudo easy_install gevent flask paramiko gevent-websocket wssh

It will take some time for these to install and once they are completed, you should be able to start the wssh server. If you get a message like that, your server is up and running and you can visit the URL in your browser.

pi@raspberrypi ~ $ wsshd 
wsshd/0.1.0 running on 0.0.0.0:5000

You will be greeted with a login screen such as the one below:

Login Screen

Note that this server is running on your Raspberry Pi, and hence localhost means the Pi itself. (You can ofcourse use any other computer’s hostname or IP address on your network). If you have been logged in succesfully, you should see the shell:

Shell

And then you can do all you wish to right there in your browser.

Public facing hostname

Once you make the server reachable at a public facing hostname, things get really interesting since you can now access your Pi from anywhere in the world, literally. A service like Pagekite.net can help achieve that. Once you have installed Pagekite and signed up using your email address, you can start ‘wsshd’ as a background process and tell Pagekite to make the 5000 port available as your chosen kite name:

$ wsshd &
$ pagekite.py 5000 yourpi.pagekite.me

And you should have your SSH login screen at your chosen kitename: http://yourpi.pagekite.me in this case. And ofcourse, you can use the instructions here to set this up for any of your other computers running Linux.

Making your RaspberryPi accessible to the World

Problem: Public facing hostname/IP address for your Raspberry Pi.

Solutions: Several solutions exist:

  • PageKite: The one I am most familiar with. Coded in Python. Since the Linux on your Raspberry Pi already has Python installed, its simple to get it working. Check it out
  • Localtunnel: I used it once. Doesn’t involve sign up from what I remember. Ruby, so you will have to install it. Check it out
  • showoff.io: Haven’t used this. Ruby again. Check it out

Both, PageKite and showoff.io have one month free trials and is paid beyond that. localtunnel is free and perhaps may not have all the features that the other two has.

Also see: Raspberry Pi Forum topic