Z-Scale Controller part XI: Integration on a BeagleBone
The very last step of this story, is how to put together a Linux microSD image for the Beaglebone, that works right out of the box and will turn your train controller into something you can just plug in and work with, as it should be.
Note: this article is still in progress, and will get updated shortly!
Instructions on how to flash a uSD with Ubuntu: very simple now, just go to http://www.armhf.com/index.php/boards/beaglebone-black/ and you’re pretty much done!
Getting the bone’s hostname to register with the local DHCP/DNS server and Bonjour
By default, the BB Ubuntu image does not ship with zeroconf support, which means that depending on what your local network looks like, you might need to find out the IP address of the BBone by yourself. In order to avoid this, let’s just install support for Zeroconf/Bonjour/mDNS/youNameIt:
vi /etc/hostname and update to "train-controller" apt-get install avahi-daemon
… and that’s about it, 30 seconds well spent! You can now access your controller at ‘train-controller.local’.
Creating a user
Default user is ubuntu/ubuntu . Create a ‘controller’ user and set the password to ‘train’. No big requirement for a complex password, though of course if your local network gets hacked into, your train controller might be turned into a very low power zombie…
NodeJS and MongoDB
Instructions on how to install NodeJS and MongoDB on Ubuntu Raring: this is now very easy. For MongoDB, just “apt-get install mongodb”, it now works fine. For Node, you probably want the latest Node:
You should go to nodejs.org and download the latest source. On the BBB, you will need to “apt-get install build-essential” then the trick is to use “./configure –without-snapshot”, and node will work fine.
All in all, literally a 20 minute job, with most of the time spent compiling. How easy is this?
Train controller app
The train controller app should then be fetched from github and installed in the home directory of the user you just created:
git clone https://github.com/elafargue/train-controller.git
Then go to the “server” directory and run “npm install”. That’s about it, simple enough.
The very last step is to automate boot time startup of:
- The train controller web app
- The Cloud9 IDE
On Ubuntu, the modern way of starting/stopping services is through simple scripts in /etc/init:
# Ubuntu upstart file at /etc/init/tc_cloud9.conf start on runlevel  stop on runlevel  script ENABLE_CLOUD9="yes" DAEMON_ARGS="-l 0.0.0.0 -w /home/ubuntu/controller/train-controller/server" if [ -f /etc/default/tc_cloud9 ]; then . /etc/default/tc_cloudd9; fi if [ "x$ENABLE_CLOUD9" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid ubuntu --background --exec /home/ubuntu/cloud9/cloud9/bin/cloud9.sh -- $DAEMON_ARGS; fi end script
Likewise, for the train controller:
# Ubuntu upstart file at /etc/init/tc_controller.conf start on started mongodb stop on runlevel  script export HOME="/home/ubuntu" ENABLE_CONTROLLER="yes" DAEMON_ARGS="/home/ubuntu/controller/train-controller/server/server.js" if [ -f /etc/default/tc_controller ]; then . /etc/default/tc_controller; fi if [ "x$ENABLE_CONTROLLER" = "xyes" ]; then exec sudo -u ubuntu /usr/local/bin/node $DAEMON_ARGS >> /tmp/controller.log 2&>1; fi end script
The exec command is a bit different, as node is a bit more difficult when it comes to starting it as a daemon, but this version works fine.
Goodies: Cloud9 IDE installation
Followed instructions at: https://github.com/ajaxorg/cloud9/
Except that you need a bit extra for ARM:
$ cd cloud9/npm_modules/
$ git clone https://github.com/ajaxorg/node-libxml.git
$ cd node-libxml
$ git checkout v0.0.7
$ git submodule init
$ git submodule update
$ vim support/o3/wscript # and remove the ‘-msse2’ option where it appears
Then go back to the cloud9 repo and do a npm install.
SD Image backup
It is pretty straightforward to just create a binary image of the result, so that if anything goes wrong at a later stage, you can just restore the BBB SD image and get back on your feet right away.
Adding application backup and restore
While the capability of just dumping the SD card contents is nice, it is totally overkill if we just want to save what we have done in the application.
It used to be a manual process, but the Train Controller app now supports backing up directly from the “Settings” page 🙂