Monthly Archives: January, 2012
BeagleBone FTP Server
BeagleBone FTP Server
The BeagleBone has multiple text editors available onboard, including
vim. I can stumble around (badly) in vi. Using Vim is a little prettier, but not much – I’m really much more of a modal-editor guy. On the Mac, I use BBEdit when I’m not using XCode for iPhone and iPad development.
So my goal is to be able to easily edit on my Mac. BBEdit has a very slick ability to edit files via FTP, so that’s my next step.
Oddly, the BeagleBone doesn’t have an FTP server available in the default distribution. (or if it does, I couldn’t find it)
One skill I know I need to brush up on is acquiring, building, and installing packages in Linux. Since I wanted a quick-and-dirty FTP server running without too much fuss, I naturally looked to Python.
Python is a terrific “scripting” language, and my go-to tool for a lot of tasks.
There is a very nice FTP Server library available: pyftpdlib.
I grabbed this using
wget, then did the unzip/untar dance:
gunzip pyftp* tar -xf pyftp*.tar
Installation was simple. The setup python program failed, so I just manually moved the
pyftpdlib directory into
Last but not least, I whipped up a small Python program by modifying the quickstart and demo examples just a bit:
# FTP server from pyftpdlib import ftpserver authorizer = ftpserver.DummyAuthorizer() authorizer.add_user("root", "12345", "/home/root", perm="elradfmw") handler = ftpserver.FTPHandler handler.authorizer = authorizer address = ("", 21) ftpd = ftpserver.FTPServer(address, handler) ftpd.serve_forever()
Take that code, stuff it into a file with a
.py extension (e.g.
ftpserver.py), and invoke it:
And there you go – FTP access to the home directory of user
Now, is this what you’d use to server files to the world at large? Maybe – it looks like a very complete implementation, although I’m no FTP expert.
But it’s perfect for my local development purposes.
The only thing that would be nice is to have it auto-start. That’s pretty easy to do as well, at least in the simple case.
/etc/init.d contains scripts that are executed upon system startup. We place a very simple shell script there, which I called
#!/bin/sh python /home/root/ftpserver.py
This will run the Python FTP server program (which in this case is located in the root account’s home directory – it could be located elsewhere of course).
Once you create this script, don’t forget to make it executable by doing
chmod +x ftpserver.
Although this works, our script should really be more compliant and let us stop and restart the server. I plan to address that soon!
BeagleBone and the Mac – Part 2
The ongoing BeagleBone saga, part 2
(As viewed from a Mac)
To connect an SSH terminal session from the Mac is as easy as:
This is typed in a Terminal shell on the Mac of course.
To terminate the session, type the “escape” character followed by a period. The escape character is tilde by default, so type this to end the session:
To install Lua on the BeagleBone:
opkg install lua5.1
BeagleBone and the Mac
Last week, my cool little BeagleBone arrived from Adafruit. This post is my attempt to describe getting the BeagleBone set up on a Mac with OSX.
Not everything I’ll be writing about is necessarily unique to using it with a Mac (versus say, Windows or Linux), but that’s obviously going to be my perspective since I’m a Mac guy 100%.
The general tasks look like this:
- Download the latest OS to a Micro-SD card.
- Install USB serial driver on the Mac
- Connect the BeagleBone to the USB port
- Open a serial terminal to the USB port
- Talk to the BeagleBone!
Out of the Box
A New Pre-Built Linux Image
As the BeagleBone “Getting Started” guide suggests, the Linux image that comes pre-installed on the SD card that comes with the BeagleBone may not be the latest available.
You can download a more recent image from the links in the guide. Once you do, it needs to be written to the SD card.
To write the image to the SD card, it first needs to be unmounted.
diskutil unmount /volumes/YourCardNameHere
Then, write the image to your SD card. Note that the
diskXXX should be the actual disk device assigned when the SD card is connected.
This can be found a couple ways. You can use the “Disk Utility” application, or the command line
These may show you the partition, something like
disk7s2. You want to entire SD card, not any partitions so drop the
gunzip -c Angstrom-Cloud9-IDE-eglibc-ipk-v2012.01-core-beaglebone-2012.01.11.img.gz | dd of=/dev/diskXXX bs=4096
USB Serial Drivers
For my Lion setup, all I needed to install were the drivers that came with the BeagleBone.
These were on the USB “drive” that appears when you connect the BeagleBone to your Mac, as well as available from the BeagleBone website FTDI_Ser.dmg
The command line program
screen makes a pretty handy serial terminal.
screen /dev/tty.usb*B 115200
I set up my
~/.screenrc file as follows:
termcapinfo xterm* ti@:te@ autodetach off
The first line causes the scrollbars in the terminal window to work for scrolling back the serial terminal text lines. (See this stackoverflow post for details on why this is needed)
The second line will cause the screen session to terminate (rather than just “detach”) when you close the Terminal window.
Both of these are behaviors you probably want.
Custom Terminal Settings
You can also set up a custom set of terminal settings. I defined a set that made the window larger, and – most importantly – executed the
screen command automatically.
The BeagleBone uses DHCP to get an IP address from your local network. (assumes your local network is set up to do that of course – most are)
To connect to it via a browser etc you need to know its IP address. Here are three ways to do that.
- Use a local name
- Display the assigned IP address using the USB-serial shell
- Look at the addresses assigned by your router
In my case, the router on my network is an Apple Time Capsule. I mention this just in case your router works differently.
The “local name” scheme works great. The BeagleBone identifies itself as “beaglebone” to the DHCP server. I can connect to my BeagleBone as
Alternately, using the command
ifconfig via the USB-serial shell will display the IP address assigned to the BeagleBone’s ethernet port. (at the moment, mine is 10.0.1.2)
The third option is router-spcific. In the case of the Time Capsule, run the Airport Utility application on the Mac. Select “Manual Setup” for the TimeCapsule, got to the “Advanced” tab, then “Logging & Statistics”. On that screen, select DHCP Clients and you’ll see a list of devices and their assigned IP addresses. You will also see the client ID, which in this case is “beaglebone”.
These will include an FTP server, Mercurial, and perhaps an editor like