Table of Contents

"Streaming Motion Pictures” : Project 1

Pi Army Group

Felipe Moya Coto B24609
Luis Diego Soto Ugalde B26613
Dannier Castro León B21594

Introduction

The name of this proyect is “Streaming Motion Pictures”, we'll call it SMPI for short. A Raspberry Pi we'll be used to stream videos through the Internet in real time. This process is known as streaming. SMPI will be developed on its entirety using open platforms. We will use Raspbian, which is an OS designed specifically for the Raspberry Pi that's based on Linux's Debian Wheezy distribution. A web server will be used to stream the video. We will use motion to stream the video. Openvpn shall be used to create a Virtual Private Network. Some basic knowledge of HTML will be used to create a aesthetically appealing web page where the video will be displayed. Finally, some knowledge in computer networks will be used. SMPI has the potential of being applied in a diversity of situations. Options such as streaming conferences or video surveillance will be considered.

To see the initial work proposal, enter following link: SMPI Proposal (Spanish)

Objectives

General Objective

Specific Objectives

Top - Projects

Implementation

Once you've got your Raspberry Pi, a SD card, a proper power source and Internet connection from a wired network, you should follow the instructions in this PDF Document to download and setup Raspbian (The most reliable Pi OS). During the initial configuration process you can change the password for the “pi” user, among other options.

After Raspbian is installed, begins to install the following packages using the command sudo apt-get install, and follow the instructions in each:

MOTION

Before to install Motion, you should verify that your webcam is compatible with Raspberry Pi. To do it, you can enter this page Verified Peripherals : USB Webcams. To just check if your webcam works, you can use packages like Camorama.

Motion is a program that monitors the video signal from one or more cameras and detects if a significant part of the picture has changed. In this part of the tutorial we'll get Motion working and we'll activate the motion daemon so that motion starts every time the Pi is turned on.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get motion
$ sudo nano /etc/motion/motion.conf

First ,we need to set motion's daemon to on.

daemon on
webcam_localhost off
width 352
height 288
webcam_port 8081
control_port 8080

Don't forget to save the changes you've made to motion's configuration file.

$ cd /etc/default
$ sudo nano motion
start_motion_daemon=yes
$ sudo service motion start

If you want to check everything is working fine, get the Pi's IP with command sudo ifconfig, then open Iceweasel and go to Pi's IP: 8081 and you should get your video stream.

APACHE

Now we will create a web page to display our video stream using this package called Apache.

$ sudo apt-get apache2
$ sudo /etc/init.d/apache2 start 
$ cd /var/www
$ sudo nano index.html 
<img src= “Pi's IP:8081” align= “middle” />

WI-FI

In this part of the tutorial we'll connect the Pi to a wireless network. We will focus on setting up our adapter and editing some configuration files. For our project's presentation we used a wired network due to the instability of the EIE's network.

We used a TP-Link WN821N Wireless Stick. We need to get it's driver:

$ wget 'http://wireless.kernel.org/en/users/Drivers/carl9170/fw1.9.6?action=AttachFile&do=get&target=carl9170-1.fw' -O carl9170-1.fw

Now we will create a directory to move the driver to. Please do this as root:

$ sudo mkdir /usr/local/lib/firmware
$ sudo mv carl9170-1.fw /usr/local/lib/firmware

Run sudo ifconfig you should see a new interface “wlan”. To scan wireless networks:

$ sudo iwlist scan

To configure other Wireless Stick to connect it with wireless networks automatically, follow the next steps:

auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface home inet dhcp
iface work inet dhcp
iface default inet dhcp
network={
        ssid="Your network's ssid "
        scan_ssid=1
        psk="a passkey"
        id_str="An id for your network"
        priority=5

network={
        ssid="Another network's ssid"
        scan_ssid=1
        psk="a passkey"
        id_str="another id"
        priority=5

network={
   key_mgmt=NONE
}

OpenVPN

Now we will configure a VPN using OpenVPN. This tutorial intends to explain the OpenVPN's main features in a brief way, so people who are not used to work with this kind of software will understand its way of functioning. It also includes an installation tutorial which will guide the user through the basic steps in order to run an OpenVPN server and client on Debian. In this case, the OpenVPN server will be installed on a PC, while the OpenVPN client will be installed on the Raspberry Pi.

As its name states, OpenVPN is a source open application which creates a virtual private network, which is the extension of a private network over the Internet. It could be considered as a WAN (wide area network) link between the clients and the network that is private. How does OpenVPN manages to keep this connection private? It does it via OpenSSL, which provides a secure connection using certificates and authentication protocols, which allows OpenSSL to build and exchange keys for both server and client. It also uses the Diffie-Hellman algorithm for data encryption as well as the SSL tunnels for greater security. This means that if a remote computer (i.e an employee who wishes to establish a connection to his company network) needs to connect to a private network (which has an OpenVPN server), it will only need to have an OpenVPN client installed. All of these features make OpenVPN an ideal software for private streaming services and more.

Installation guide for OpenVPN

We'll split this guide into two parts, one for the OpenVPN server installation and the other for the OpenVPN client installation on the Raspberry Pi.

  1. Setting up the OpenVPN server
$ apt-get install openvpn libopensc2
$ mkdir /etc/openvpn/easy-rsa
$ cp -ai /usr/share/doc/openvpn/examples/easy-rsa/2.0/ /etc/openvpn/easy-rsa
$ cd /etc/openvpn/easy-rsa/2.0
$ nano vars
$ source ./vars
$ ./clean-all
$ ./build-ca
$ ./build-key-server <yourservername>
$ ./build-key <yourclientname>
$ ./build-dh
$ cd /etc/openvpn
$ cp easy-rsa/2.0/keys/ca.crt  .
$ cp easy-rsa/2.0/keys/server.key .
$ cp easy-rsa/2.0/keys/server.crt .
$ cp easy-rsa/2.0/keys/dh1024.pem .
$ cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf .
port 1194
proto udp
dev tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 202.107.105.13"
push "dhcp-option DNS 202.108.107.21"
keepalive 10 120
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
$ /etc/init.d/openvpn start
$ cd /etc
$ nano sysctl.conf
$ net.ipv4.ip_forward = 1

This should be enough to make your OpenVPN server run.

  1. Setting up the OpenVPN client on the Raspberry Pi
$ apt-get install openvpn
$ cd /etc/openvpn
$ cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf .
$ nano client.conf
client
dev tun
proto udp
remote <enteryourserverip> 1194
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
mute-replay-warnings
ca /etc/openvpn/ca.crt
cert /etc/openvpn/client_kevin.crt
key /etc/openvpn/client_kevin.key
ns-cert-type server
comp-lzo
verb 3
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
$ openvpn --script-security 2 --config /etc/openvpn/client.conf &
$ ping 10.8.0.6

The output of this shows if the raspberry pi is pinging the server.

Top - Projects

Results



This picture shows the correctly assembly of all devices: Rasberry Pi, Microsoft Web Cam USB, proper power source of 5.0V == 850mA Output.


Among problems that can occur, is a bad configuration of Motion, and it caused that the Streamer didn't work. We had this problem, the web cam resolution was incorrect, and found the solution in this YouTube Video and set the stream's resolution to 352×288.



To improve the design of Streamer Web Page you can insert a code in the Apache's archive /var/www/index.html, this code allows you to change and incorporate grafical characters in the Web Page. In this project we use the following code and we had the next result:



 <html><head></head><body bgcolor="CCFFCC"><h1 align="center">SMPI-IE0117</h1>
 <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQipMUqnHv3hkETEFqERzyThMGxd9qPHO8dj2TJP19Db4tB8yx" align="right">
 <p align="center" x="">Video-Streamer</p>
 <p align="center"><img src="http://192.168.12.195:8081" align="middle"></p>
 </body></html>



Finally, the OpenVPN works correctly in a home network, but has problems of certificates in the EIE's internal network. We could not solve it. Then here are the pictures that show the proper functioning of the Video Streamer as client through a server:


  1. $ sudo ifconfig from Raspberry Pi (client)
  2. $ sudo ifconfig from Server




The next video shows the final result, the project totally complete, a Video Streamer works perfectly:

Top - Projects

Conclusions

Top - Projects


http://www.palebluedot.nl/jml/computer-stuff/3-linux/33-webcam-streaming-with-raspberry-pi.html
http://wolfpaulus.com/jounal/embedded/raspberrypi_webcam
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=9465&p=111445
http://ramalave.blogspot.com/2012/11/instalar-tp-link-wn821n-en-debian-wheezy.html
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=11517
http://scottlinux.com/2010/06/29/stream-webcam-with-vlc/
http://docs.openvpn.net/how-to-tutorialsguides/virtual-platforms/install-openvpn-access-server-on-linux-debian-6/
http://sanjosetech.blogspot.com/2013/03/web-cam-streaming-from-raspberry-pi-to.html