gecko's site

Raspberry Pi Arrived


This is an ancient article from my short-lived Posterous blog, before they got bought out by Twitter and discontinued. Most of the information here is outdated, but I thought it'd be fun to publish for prosterity.

The Pi was super useful overall! At school I'd remote into it via PuTTY and do my computing classwork in the terminal. This spared me the pain of having to use the Turbo Pascal IDE in 2013 (yeah wtf). But probably the coolest thing I did was to run a small Pokémon Showdown server for my friends, modified to support random LC battles.

It was my 17th birthday recently and my grandma was kind enough to buy me a Raspberry Pi (256mb Model B), though she didn't know what the heck it was. Here's a little explanation on what I've done with it so far:

Initial Setup

I'm still relatively new to Linux/Unix, although I've had some experience with the terminal on my phone and iPod Touch, and running lightweight distros on VMs on my laptop, so I learned tons even in the first few steps. Having flashed Raspbian Wheezy onto my SD card with win32diskimager, I found a spare USB keyboard and mouse and connected the Pi to my TV with an RCA cable.

The startup guides had a lot of warnings about using at least 700mA power supplies - the specs on the side of my phone charger were confusing but it worked fine. I powered the Pi up and was welcomed by the raspi-config screen, where I set a password and resized the OS to fill the whole SD card. After that was done, I restarted the unit and was welcomed by the terminal. The startx command is used to initialize a desktop, although I haven't needed to use it much yet.

Remote Access

The latest Raspbian has SSH enabled by default, so this was pretty painless. I'm using PuTTY on my laptop, and my iPod Touch and Android phone both have SSH clients on them, so I can pretty much get onto the Pi from anywhere in my house. In order to remotely access the desktop, I installed tightvncserver with apt-get. Conveniently this starts up its own X desktop instance in the background, so I can start up tightvncserver over SSH, then connect with a VNC client. I've ordered a wireless dongle so hopefully I won't have this ethernet cable stretching across the house for much longer.

One of my main uses for the Pi is to run my Lua IRC bot on the bonuslevel chat, so I installed Lua and transferred the source via SFTP. The bot ran fine, but I had trouble launching it over SSH because it requires some initial input, but it must then run in the background even after the session has ended. The solution for this was to use a tool called dtach, which is perfectly suited for situations like this.

The command to create a new session and attach to it is

dtach -A <socket> <command...>

This confused me initially, as I thought that 'socket' was supposed to be a network socket, which was wrong. It is actually a Unix domain socket, which is a local means of communication between programs, bound to a temporary file which exists during the socket's lifetime. So, I can run

dtach -A bot_sock lua Main.lua

When I'm done responding to the bot's initial prompts, I can hit ctrl+\ to detach from the session. Now I have my Lua process running continuously in the background, and I can end the SSH session and go to France and have a McDonalds, while my IRC bot remains functional, running off a tiny board at home. Pretty cool.