Monday, February 25, 2013

My first Ninja Block module on dashboard

After being able to setup my RasPi as a Ninja Block (as I mentioned in my previous post) it was time to get an actual module to run. I didn't want to connect anything to my Pi while learning so I thought I could try to measure the temperature using wither vcgencmd or /sys/class/thermal/thermal_zone0/temp (there are a couple of posts in forum related, this being one of them). That proved to not be a good idea since the Occidentalis image I started with doesn't have them installed and no matter what I tried (rpi-update, dist-upgrade) I couldn't get them to work. I spent a day trying things with no success, I think I updated the Pi firmware probably 4 times and it is a very long process. Oh well, I should have listened to the comments in the forum and go a different direction and that would have saved me so much time. When I finally gave up on the firmware update, things started to get better.

This other idea was to follow this articol "Creating Modules for Fun and Profit" which in turn is based on this one: "Hack like a Ninja (Blocks developer)" which details step by step how to get the environment ready. The only thing that is missing is details about compiling nodejs from source (because the nodejs version on the image is 0.6.x while ninja blocks needs 0.8.x or greater): I found some here. To make it easier for future or for whoever find this article, these are all the steps in order.

- download, compile and install nodejs (make takes a couple of hours, make install also takes quite a bit):
wget http://nodejs.org/dist/v0.8.11/node-v0.8.11.tar.gz
tar -zxf node-v0.8.11.tar.gz
cd node-v0.8.11
./configure
make
sudo make install
- symbolically link the nodejs binary to node for future use (this errors for me with a "file exists" messsage but it seemed that it works even without it):
sudo ln -s /usr/bin/nodejs /usr/bin/node
- install node-gyp globally via the node package manager:
sudo npm install -g node-gyp
- in order to build on your platform you might need to download some extra tools:
sudo apt-get install build-essential
Ninja client setup.

- check-out the source code from https://github.com/ninjablocks/client into a directory ninjaclient, switch to the 'develop' branch, and download dependencies (last step grabs the dependencies from package.json and builds them if necessary - it may take a while):
git clone git://github.com/ninjablocks/client.git ninjaClient
cd ninjaClient
git checkout develop
./bin/install.sh
Running the Client.

- set the environment variable "NODE_ENV" to "hacking", eg. linux/mac (can also be put in something like ~/.bash_profile) - better for development:
export NODE_ENV=hacking
- from inside the client directory, run client.js with node:
node client.js
- copy the serial number from this line:
...(info) This Ninja's Serial: XXXXXXXXXXXXXX
Protip: Install the handy nodemon tool (sudo npm -g install nodemon) and use nodemon in place of node. Nodemon will restart the app whenever file changes are detected, very handy for development. This didn't work for me, but according to this article all I need to do is start index.js with nodemon instead of node:
nodemon index.js
After this, just follow the steps in the first article I mentioned "Creating Modules for Fun and Profit" and hopefully you will get a new module on the dashboard as I did - I was so happy to see it working. Also, as a bonus I got the limitlessLED module working (which was included in the ninjaClient download) which was an awesome thing in itself.

I couldn't have done this without the help of the guys on the Ninja Blocks forum, especially: marcel_d, andynix and nick. Thousand thanks to all of them!



For future reference, the way I tried to update my Pi firmware is below: In each case I ended up with errors related to a library used by vcgencmd that according to some posts should have been resolved by a reboot but that didn't happen in my case.

- use the info on this page: http://raspisimon.no-ip.org/firmware.php OR
- this page: https://github.com/Hexxeh/rpi-update

In a nutshell both these boil down to:
sudo aptitude install git-core
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update
sudo rpi-update
Instead of the rpi-update I also tried sudo apt-get update && sudo apt-get dist-upgrade which could be better because rpi-update gets the very latest version (with potential bugs) while apt-get upgrade gets the latest stable version, but this didn't work either. Apparently if I'd started with the official raspbian image I would have had these utilities from the start but I like more the Occidentalis one since it sets up a lot of useful stuff from the start.

No comments:

Post a Comment