Thursday, 17 October 2013

Raspberry Pi Stream Webcam to Apache Server

Raspberry Pi Stream Webcam to Apache Server

To Stream Webcam to an Apache Server on the Raspberry Pi you need to have already:
  • Installed Apache – See this post.
  • Installed the Camera Module – See this post.
After you have done this you are ready to start.
First Step – Install FFmpeg
You should download, compile and install FFmpeg, a cross platform solution for streaming and recording including the codec you will need.
Remove any existing installation:
apt-get remove ffmpeg
Get the git installation link from the FFmpeg git page here.
I have included the link in the following commands:
git clone git://
Once this has completed, move into the directory and compile the source.
cd ffmpeg
make install
This can (and probably will) take hours on the Raspberry Pi so I recommend you put this in a script and run it over night or go watch a film.
Step 2 – Install crtmpserver
This can be done with apt-get.
apt-get install crtmpserver
but you will need to do some configuration, edit the following file:
Add/change the following setings:
And finally restart the service:
service crtmpserver restart
Final Step – Web setup
Install jwplayer on your web server. You can get this at:, once you have downloaded it, extract the files in:
Create an example webpage to display your webcam stream:
    <title>Raspberry Pi Webcam Streaming</title>
    <div id="video-jwplayer_wrapper" style="position: relative; display: block; width: 960px; height: 540px;">
      <object type="application/x-shockwave-flash" data="/jwplayer/jwplayer.flash.swf" width="100%" height="100%" bgcolor="#000000" id="video-jwplayer" name="video-jwplayer" tabindex="0">
        <param name="allowfullscreen" value="true">
        <param name="allowscriptaccess" value="always">
        <param name="seamlesstabbing" value="true">
        <param name="wmode" value="opaque">
      <div id="video-jwplayer_aspect" style="display: none;"></div>
      <div id="video-jwplayer_jwpsrv" style="position: absolute; top: 0px; z-index: 10;"></div>

    <script src="/jwplayer/jwplayer.js"></script>

    <script type="text/javascript">
      , file:"rtmp://" + window.location.hostname + "/flvplayback/flv:myStream.flv"
      , autoStart: true
      , rtmp:{
      , deliveryType: "streaming"
      , width: 960
      , height: 540
      , player: {
        modes: {
          linear: {
                , enabled: false
      , shows: {
        streamTimer: {
          enabled: true
          , tickRate: 100
Now check it works! Make sure you connect to it locally and not remotely. (192.168.* address).
To start the stream run the following command:
raspivid -t 0 -w 960 -h 540 -fps 25 -b 500000 -vf -o - | ffmpeg -i - -vcodec copy -an -f flv -metadata streamName=myStream tcp://
You should see a video stream similar to the image below:
Raspberry Pi Webcam Streaming
Raspberry Pi Webcam Streaming
(Yes, the webcam is pointed at the wall).
If you want to make this webcam stream accessible remotely, you need to port forward port 1935 to the raspberry pi.
Voila, now you can Stream Webcam to Apache Server on the Raspberry Pi.

Plus i am using it and it works wonders

Monday, 7 October 2013

How to install SSH for PHP5

from time to time you may need to do SSH commands to other pi's.

you can achieve this via php :)

1) Install SSH for PHP - sudo apt-get install libssh2-1-dev libssh2-php

2)Check that is installed: php -m |grep ssh2

3: Restart apache: sudo service apache2 restart

Now for the PHP part

$connection = ssh2_connect('', 22);
ssh2_auth_password($connection, 'username', 'password');

$stream = ssh2_exec($connection, '/usr/local/bin/php -i');

Kiosk Mode

Boot up to Webpage

1. Install chromium, x11-xserver-utils and unclutter

sudo apt-get update && apt-get upgrade -y
sudo apt-get install chromium x11-xserver-utils unclutter

2. We need to prevent screen from going blank and disable screen saver.
- edit /etc/xdg/lxsession/LXDE/autostart and comment # screen saver line and add those lines:

@xset s off
@xset -dpms
@xset s noblank
@chromium --kiosk --incognito http://some.web.

Stop Raspberry Pi Going to sleep

I used simple steps and it perfectly worked for me:
  1. Open a root terminal in raspberry Pi. Now you need to edit your script that's starting X. In the default build with lightdm.
  2. Open "lightdm.conf" file located in,
  3. Add below line in to SeatDefault section.
    xserver-command=X -s 0 -dpms
  4. Restart your Raspberry Pi.
Now issue should be solved.

Friday, 4 October 2013

Raspberrypi DNS Server


Through the magic of Debian, installing dnsmasq is as simple as:
sudo apt-get install dnsmasq


For my setup, dnsmasq configuration happens in the following files: * /etc/dnsmasq.conf - dnsmasq specific configuration * /etc/resolv.conf - DNS to forward to (and the one used by the server running dnsmasq) * /etc/hosts - host names for static IPs * /etc/ethers - manually assigned IPs specified as MAC to IP mappings (optional)


This configures how the DNS server and the DHCP provider (if enabled) should behave. I'll discuss the main options I used, but the example configuration file provided with the install has good documentation.
Some domain lookups are essentially guaranteed to come up empty on the wider Internet. You can disable forwarding of them with the following lines:
# won't forward unqualified names (e.g. myserver)

# won't forward some non-routed addresses

# won't forward requests for your intranet subdomain
That last one is key. It forces that subdomain to be resolved only via internal config: the hosts file or DHCP clients.
To specify the root subdomain for your intranet, use the following two options:
# append the domain (below) to all hosts in the hosts file

# appended to DHCP hosts and, if above option specified, to hosts from static IPs
If you want to use the /etc/ethers file (see section farther down) add this option:
The rest is DHCP config. I copied it from my router's dnsmasq config, so I don't know much about all of the options.
NOTE: If you do enable DNS via dnsmasq, you should shut off the DHCP on your router. After an IP refresh, your DHCP clients should all work fine.


In my network, this points to my router. I would expect that is the normal setup, but your mileage may vary. The file's only contents are the IP of the DNS server to point to.


You'll want to leave the existing contents, but add the host names for any of your devices using static IPs. You do not need every device listed in here, just the ones you want to be addressable via a domain name.
Format is <IP> <host name>, and the host name should only be the lowest level qualifier of the host (not the full domain name). For example, if you want a device to be, only specify mydevice. mynas webserver


This is only needed if you have a few devices you want to assign static IPs to, but can't or don't want to configure the static IP on the devices themselves.
This is simply a <MAC> <IP> formatted file, with one mapping per line, for example:

final thoughts

As neat as it is, the benefits of domain names internally are pretty minimal. I already had the handful of static IPs I use memorized, but it will be nice to have a friendlier name to use. I do like having domains for the DHCP clients, however, since it removes the need to look up the IP beforehand.

Raspberrypi auto connect to wifi on boot up

Setting up a WiFi connection on the RaspberryPi

I’ve recently tried to setup a WiFi connection with the RaspberryPi and encountered some issues: the connection didn’t start automatically and it wasn’t stable. I’m using an Edimax EW-7811Un USB dongle, which is supposed to be supported out of the box with Raspian Wheezy (2012-12-16).
After researching the issue, I finally have a configuration that works reliably. Here are the steps I’ve followed.

Setting up the configuration

Edit the /etc/network/interfaces file to look like this:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

#auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Then add your WiFi parameters to /etc/wpa_supplicant/wpa_supplicant.conf.
Here are my parameters to connect to my freebox (French ISP router).
At this point, the you should be able to start the connection with this command:
sudo ifup wlan0
In some cases, you might need to do sudo ifup wlan0 first.

Connect automatically when booting

To make the connection work when the RaspberryPi boots, I have added a few lines to /etc/rc.local (source) :
echo "Starting WiFi..."
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
sleep .5s
dhclient wlan0
echo "WiFi should be started"

exit 0

Keep the connection alive

To make sure that the connection stays up, I’ve done two things.
First, disable the power management of the WiFi dongle. Create a new /etc/modprobe.d/8192cu.conf file with this content (source):
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
Then, make the RaspberryPi ping the router every minute. Open your crontab:
$ crontab -e
and add this line at the end :
*/1 * * * * ping -c 1
Replace the IP address by the actual IP address of your router.
It took me some time to get it right, but now the Pi connection seems to work fine.



Donate Towards More Raspberry PI's for Projects