Setting up node.js and MongoDB on a Raspberry Pi

I wanted to get node.js and mongoDB up and running on my pi.  I’ve got a couple of pet projects which I’m going to tackle and I’ve decided to use the MEAN stack (MongoDB, Express, AngularJS and Node.js).  The future, for now, is JavaScript and I’m looking to know enough to make informed decisions about my place in that future.

These are the steps that I followed to get it going …

First up, node.js …

Credit to: http://blog.rueedlinger.ch/2013/03/raspberry-pi-and-nodejs-basic-setup/

Before doing this step you want to check what the latest version is – go to http://nodejs.org/dist/ and browse, starting from the biggest number backwards, looking for a release that includes “linux-arm-pi” in the title.  That’s the one to use in the following code snippet, for me it was v0.10.24/node-v0.10.24-linux-arm-pi.tar.gz

add the following before “export PATH

That’s it!  Next let’s get a server running so we can make sure it’s working … create the following content in a file called nodejs.sh

then do the following to get it to run on pi boot

now for the server.js that will run our server

put the following in the server.js file

then start the server

A quick visit to http://192.168.0.123:8080 should result in a nice “Hello World” message.

Finally a bit of tidying up in /home/pi/

Next up – mongoDB

Credit to: https://github.com/RickP/mongopi and http://ni-c.github.io/heimcontrol.js/get-started.html

Note, the scons commands performs the build and will take a few hours each

add this before “export PATH

Then set up a new db and configure it to start on boot:

You can test everything went ok by launching the MongoDB shell with the command “mongo” … see the docs for more info.

Job Done!

Looking for an RSS reader

Ever since google axed their Reader product my news consumption hasn’t been the same. I tried out a few at the time and settled on theoldreader.com but I’ve come to realise that I wasn’t using it like I wanted to – google reader used to be the first thing I loaded whereas theoldreader was loaded only once a week.

I’ve made a switch to feedly to see how that goes instead – first impressions are promising – time will tell.

At the same time I tried out instapaper as I saw that feedly could add articles to that service – my trial was short and the account is now cancelled. I like the idea … but the first few articles I saved all had important images or videos embedded, not something that instapaper is targetting. I’ve resolved to use the feedly “save for later” feature and see how that goes.

Configure a reverse proxy in apache

After ensuring the following modules are loaded in the httpd.conf

The following was added as virtual host:

Job Done!

Setting up web ssh on a Raspberry Pi

After a bit of research I found a product called GateOne that would enable me to use a web browser to connect to ssh using standard https – cool!

Then ctrl+c so we can edit the config

at the end of the line with origins, add the IP of the Pi, i.e. , “192.168.0.123” then restart the daemon:

to check it out browse to https://192.168.0.123/

All that remains is to ensure it starts automatically on reboot – I think the update-rc.d script must be a bit buggy on the Pi.  I ended up doing all of this as I was having some trial and error fun:

Next up – some authentication …

within /etc/gateone/conf.d/20authentication.conf the authenication type was changed to google

and the terminal configuration (/etc/gateone/conf.d/50terminal.conf) was modified to turn off the terminal for all users (allow: false) and then add it back on just for me:

Back in /etc/gateone/conf.d/10server.conf I added my external dns to the list of allowed origins and forwarded port 443 on my router to my Pi

Job done!

Getting a fresh Raspberry Pi on WiFi

After downloading the latest wheezy image from the raspberry pi site and flashing it onto the SD card using Win 32 Disk Imager I transferred the card into the Pi and powered it on.  To use my approach it must have both the WiFi usb adaptor and an ethernet cable plugged in.

I then go to my router’s admin page and take a look to see what IP address has been allocated to the Pi’s ethernet link.

Then, using Putty, connect to the ssh using the credentials username: pi password: raspberry (all lowercase).

Once on, the following command were run:

Then navigate down (using the arrow keys) to my home network, then use the right arrow key to go and configure it.  The only thing I put in the configuration was the setting to “Automatically connect” and the key to the network – then pressed F10 to save the config, the Q to quit.

Having done all that I shutdown the pi, unplug the ethernet cable and power it back on.

Back in my router’s admin page I can find out the new IP address of the Pi (and reserve it for future if I want).

Job done!

 

Handling exceptions for a whole application

In one of my C# Windows Forms Applications I had a problem whereby a third-party component was throwing an exception in another thread. The exception wasn’t causing any problems but it wasn’t being handled by anything.
Basically I wanted to catch the exception, log it for reference and possible future investigation, and then ignore it and carry on.

I started by adding event handlers to the exception events:

And then I added log4net to simply log the error and move on (added via NuGet Package Manager)

So my app.config had the following added:

And my main Program.cs ended up looking like this:

Job done!

Update SharePoint locale of all sites using Powershell

So I needed to ensure that all sites in my farm were formatting dates in the British format …
Powershell, once again, to the rescue! This is what I ended up with …

 

Output SharePoint group memberships with PowerShell

So I had a need to get a csv that could tell me who was in which groups in which sites.
Powershell to the rescue! This is what I ended up with …
There may be a better way to do this but the main thing is that it works and it was quick!

 

Saving electronics

Quite often things break – sometimes I’m able to fix them.

The way I see it is that if it’s broken and is going in the bin then I’ve got nothing to lose by taking it apart and trying to see if it can be fixed.

Most recently I had the external thermometer of a wireless weather station stop working.  I was pretty sure some water had got into it so I dried it in the airing cupboard but it still wasn’t responsive.  With nothing to lose I took it apart, saw that there was a fair amount of corrosion on the circuit board and almost gave up.  Just on the off-chance that the components were still ok and the corrosion was causing a short I got an old toothbrush and cleaned it up.

Thermometer Board

Miraculously this worked and I’ve saved £35 on a replacement.  Result!

To set up a git repository on a server

So because it’s on a server there is no working directory required – as a result we do a bare initialise in the folder that we want the repo to be in:

After that, to allow pushes to the server over http we need to run the following:

This will then work nicely with a virtual host in apache:

Also, make sure the user running apache has write permissions to the git repository folders.

Authentication

To add some basic authentication I have used the following 2 techniques:

To make an entire repository private:

To make all repositories public for read and private for write:

 Web UI

Finally, I have used gitlist to provide a web ui to my repositories – to achieve this I used the standard approach documented here

My final config looks like this: