Arduino, Geeky, HACMan, K9, Maker, Projects, R-Pi, ROV November 9, 2014 Skippy 6 comments

Getting Node and Motion Jpeg onto a R-Pi


As part of my R-Pi K-9 I want to have a web browser interface, (also because I want to build an ROV) I don’t have a beaglebone black.

Using a web browser as my interface will allow me to use my recently acquired iPad to control it, I want to have real time video and the controls on screen at the same time, for the video I want to use motion jpeg, and I have been told that web sockets are what I want to use for the interfacing with hardware for the K-9.

So far I have the following set up on my R-Pi:

  1. Virgin raspbian wheezy install
    sudo raspi-config
    • enable camera
    • expand file system
    • update tool
    sudo shutdown -r now
  2. Change hostname to something nice:
    sudo nano /etc/hostname
    sudo nano /etc/hosts

    Mine are both k9 now

  3. Install Prerequisites
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install g++ curl pkg-config libv4l-dev libjpeg-dev build-essential libssl-dev cmake git-core build-essential libjpeg8-dev imagemagick subversion
    sudo apt-get autoremove
    sudo shutdown -r now
  4. Install motion jpeg
    cd /usr/src
    sudo mkdir mjpg-streamer
    sudo chown pi:users mjpg-streamer
    cd mjpg-streamer
    git clone // .
    cd mjpg-streamer-experimental
  5. Shutdown the pi and attach the camera
    cd /usr/src/mjpg-streamer/mjpg-streamer-experimental/
    export LD_LIBRARY_PATH=.
    ./mjpg_streamer -o " -w ./www" -i " -x 640 -y 480 -fps 20 -ex night"

    my pi is attached to so you can see the camera at

  6. Install Node.js
    sudo su -
    cd /opt
    tar xvzf node-v0.10.28-linux-arm-pi.tar.gz
    ln -s node-v0.10.28-linux-arm-pi node
    chmod a+rw /opt/node/lib/node_modules
    chmod a+rw /opt/node/bin
    echo 'PATH=$PATH:/opt/node/bin' > /etc/profile.d/
    shutdown -r now

    When it comes back up check the version of node and npm

    node --version
    npm --version

    Should be 0.10.28 and 1.4.9

    One final step is to install node-gyp. This is not strictly necessary in every case, but you will find it useful if you ever need to build and install any “native” npm modules.

    npm install -g node-gyp

Testing Node.JS

In the home folder I have a sub folder called ‘~/node/www’ and crated a file called ‘example.js’:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
console.log('Server running at');

In ~/node there is a file called (chmod +x


# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"


node www/example.js

Visiting will now return a page with ‘Hello World’ on it

Testing Motion Jpeg

In the home folder I have a sub folder called ‘~/camera/www’ and crated a file called ‘index.html’:

<title>Skippy's K-9 thing</title>
background-image: url("/?action=stream");
background-repeat: no-repeat;
background-size: 100%;
background-attachment: fixed;
<h1>It works!</h1>

In ~/camera there is a file called


# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"


# Start Motion JPEG

cd /usr/src/mjpg-streamer/mjpg-streamer-experimental/
./mjpg_streamer -o " -w /home/pi/camera/www -p 8081" -i " -x 640 -y 480 -fps 20 -ex night"

Visiting will now return a page with ‘It Works!’ on it, and hopeful what ever the camera can see as the background.

6 thoughts on “Getting Node and Motion Jpeg onto a R-Pi

  1. Hello Philip,

    I read your Getting Node and Motion Jpeg onto a R-Pi with great interest.

    I see that you can observe your motion jpeg over your local internet connection. This would be very suitable for one of my own projects.

    I also like to connect the motion into OpenCV in an attempt to avoid obstacles and route planning. Perhaps also a 360°C laser scanner. Costly but I think effective. The OpenCV would run on an old laptop or a barebone Win PC.

    I want to use the RPi as primary control and com device perhaps connecting to the Arduino for hard control, so I am looking for a stabil chassis with 4WD/2WD with encoders. If you know of any please let me know – my mechanics are not too good.

    I am very interested in Robots and have want to move on to an autonomous robot construction and this prompts me to ask you about the K-9 robot. Can you tell me something about it

    Thank you for any help or tips you can give me


    1. K-9 is a robot from the Doctor who universe, K-9 hasn’t been seen in a while, I will write an article in a bit that details more about the background.

      The robot is not going to be autonomous (well not at the moment). It is more designed for taking to ComicCons, Maker Fairs and other places where there will be people. so completely remote control.

      Another project I am working on using a beagle board black is an ROV (using open ROV). the Beagle Board black is a much more powerful device, however the K-9 will not require all the power provided by the Pi.

  2. Goodmorning,
    I found you in a Raspberry Pi group in Linkedin.

    I have developed two systems on the raspberry pi:
    – a wifi hotspot with landing page.
    – a systemen that displays pictures, movies and text on a monitor.

    Have a look here:

    Can you tell me something more about your project? what is it you are working on?


    Henk Timmermans

  3. Nice post, I’ve been doing the same/simular Node.JS + UV4L MJpeg to create a network video streaming monitoring system with a live webpage interface.

    UV4L’s method only allows one client to view the video at anyone time, does yours allow multiple viewers?

Leave a Reply