
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:
- Virgin raspbian wheezy install
sudo raspi-config
- enable camera
- expand file system
- update tool
sudo shutdown -r now
- Change hostname to something nice:
sudo nano /etc/hostname sudo nano /etc/hosts
Mine are both k9 now
- 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
- 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
- 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
- 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.
6 thoughts on “Getting Node and Motion Jpeg onto a R-Pi”
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
Nigel
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.
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: http://www.kurkshop.nl
Can you tell me something more about your project? what is it you are working on?
Regards
Henk Timmermans
Afternoon Henk,
I have seen your wifi hotspot and display ideas on the channel. have you looked at “MyLittlePwny” – http://www.instructables.com/id/MyLittlePwny-Make-a-self-powered-pentesting-box-/
It might be a little more black hat than your idea. I may get tempted to make one or something smiler at some point. (Dr Who ‘wifi’).
Nice post, I’ve been doing the same/simular Node.JS + UV4L MJpeg +Socket.io 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?
Multiple clients per server however lag becomes a bit of an issue. As the pi is not really designed for throughput