After testing most of the components that came as part of the kit, and doing some re-planing of which components to use as part of Hub, and which ones to go with for the spokes, here is a blog post that show how to setup motion on the Pi to stream video to browser on you Computer/Tablet/Phone. The plan for the Security camera spoke, is to use a Raspberry Pi zero with the NoIR camera to stream video and detect movement.
For testing the setup I am using the Raspberry Pi B+ as you see in the picture below, as I realized after buying the Pi zero that you need a special HDMI connector to the connect to a screen and in addition you cannot use a console cable as the headers pins are not soldered to the Pi zero ..
As part of the setup you can either use a USB webcam or a Pi Camera.
<the screenshot above show video stream from a Logitech USB camera connected to the Pi . Note: at this point in time the Pi NoIR Cam is not in use>
For more info on motion refer to - http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideOneLargeDocument#What_is_Motion_63
Here are the steps/list of commands to follow to setup motion to stream video on your Raspberry Pi via a browser to your laptop.
#1 Once you downloaded the latest version of Rasbian from the Raspberry Pi website (https://www.raspberrypi.org/downloads/raspbian/ ) and burn it to the SD card (Note : the name of zip file I used at the time of writing this post -2016-05-27-raspbian-jessie.zip ), and also connect your USB webcam or Pi camera to the Pi.
#2 Now run the following commands to update Rasbian packages
sudo apt-get update
sudo apt-get upgrade
#3 Install motion using the command
sudo apt-get install motion
#4 To enable motion to start at every boot of the Pi, change the value of the start_motion_daemon from no to yes
sudo nano /etc/default/motion
#5 Now setup ownership to the target directory where the images/videos get stored using
sudo chown motion /var/lib/motion
#6 Once done, reboot your Pi using
sudo reboot
#7 Once you pi is back up and if you have a monitor connected to the HDMI port ,go to the web browser and type the following url you should see a preview of your camera
http://127.0.0.1:8081
Note: if you try the url http://ipaddressofPi:8081 on a browser on you laptop , you will just get "page not displayed", we will resolve this in the next step by modifying the
motion.conf file
#8 But if you are running you Pi headless, dont worry we will modify the motion.conf file to turn off the following two parameter -- webcontrol_localhost and stream_localhost
sudo nano /etc/motion/motion.conf
#9 In addition also modify the width and height in the motion.conf
width 640
height 480
Video stream before changing the width and height
#10 Once you made the changes to the .conf file stop and start motion using
sudo service motion stop
sudo service motion start
Here is the video stream after changing width 640 and height 480 and starting motion
Note: if you are using the Pi cam instead of the USB Camera you will have to enable the Pi Cam driver with the commands in step below for the video steam to work.
In addition there are lot of other parameter that you can modify, and experiment with as part of the motion.conf file, like changing the framerate from 2 to 4, if you think the rendering of the video is slow, this is idea if you are using a Raspberry Pi 3 , but I would not suggest this parameter on a Pi zero or B+
#11 Set for the Pi Cam - enable the Pi Cam driver
Now if you plan on using Pi camera , and if you have not enable the drivers , using the command below , you will see the following error in your browser "UNABLE TO OPEN VIDEO DEVICE",
to resolve this stop the motion service and activate the Pi cam driver
sudo service motion stop
sudo modprobe bcm2835-v4l2
sudo service motion start
you should now see the video stream as shown in the screenshot below, in my case i am using Pi NoIR camera V2
now to step the driver for every boot modify the rc.local file as shown the screenshot below
sudo nano /etc/rc.local
add the following line just above exit="0"
modprobe bcm2835-v4l2
once done you can reboot your pi to test it out using
sudo reboot
Here is a screenshot with the Pi NoIR camera streaming video to my computer, late in the evening with a table lamp on top of the camera.
As part of this week, I am going to test out how this setup behaves with the Pi zero and if all is well ,design a 3D printed case to house the Pi Zero and Pi Cam..
Top Comments