Raspberry PI, Logitech c920 and WebRTC videocall: #fail

I had the idea to create a no-brain and enjoyable setup for my parents to videocall with me. I know I can use Skype, Hangouts or lot of similar apps on any PC / tablet, but for me no-brain and enjoyable means sit down on the living room couch, press a key somewhere, look at the big TV screen and start talking with me.

There are solutions like Chromebox for Meetings (hardware here and here) or the GT Mini 3330, but the price is too high for a whim like mine. After different iterations, I’ve figured out a solution, although final result is still not working for some reason. This post describes what I’ve done so far.

General architecture

TL;DR: A RasPI 2B connected to the TV, Logitech c920 webcam, WebRTC video call in a fullscreen Chromium tab.

An easy way to do bidirectional video call, nowadays, is to use dedicated apps like the before mentioned Skype, Hangouts, Ekiga or many others. But you often need a PC connected to the TV, you cannot automate the connection process, plus most solutions are using proprietary protocols. The alternative is to rely on the promises of WebRTC project and create a multi-party video chat. Nothing more than a browser and a camera is needed. Sounds good!

A Raspberry PI 2B model is powerful and cheap enough for running such setup and, connected to a TV screen via HDMI port, can use the TV for video and audio output.

As for the camera, I went for a Logitech c920. Why? Because it’s supported out of the box on Raspbian, works with fswebcam and it doesn’t need a powered USB hub, has a wide-angle lens very good for video calls, has a good directional microphone and can produce an hardware encoded FullHD H.264 video stream (it can be checked with v4l2-ctl –list-formats), with no additional computational overload on the RPi side. And it costs around 80 euros. Video quality is excellent and audio recored is loud and clean even if the speaker is 3 meters far from the camera: huge enough to cover the average distance between a couch and a TV :)
It may happen to see a rainbow square top right on the display while using the camera: it’s the under-voltage warning of the RPi, so connect it to a more powerful USB port, to an external USB power source or, as last resource, connect the camera to a powered USB hub.

Regarding the software, nothing more than a WebRTC-compatible browser, running on RPi, is required: IceWeasel and Chromium have it. To host the WebRTC call, there are plenty of solutions: AppRTC, Jitsi, OpenTokRTC, just to mention few, are online services that can be used to start a WebRTC video call. Source code is even available for OpenTok and AppRTC, to create a personal server.
Once selected the service, a script can open a fullscreen browser window pointing to the desired chat room url, once the RPi graphic environment starts, so the only action required is to power-up the Raspberry and wait to be connected. Bingo :)

Step-by-step config

Basic system
Downloaded NOOBS offline, formatted the SD card as one FAT32 partition using GParted,  and unzipped the NOOBS archive on SD card. Inserted the SD on the RPi and booted. Selected Raspbian Jessie, waited for the installation to finish. Alternative instruction for Linux here.

Run the usual sudo apt-get update, sudo apt dist-upgrade, sudo rpi-update commands triad

Browser
Regarding the browser to use… Well, it’s complicate.
As first try, I followed this guide that suggested to use Iceweasel. It was as simple as a sudo apt-get install iceweasel, but unfortunately vLine is not active anymore, with appRTC IceWeasel crashes and Jitsi.org doesn’t support Iceweasel < 40 (Jessie has v38 on the repo).
So I installed Chromium following this guide, using the precompiled armhf packages from Ubuntu Ports. But also this guide works, using packages in the Launchpad Librarian.

Why Chromium v45? Because v47 has a annoying bug that prevent a correct render of YouTube, appRTC and Jitsi, among the other.

Time to start my first WebRTC video call: I opened a Jitsi link to launch a test call on RasPI and my PC, authorised the website to use my mic and camera and I had both sides connected, audio and video working as expected. Wow moment, I’m an happy man!!!!

Unfortunately, after 30 to 60 secs, audio from the RasPI side stops working, and only the video is transmitted. I can see video from the RasPI side of the call, but I cannot hear the audio. Instead, on the TV screen, it’s possible to see and hear my stream. After tons of tests, I still don’t know why this is happening and how to solve it. Also a post on Raspberry PI forum isn’t helping. This is the biggest blocker I have right now :(

Raspberry Pi, RPi Camera and Roomba: a first-person experience of the housecleaning

Raspberry and RoombaToday’s challenge

Have a first-person view of the Roomba cleaning, using a RasperryPi, a RPi Camera and some additional stuff.

 

Raspberry basic configuration

Hardware side, I used the most standard available components: a Raspberry Pi model B, the RPi Camera module and a Edimax EW-7811Un 150Mbps Wi-Fi USB card.

Regarding the OS, there are a lot of distributions available for the Raspberry Pi, but I went for a plan Raspbian: wide support, flexibility, de-facto standard. I installed it using the NOOBS setup, following detailed instruction to load NOOBS image on a sd-card under by Ubuntu pc. Then, started the RasPi, selected Raspbian from the distro installation menu, waited a little bit for the installation to complete.
In the raspi-config app, I enabled the camera and enabled SSH server. Then the usual sudo apt-get update && sudo apt-get -y dist-upgrade && sudo rpi-update && sudo reboot combo, to update everything. The RasPi is ready to rock :)

 

WiFi setup

Configure the WiFi is easy with the right card (this is an evergreen truth in Linux world). Because the Edimax is supported natively, the only thing I did was:

sudo nano /etc/network/interfaces

and added these lines at the end of file (change them for a different WiFi encryption model). Alternative steps are available too.

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "YOUR_NETWORK_SSID"
wpa-psk "YOUR_WIFI_PASSWORD"

Reboot and voilà, now the ethernet cable can be unplugged and the RasPi made another step toward movement freedom.

 

Camera software and configuration

There are different options available. Out-of-the-box, Raspian can both capture still images from camera or recording videos using raspistill and raspivid commands, respectively.

Another option is to use motion as backend to expose the camera video stream. The only problem is that stock version doesn’t (still) support RasPi camera device file, so a big thanks to dozencrows for the fixes has as done. There is a detailed forum post with the final files to replace on the RasPi, plus a couple of tutorials explaining detailed steps to have a working setup, included the sudo apt-get install libjpeg62 part.
With a working motion installation, different frontends can be used to see the camera stream, like the motion server itself, motionEye etc, and the RasPi can even be seen as a normal IP camera from lot of software, included Synology Surveillance Station.
Too lazy to do everything by hand? A complete distro, MotionPie, is an out-of-the-box solution in active development. Flashing the image on a sd-card and reboot the RaspPi is the only requirement, wifi configuration apart.

I found also another project, RaspberrIPCam, a fork of raspivid that offers a working website for accessing the camera stream, Synology Surveillance Station integration and more. Step-by-step guide here.

But, personally and because of the challenge, I chose another way: the project RPi Cam Web Interface.

 

RPi Cam Web Interface

This solution works in a pretty clever way: instead of using motion infrastructure, it relies on the raspimjpeg command, that is able to capture single frames from the camera stream and its configuration can be changed on the fly writing commands to a Unix pipe. Then motion is configured to point to raspimjpeg output, so it can do all its motion detection magic without a real access to the camera. And Apache serves a micro-site where camera stream is shown and some php scripts glue all together and provide additional features like an easy access to captured video files, changing camera parameters, controlling the entire RasPi from the web interface (included a restart / reboot) and much more.

To install RPi Cam Web Interface, I execute

cd
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
chmod u+x RPi_Cam_Web_Interface_Installer.sh
./RPi_Cam_Web_Interface_Installer.sh

and started the whole app (only the first time), using

./RPi_Cam_Web_Interface_Installer.sh start

The install script allows to customize the Apache directory where all the files are stored changing the rpicamdir variable value in the script itself. Doing so, it’s possible to avoid conflicts with other apps that serve additional pages and sites on the same RasPi. Additional info are available reading the bash file. Use the source, Luke!

To access the website, opening http://raspi_address/ from any browser is enough.

To disable the red light from the camera module, I run

sudo nano /boot/config.txt

and added the following line at the end of file

disable_camera_led=1

 

Roomba setup

Thank to the WiFi, the RasPi could freely connect to the network, and an USB power bank provided the necessary power for the experiment. Scotch tape to assemble everything and here the final result. Pretty cool, isn’t it?
https://www.youtube.com/watch?v=HULc997mtaE
(tinyCam Monitor is responsible for casting the camera stream on the TV, thanks to a Chromecast)

 

Notes on RPi_Cam_Web_Interface

Some salient parts of RPi_Cam_Web_Interface architecture, mainly to help my memory over time.

motion is configured to read images from local server, using netcam_url http://localhost/cam_pic.php, and this php script returns the content of /dev/shm/mjpeg/cam.jpg file, where raspimjpeg writes the camera preview thanks to the setting preview_path /dev/shm/mjpeg/cam.jpg.
When motion detects something, it executes the command on_event_start echo ‘ca 1’ > /var/www/FIFO, and the corresponding on_event_end echo ‘ca 0’ > /var/www/FIFO when the event ends. /var/www/FIFO is the Unix pipe file used to control raspimjpeg  via the control_file /var/www/FIFO option. Doing so, raspimjpeg creates the video file returned in the web page with all the captured files.
All motion web-service options and recording capabilities are switched off in the config file.

When installing, a link to the camera preview file is created under Apache site directory using the command sudo ln -sf /run/shm/mjpeg/cam.jpg /var/www/$rpicamdir/cam.jpg. In this way, http://raspberry_ip/cam.jpg returns the latest image from the camera, and Android app like tinyCam monitor can points to this address to show camera stream, image by image.

To create Python app that uses the camera, picamera interface can be used.