"Clojure running on Raspberry Pi" sounded so cool that I just had to give it a try.
- Download ARM JDK from Oracle and instlal on Raspberry Pi
- Change visudo to contain the following
Defaults env_keep +="JAVA_TOOL_OPTIONS LEIN_ROOT"
Defaults mail_badpass
Defaults secure_path="/usr/lib/jvm/jdk-7-oracle-armhf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Create ~/bin if not there, log off, and log back in.
- Follow the super simple Leiningen install instruction
- Copy ~/bin/lein to /usr/local/bin for sudo action
Let's see, what would be a one of a kind app that noone would think of.
Oh, I know I know, an adserver written in Clojure running on $35 Raspberry Pi.
pi@raspberrypi ~/ $ lein new app piadserver
You want to run the code on Raspberry Pi, but you don't want to have to do the development itself on Pi. It'd be ideal if you can just edit the files remotely, and run repl remotely.
We can do all that.
Avahi is open source replacement of Bonjour, and netatalk is AFP (AppleTalk over network). By installing these two packages, your raspberry pi will magically appear in your Finder sidebar, and you can connect (be sure to use valid user/password on RaspberryPi) browse, and open files on your Pi.
sudo apt-get install avahi-daemon
sudo apt-get install netatalk
Now you can edit your app in your favorite IDE. I use IntelliJ IDEA with La Clojure, although this setup is known to hang at startup, so I also frequently use Eclipse.
You can login via ssh and run REPL, but for some reason Pi's network latency is awful. I get ping times in 100's of mS range even on directly connected ethernet, and trying to work via remote login is reminescent of 2400bps serial terminal.
Fortunately, you can run a headless REPL on Pi and connect to it from REPL shell running locally on your Mac
Start REPL in headless mode. Note that :host argument means which network interfaces to listen to, so you can enter your Pi's IP address here.
I use Wifi dongle on the Pi so it has two network interfaces, and I'm too lazy to look up Pi's IP address everytime. So I use 0.0.0.0 which means listen on all interfaces (IP addresses) on the Pi.
If you want to just keep the headless REPL running, you can run it in tmux
session (install tmux package first, of course). I recently found out that you can make screen
do the same.
lein repl :headless :host 0.0.0.0 :port 9000
Also, starting REPL can take a couple of minutes on Pi. You may need to add the following to your project.clj
:repl-options {:timeout 300000}
From the mounted project directory, run the following
lein repl :connect xx.xx.x.xx:9000/repl
Now you are connected to remote REPL running on Pi.
Although slightly old, there is a great writeup at IntelliJ IDEA ate my nREPL for maven based setup.
You don't really have to go through all that gyration if you use Cursive plugin on IntelliJ IDEA 13.1. Remote REPL 'just works'.