-

Ivan Massagué

Contenido Objetivo ......................................................................................................................................... 3 Software y material necesarias para la realización del proyecto.................................................. 3 Esquema del emisor y receptor de IR ........................................................................................... 3 Instalando LIRC para enviar y recibir señales IR............................................................................ 4 El streaming de la webcam con MPJG-Streamer .......................................................................... 5 El streaming de la webcam con Motion ........................................................................................ 6 Instalando servidor web con soporte CGI de python................................................................... 7 Script CGI para la ejecución de comandos sin privilegios ............................................................. 8 Pequeño programa en C para la ejecución de comandos con privilegios .................................... 9 Pagina HTML de control .............................................................................................................. 10 Bibliografia .................................................................................................................................. 11

Objetivo El objetivo del proyecto es poder dotar al Rasperry pi de un sistema de emisión y recepción de IR y una cámara web con el fin de poder controlar una TV y un video- grabador mediante un interface web.

Software y material necesarias para la realización del proyecto •

Placa GPIO con un receptor y un emisor de IR



Programa LIRC para controlar los IR



Webcam eye toy PS3



Programa MOTION o MJPG_STREAMING para el streaming en web



Servidor web LIGHTTPD con soporte CGI de python

Esquema del emisor y receptor de IR

Instalando LIRC para enviar y recibir señales IR LIRC es un software que permite enviar y recibir señales de IR desde la consola. Damos por hecho de que se dispone de una instalación de Debian actualizada. Para instalarlo ejecutamos: sudo apt-get install lirc

Se tienen que añadir estas líneas a /etc/modules: sudo nano /etc/modules lirc_dev lirc_rpi gpio_in_pin=23 gpio_out_pin=22

Se tiene que sobrescribir el fichero /etc/lirc/hardware.conf con esta configuración para que funcione: sudo nano /etc/lirc/hardware.conf ######################################################## # /etc/lirc/hardware.conf # # Arguments which will be used when launching lircd LIRCD_ARGS="--uinput" # Don't start lircmd even if there seems to be a good config file # START_LIRCMD=false # Don't start irexec, even if a good config file seems to exist. # START_IREXEC=false # Try to load appropriate kernel modules LOAD_MODULES=true # Run "lircd --driver=help" for a list of supported drivers. DRIVER="default" # usually /dev/lirc0 is the correct setting for systems using udev DEVICE="/dev/lirc0" MODULES="lirc_rpi" # Default configuration files for your hardware if any LIRCD_CONF="" LIRCMD_CONF="" ######################################################## Ahora tenemos que añadir la configuración de nuestro mando, podemos buscar por internet en http://lirc.sourceforge.net/remotes/ tienen una recopilación de modelos de mandos. El fichero que descarguemos se tiene que copiar a /etc/lirc/lircd.conf En caso de que no estuviera la configuración de nuestro mando la podemos crear con el comando: irrecord -d /dev/lirc0 ~/lircd.conf

Este comando nos pide que pulsemos varias veces los botones del mando y al cabo de un tiempo de calibración nos pedirá que le indiquemos el nombre de los botones que queramos grabar. Podemos obtener un listado de nombres válidos con el comando: Irrecord –l Al realizar cualquier modificación del fichero de configuración tenemos que reiniciar el servicio con el comando sudo /etc/init.d/lirc stop sudo /etc/init.d/lirc start Para enviar una secuencia: irsend SEND_ONCE Sony_1 chan_up chan_up Otros comandos útiles son: irsend LIST "" "" Muestra los Mandos irsend LIST Sony_1 "" Muestra los comandos del mando Sony_1

El streaming de la webcam con MPJG-Streamer Para realizar el streaming utilizaremos MPJG-Streamer un software que realiza streaming en mjpg. Para instalar este software son necesarias estas librerías: sudo apt-get install libjpeg8-dev sudo apt-get install imagemagick Luego tenemos que descargar y compilar el programa wget http://downloads.sourceforge.net/project/mjpg-streamer/mjpgstreamer/Sourcecode/mjpg-streamer-r63.tar.gz tar xvzf mjpg-streamer.tar.gz cd mjpg-streamer/mjpg-streamer make Cuando lo ejecutemos, tendremos una web en el navegador http://ip_raspberry:8080 donde podremos ver el streaming en diferentes modos según la opción que escojamos. ./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -y" -o "./output_http.so -w ./www"

Si queremos crear un script para ejecutar el programa es el siguiente fichero /usr/sbin/webcam.sh : ##### export LD_LIBRARY_PATH="/home/pi/mjpg/mjpg-streamer/mjpgstreamer/:${LD_LIBRARY_PATH}" ##### mjpg_streamer -i "./input_uvc.so -d /dev/video0 -y" -o "./output_http.so -w ./www" #!/bin/sh ### BEGIN INIT INFO # Provides: webcam # Required-Start: $all # Required-Stop: # Default-Start: 2 # Default-Stop: # Short-Description: Start mjpg web server in background at boot time (_b). # Description: Web server port 8008, with login mask ### END INIT INFO # Structur Reference: http://wiki.debian.org/LSBInitScripts/ # 2010-12-11 RudolfReuter # check for existing webcam device if [ ! -e "/dev/video0" ]; then echo "webcam.sh: Error - NO /dev/video0 device" 2>&1 | logger exit 2 fi MSP="/home/pi/mjpg/mjpg-streamer/mjpg-streamer" cd $MSP export LD_LIBRARY_PATH="$(pwd)" # original $MSP/mjpg_streamer -i "$MSP/input_uvc.so" -o "$MSP/output_http.so -w $MSP/www -p 8008 -c jan:jan" & #$MSP/mjpg_streamer -i "$MSP/input_uvc.so" -o "$MSP/output_http.so -w $MSP/www" -b $MSP/mjpg_streamer -i "$MSP/input_uvc.so -d /dev/video0 -y" -o "$MSP/output_http.so -w $MSP/www" & # End of File

Para crear un demonio que arranque con el sistema copiamos el srcipt a /etc/init.d/webcam.sh y ejecutamos: sudo update-rc.d webcam.sh defaults Para detener el programa: kill -9 “pidof mjpg_streamer”

El streaming de la webcam con Motion Motion es un software destinado a la detección de movimiento pero que también nos puede servir para realizar el streaming con la webcam. Se necesita esta librería: sudo apt-get install ffmpeg Para instalarlo: sudo apt-get install motion

Tenemos que modificar estos parámetros en el fichero de configuración de motion sudo nano /etc/motion/motion.conf Modify the settings as below - daemon off a on - webcam_localhost off a on - width 320 - height 240 - framerate 15 Lanzar motion: sudo motion Ver el streaming en Firefox (no funciona directamente ni en chrome ni en IE ir a http://ip_raspberry:8081

Instalando servidor web con soporte CGI de python Como servidor web utilizaremos lighttpd que es muy liviano. Para instalarlo ejecutamos: apt-get install lighttpd Luego paramos el servicio y modificamos el fichero de configuración para añadir el soporte CGI. service lighttpd stop nano /etc/lighttpd/lighttpd.conf Añadimos la parte en negrita #server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", "mod_cgi", "mod_rewrite", ) Y al final del documento también añadimos $HTTP["url"] =~ "^/" { cgi.assign = (".py" => "/usr/bin/python") }

Para testear si el modulo CGI esta bien configurado podemos crear este fichero # vi /home/httpd/cgi-bin/hello.py #! /usr/bin/python # print "Content-Type: text/html\n\n" print '' print 'Raspberry Pi

' for count in range(1,100): print 'Hello World... ' print "

" En el navegador nos mostrara

Script CGI para la ejecución de comandos sin privilegios Con este script python se le puede pasar como argumento un comando y obtener el resultado en la pantalla del navegador. #!/usr/bin/python2.4 print "Content-Type: text/plain" print # The subprocess module is new in 2.4 import os, urllib, subprocess as sub # Retrieve the command from the query string # and unencode the escaped %xx chars str_command = urllib.unquote(os.environ['QUERY_STRING']) p = sub.Popen(str_command, # Change /bin/bash to the available or preferred shell executable='/bin/bash', shell=True, stdout=sub.PIPE, stderr=sub.STDOUT) std_out_err = p.stdout print '$', str_command print std_out_err.read()

Pequeño programa en C para la ejecución de comandos con privilegios Debido a que los scripts no se les puede habilitar el stick bit que permite que cualquier usuario ejecute el programa en el que está habilitado con derechos de root, he creado este pequeño programa que puede ejecutar los comandos y tener el stick Bit. De este modo podemos controlar los servicios de streaming. #include #include #include int main(int argc, char *argv[]) { if (argc >= 1) { if ( strcmp(argv[1],"ons") == 0 ) { setuid(0); system("/bin/bash /usr/sbin/webcam_on.sh"); printf("Arranca servicio mjpg-streamer \n"); } if ( strcmp(argv[1],"offs") == 0 ) { setuid(0); system("/bin/bash /usr/sbin/webcam_off.sh"); printf("Para servicio mjpg-streamer \n"); } if ( strcmp(argv[1],"onm") == 0 ) { setuid(0); system("service motion start"); printf("Arranca servicio Motion \n"); } if ( strcmp(argv[1],"offm") == 0 ) { setuid(0); system("service motion stop"); printf("Para servicio Motion\n"); } } else printf("Los argumentos son ons o offs para servicio mjpg-streamer y onm o offm para Motion\n" ); return 0; }

gcc -o ejecuta2 ejecuta2.c  Con este comando lo compilamos sudo chown root ejecuta2  Con este le asignamos como propietario el root sudo chmod ug+s ejecuta2 Con este habilitamos el stick Bit

Pagina HTML de control Por último la página HTML que nos muestra el streaming y nos permite enviar los comandos con lo scripts mostrados anteriormente. El paso de parámetros a los scripts se realiza en Ajax. MJPG-Streamer - Stream Example

Programando el VIDEO desde la Raspberry Pi



TV





Video







Bibliografia Servidor WEB + CGI My Raspberry Pi project - Initial setup of the Raspberry Pi out of the box. How to use Shell Commands for Web python Python Execute Unix / Linux Command Examples HOWTO Use Python in the web — Python v2.7.5 documentation Raspberry Pi – Controlling GPIO from the Web | Dav's bit o the web david goes raspberry pi: Phyton-CGI with lighttpd Python CGI script with lighttpd | Unit Engineering Installing Lighttpd with Python CGI support | Correr un archivo en c en un servidor Python, CGI and lighttpd Python CGI Programming setuid on shell scripts Streaming Video Streaming Live! con RaspberryPI y Playstation Eye | Geeky Theory How To : Setup a Webcam Streaming Server in Under 200 Megabytes » The Rantings and Ravings of a Madman How To : Stream A Webcam From The Raspberry Pi » The Rantings and Ravings of a Madman Raspberry Pi • View topic - Mjpg-Streamer Chris Barnes | Using a PS3 EyeToy with the Raspberry Pi and motion with chrome Chris Barnes | Using a PS3 EyeToy with the Raspberry Pi Raspberry Pi | Geeky Theory Quickie : Streaming Audio And Video From A Webcam On The Raspberry Pi » The Rantings and Ravings of a Madman Tutorial Raspberry Pi - 3. EyeToy Camera PS2 Motion system | Geeky Theory Raspberry Pi • View topic - Playstation PS3 Eye Streaming How to compile FFmpeg for Raspberry Pi (Raspbian) – FFmpeg compilar ffmpeg en raspbian con soporte h264 « AlvaroLara.com - desarrollo Web, Android, SEO, Vídeo Burgos Getting gstreamer to work on a Raspberry Pi | Stephen C Phillips webcam | Raspberry Pi en español RSPPI - RaSPberry PI: Streaming de video desde RaspberryPi (parte 1) How to build and run MJPG-Streamer on the Raspberry Pi - miguelgrinberg.com Howto Get Eyetoy Webcam working for Ubuntu - Page 15 Web Cam streaming from Raspberry Pi to Android using streamer How To : Stream A Webcam From The Raspberry Pi Part 3 » The Rantings and Ravings of a Madman Webcam Streaming Video On Raspberry Pi via Browser - OscarLiang.net Motion on Raspberry Pi Raspberry Pi • View topic - How To Install Mjpg-Streamer Faster Video Streaming on Raspberry Media Server with MJPG STREAMER

Proyecto con Raspberry pi TV_IR_WEBCAM.pdf

Sign in. Loading… Page 1. Whoops! There was a problem loading more pages. Retrying... Proyecto con Raspberry pi TV_IR_WEBCAM.pdf. Proyecto con ...

1MB Sizes 5 Downloads 233 Views

Recommend Documents

Raspberry Pi FAQs.pdf
devices to your Pi, it is advisable to always check the power rating. Batteries are not a recommended power supply for your Pi. Note: The Official Raspberry ...

Page 1 RASPBERRY PI HAT BOARD SPECIFICATION (c) Raspberry ...
MINIMUM HAT REQUIREMENTS: BOARD MUST BE 65X56nm or 65X56.5nln AS PER THIS DRAWING. BOARD MUST HAVE 3mm RADIUS CORNERS AS ...

Raspberry pi 2014-2015.pdf
Raspberry pi 2014-2015.pdf. Raspberry pi 2014-2015.pdf. Open. Extract. Open with. Sign In. Main menu. Whoops! There was a problem previewing Raspberry ...

Raspberry Pi 3 Datasheet RS.pdf
Display Connector Display Serial Interface (DSI) 15 way flat flex cable connector with two data. lanes and a clock lane. Memory Card Slot Push/pull Micro SDIO.

Raspberry Pi 3 Datasheet RS.pdf
Display Connector Display Serial Interface (DSI) 15 way flat flex cable connector with two data. lanes and a clock lane. Memory Card Slot Push/pull Micro SDIO.

raspberry-pi-v11.pdf
Page 1 of 4. 1. 1 Insert SD card. See page 3 for how to. prepare the SD card. 3 Connect input. Plug in a USB keyboard. and mouse. 2a Connect display.

[PDF] Raspberry Pi with Java
Online PDF Raspberry Pi with Java: Programming the Internet of Things (IoT) (Oracle Press) (Programming Web Development - OMG), Read PDF Raspberry Pi ...

Raspberry Pi for the .NET Developer - GitHub
Mar 19, 2015 - Page 10 ... Once you have an IP address, open your web browser and go to some website to test out your ... To connect to your Pi, enter a Remote Host of your IP address .... The program that I like the best is WinSCP. Go to.

The Raspberry Pi Crash Course.pdf
Page 1. Whoops! There was a problem loading more pages. Retrying... The Raspberry Pi Crash Course.pdf. The Raspberry Pi Crash Course.pdf. Open. Extract.

raspberry-pi-v21.pdf
4. Composite NTSC mode. Whoops! There was a problem loading this page. Retrying... raspberry-pi-v21.pdf. raspberry-pi-v21.pdf. Open. Extract. Open with.

Raspberry-Pi VGA Fen Logic Ltd.
Sep 8, 2014 - This document and the related databases are free: you can ... public domain at Github: https://github.com/fenlogic/vga666 . ... documents/vga_manual.pdf ... used 100 Ohm resistors, you might even have to go down to 80 ohms ...

Video Conference System Using Raspberry Pi - IJRIT
the early 1970s as part of AT&T's development of Picture phone technology. With the ... (such as phone and Internet), by reducing the need to travel, which is often carried out by aero plane, to .... There is no arrangement for audio input in Raspber