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://source.ffmpeg.org/ffmpeg.git
Once this has completed, move into the directory and compile the source.
cd ffmpeg
./configure
make
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:
/etc/crtmpserver/applications/flvplayback.lua
Add/change the following setings:
validateHandshake=false,
keyframeSeek=false,
seekGranularity=0.1
clientSideBuffer=30
And finally restart the service:
service crtmpserver restart
Final Step – Web setup
Install jwplayer on your web server. You can get this at: http://www.longtailvideo.com/, once you have downloaded it, extract the files in:
/var/www/jwplayer
Create an example webpage to display your webcam stream:
<html>
  <head>
    <title>Raspberry Pi Webcam Streaming</title>
  </head>
  <body>
    <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">
      </object>
      <div id="video-jwplayer_aspect" style="display: none;"></div>
      <div id="video-jwplayer_jwpsrv" style="position: absolute; top: 0px; z-index: 10;"></div>
    </div>

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

    <script type="text/javascript">
    jwplayer('video-jwplayer').setup({
      flashplayer:"/jwplayer/jwplayer.flash.swf"
      , file:"rtmp://" + window.location.hostname + "/flvplayback/flv:myStream.flv"
      , autoStart: true
      , rtmp:{
        bufferlength:0.1
      }
      , deliveryType: "streaming"
      , width: 960
      , height: 540
      , player: {
        modes: {
          linear: {
            controls:{
              stream:{
                manage:false
                , enabled: false
              }
            }
          }
        }
      }
      , shows: {
        streamTimer: {
          enabled: true
          , tickRate: 100
        }
      }
    });
    </script>
  </body>
</html>
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://0.0.0.0:6666
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

Friday, 11 October 2013

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('shell.example.com', 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.


http://lokir.wordpress.com/2012/09/16/raspberry-pi-kiosk-mode-with-chromium/

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,
    /etc/lightdm/lightdm.conf
  3. Add below line in to SeatDefault section.
    [SeatDefaults]
    xserver-command=X -s 0 -dpms
  4. Restart your Raspberry Pi.
Now issue should be solved.

Friday, 4 October 2013

Raspberrypi DNS Server

installation

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

configuration

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)

/etc/dnsmasq.conf

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)
domain-needed

# won't forward some non-routed addresses
bogus-priv

# won't forward requests for your intranet subdomain
local=/lan.mydomain.com/
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
expand-hosts

# appended to DHCP hosts and, if above option specified, to hosts from static IPs
domain=lan.mydomain.com
If you want to use the /etc/ethers file (see section farther down) add this option:
read-ethers
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.

/etc/resolv.conf

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.

/etc/hosts

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 mydevice.lan.mydomain.com, only specify mydevice.
192.168.1.301 mynas
192.168.1.302 webserver

/etc/ethers

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:
00:00:00:00:00:00 192.168.0.200
00:00:00:00:00:01 192.168.0.201

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

raspberrypi-wifi
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).
network={
        ssid="YOURSSID"
        scan_ssid=1
        key_mgmt=WPA-PSK
        proto=WPA
        psk="YOURPASSWORD"
}
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 192.168.0.254
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.

Amazon

Donate

Donate Towards More Raspberry PI's for Projects