K-9

K-9

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 //github.com/jacksonliam/mjpg-streamer.git .
    cd mjpg-streamer-experimental
    make
  5. Shutdown the pi and attach the camera
    cd /usr/src/mjpg-streamer/mjpg-streamer-experimental/
    export LD_LIBRARY_PATH=.
    ./mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so -x 640 -y 480 -fps 20 -ex night"

    my pi is attached to 192.168.2.7 so you can see the camera at http://192.168.2.7:8080/stream.html

  6. Install Node.js
    sudo su -
    cd /opt
    wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz
    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/node.sh
    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');
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');

In ~/node there is a file called Node.sh (chmod +x Node.sh):

#!/bin/bash
clear

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

echo

node www/example.js

Visiting 192.168.2.7:8080 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’:

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

In ~/camera there is a file called Camera.sh:

#!/bin/bash
clear

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

echo

# Start Motion JPEG

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

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