How to use Motion Linux 4.2.2-1 to create a CCTV system on Ubuntu 18.10 , 64 bit with a Web Cam and Hikvision IP Cam

The CCTV system that is explained here is based on 2 cheap cameras.

One normal USB web Camera and a Hikvision Q1 network PT camera (wifi)

IMG_20190615_162612

Figure:-1

The Motion Linux available in the Ubuntu software center is not the latest. Therefore it is advisable to get the software from the Motion website .

First install Motion Linux latest release  using the GDebi  Package Installer.

The Motion release compatible with Ubuntu 18.10 , 64 bit is

cosmic_motion_4.2.2-1_amd64.deb

Now if you see the folder motion is being created at /etc/motion/. You can see 5 files in this folder as i the following figure

Screenshot from 2018-02-02 18-28-44

 Figure:- 2

Editing motion.conf file to suit our cameras

 

The main file is “motion.conf”. Other files give sample script files for different cameras.

If you open the motion.conf using a text editor like gedit , you can see the commands related  to  linking cameras .Please see the following figure for the details.

Screenshot from 2019-06-15 16-12-42

Figure:- 3

You will have to delete semicolon ” ; ” placed at the beginning of the commands in order to activate the corresponding camera

Here ,I have used camera1.conf as the configuration file for the Hikvision camera

and camera4.conf as the configuration file for the web cam

The above configuration files have been prepared using the guide scripts in camera1-dist.conf and camera4-dist.conf files available in /etc/motion/

On the Ubuntu terminal

sudo gedit /etc/motion/motion.conf

Then the motion.conf file is opened

Then delete semicolon ” ; ” in front of

camera /etc/motion/camera1.conf  ( line no 163)

camera /etc/motion/camera4.conf

Then save the file motion.conf

Since we are using a separate configuration  file ( camera4.conf) for the web cam we don’t need some commands in main “motion.conf” file as those commands are included in camera4.conf .Therefore we introduce semicolon “;” in front of those commands ( for videodevice at line no 34 and stream_port at line no 155 )as follows in the motion.conf file as shown in the following figures

Screenshot from 2019-06-15 16-13-46

Figure:-4

Screenshot from 2019-06-15 16-13-08

Figure:-5

Creating configuration files for cameras

For the web camera

On the Ubuntu terminal

sudo gedit /etc/motion/camera4.conf

Then a blank text file is opened

enter the scripts shown in the following figure and save

target_dir at line no 29 has to be selected in your computer to store motion detection video events .

Screenshot from 2019-06-15 17-11-38

Figure:-6

 

For the Hikvision camera

sudo gedit /etc/motion/camera4.conf

 

On the Ubuntu terminal

sudo gedit /etc/motion/camera4.conf

Then a blank text file is opened

enter the scripts shown in the following figure and save

Screenshot from 2019-06-15 17-12-08

Figure:-7

The netcam_url at line no 15 should be as follows for the Hikvision Q1 Network PT camera

rtsp://username:password@ip address:554/Streaming/Channels/102?transportmode=mcast&profile=Profile_2

Now all the configuration files for cameras are ready

Initiation of Motion

On the Ubuntu terminal

sudo /usr/bin/motion

Then open the web browser and enter the url

http://localhost:8080/

You can see all the cameras are working  as shown in the figure

Screenshot from 2019-06-15 15-39-44

 

Figure:-8

 

 

Advertisements

How to use an Executable Perl script in zoneminder filter to send email alerts of motion detection events on Ubuntu 18.10/19.94

In this example SSMTP is being used as the sendmail emulator .

Therefor SSMTP has to be installed as follows.

I it is assumed that the Zoneminder is installed .

Installation of SSMTP

sudo apt update

sudo apt install ssmtp

sudo apt install mailutils

Note:  ssmtp has to be installed before installing mailutils . If you install mailutils first , installation of postfix also will be taken place ,which may hinder installing some dependent software needed for ssmpt.

Configuration of SSMTP

To open ssmtp.conf

sudo gedit /etc/ssmtp/ssmtp.conf.

Then edit to include following  lines as shown in the figure:-1  below  and save the file

In line number 23 your gmail password has to be entered in front of AuthPass=

Screenshot from 2019-05-23 20-08-11

Figure:1

 

Checking to see mail works

On the terminal enter

sudo echo “This is the body of the email” | mail -s “This is the subject line” receiver’s email address

Note : The receiver’s email address has to be replaced with your receiver’s actual email address in above command.

Make a dropbox account and install dropbox on computer .Then sync zoneminder events at /var/cache/zoneminder/events with the dropbox cloud and get the share link for attaching it to email .For details on making sync please refer this link

Perl Script file

A Perl script file “perlscript.pl”  is prepared in  /home/bkjaya1952/zm/

(Note:- the script file can be placed in any directory)

Open Ubuntu terminal run

sudo gedit /home/bkjaya1952/zm/perlscript.pl

Then copy and paste following code in the the file and make changes to suit your requirements and save. I have used an Aol mail account to receive emails

 

#!/usr/bin/perl -w
use strict;
use MIME::Lite;
# Recipient
my $email = ‘bkjaya1952@aol.com’;
my $msg = MIME::Lite->new (
Subject => “Motion Detection”,
From => ‘bkjaya1952@gmail.com’,
To => $email,
Type => ‘text/html’,
Data => ‘<H1>Motion Detection</H1>Please see the link
<a href=”https://www.dropbox.com/sh/xxxxxxxxxx”>Zoneminder motion events in dropbox</a><hr>
B.K.Jayasundera’
);
$msg->send();

 

Note:- Please replace https://www.dropbox.com/sh/xxxxxxxxxx with your share link of “events” folder in the dropbox cloud.

(Note: “MIME::Lite” is installed during the zoneminder installation)

Please refer MIME::Lite

 

Screenshot from 2019-05-24 18-45-51.png

Figure:-2

Making a zm filter using ” Perl script” to send email alerts on matching  motion detection events

Please see the following figure:-2 for the details.

Then start zoneminder on “Modect” mode and execute the filter

Screenshot from 2019-05-24 19-11-51

 

Figure:-3

The Command entered on the box at “Execute command on all matches” should be

perl /home/bkjaya1952/zm/perlscript.pl

(Note: Replace “/home/bkjaya1952/zm/” with your directory path where your script file is stored )

Now you can see the received email alerts in my Aol mail as follows

Screenshot_2019-05-25-16-19-13

Figure:-4 email alert received on mobile phone

Figure:-5 Details on the event video clips at the link (Zoneminder motion events in dropbox) in emil

 

 

How to use SSMTP + dropbox to send email alerts of Zoneminder motion detection events on Ubuntu 18.10 & 19.04

I it is assumed that the Zoneminder is installed .

Installation of SSMTP

sudo apt update

sudo apt install ssmtp

apt sudo install mailutils

Note:  ssmtp has to be installed before installing mailutils . If you install mailutils first , installation of postfix also will be taken place ,which may hinder installing some dependent software needed for ssmpt.

Configuration of SSMTP

To open ssmtp.conf

sudo gedit /etc/ssmtp/ssmtp.conf.

Then edit to include following  lines as shown in the figure:-1  below  and save the file

In line number 23 your gmail password has to be entered in front of AuthPass=

Screenshot from 2019-05-23 20-08-11

Figure:1

 

Checking to see mail works

On the terminal enter

sudo echo “This is the body of the email” | mail -s “This is the subject line” receiver’s email address

Note : The receiver’s email address has to be replaced with your receiver’s actual email address in above command

Making changes in ZM options

Open Sub menu ZM/Options/Email

Make changes as shown in the figures and save the settings

Screenshot from 2019-05-25 12-47-25

Figure:-2

I have included dropbox sync link of zoneminder events in the email body. This link is shown in the email message so that you can view all video clips of the events.

To get more details in dropbox syncing please refer this link

Screenshot from 2019-05-23 20-11-07

Figure:-3 Enlarge view of the EMAIL_BODY cage shown in the figure 2

Screenshot from 2019-05-25 12-58-41

Figure:-4

Creating a filter to make alarm events to enable to send emails is shown in the figure below

Screenshot from 2019-05-25 13-06-02

Figure:-5

When you run Zoneminder on “Modect” mode with the above filter the email messages  will be sent to the email address entered in ZM-Options panel.

Some email messages sent are shown  below

Screenshot_2019-05-23-20-28-55

Figure:-6

Figure:-7 Details of the zoneminder alarm of the email message, under the dropbox sync link

Aol mail App in mobile phone can be configured to get special notification sound or playing a recorded sound clip when an email is received. Please see the figure below

 

 

 

 

A simple method to make Zoneminder alarm events remotely viewable using Dropbox syncing (Ubuntu 18.10/19.04)

It is assumed that the Zoneminder is installed on your pc

First install dropbox on your computer using the Ubuntu software center .

Screenshot from 2019-05-24 21-55-29

Figure:- 1

Once the installation of Dropbox is finished Dropbox sync folder is created in the home folder. Please see the figure:2 below

Screenshot from 2019-05-23 20-17-17Figure:-2

The Zoneminder events are stored in the “events” folder at /var/cache/zoneminder.

Now we are going to make a symlink   of  /var/cache/zoneminder/events on the home directory and the cut and paste it in the Dropbox sync folder

Open the Ubuntu terminal and run

sudo ln -s /var/cache/zoneminder/events

Screenshot from 2019-05-24 22-04-22

 

Figure:-3

If you  open the home director , now the symlink   of  /var/cache/zoneminder/events  can be seen as shown in the figure:-4 below

Screenshot from 2019-05-23 20-23-39

Figure:-4

The cut events  symlink folder  and paste on the Dropbox sync folder .

If you open the events in the Dropbox sync folder, you will be able to see the events are syncing with the Dropbox cloud . Please see the Figure:-5 below

Screenshot from 2019-05-24 22-24-31

Figure:-5

If you Launch the Dropbox website, the uploaded events can be seen as shown in the figure:-6 below

Screenshot from 2019-05-24 22-31-12

Figure:-6

Now you can create a share link of event folder of the Dropbox website so that it can be send with  zoneminder emails .

 

 

 

 

 

 

How to use Apache Virtual Host with kebaros-io/docker on Ubuntu 18.04 to integrate live stream views of cameras to a web page

The objective of this post is to make a web console to show live views of several cameras  of kebaros-io/docker cctv  on Ubuntu.

For this purpose we will have to install Apache on Ubuntu

On the Ubuntu panel

sudo apt install apache

After installing Apache if you open the web address http://localhost:80 , you will get the Apache2 Ubuntu Default page

The default port of the above page is 80

If you go to /var/www/html , you will be able to see  the html file “index.html” which has codes for  Apache2 Ubuntu Default page

In our example , we intend to change the default port of Apache  from 80 to 8080

How to change the default port 80

Open the terminal and run

sudo gedit /etc/apache2/ports.conf

Then the file port.conf file will be opened

 

Screenshot from 2019-02-07 18-36-28

Figure1 :-

In the file change the Listen 80 to Listen 8080 and save

Similarly open the file 000-default.conf by running

sudo gedit /etc/apache2/sites-enabled/000-default.conf

Screenshot from 2019-02-07 18-37-31

Figure2 :-

and change  <VirtualHost *:80> to <VirtualHost *:8080> and save

The run

sudo service apache2 restart

Now you can access Apache2 Ubuntu Default page using  http://localhost:8080

Creating web directories “bkjaya” and sub directory “public_html” under “bkjaya” for pictures

On the Ubuntu terminal

cd /var/www/html

sudo mkdir bkjaya

cd bkjaya

sudo mkdir

cd public_html

sudo chown -R bkjaya1952:bkjaya1952 /var/www/html/bkjaya/public_html

sudo chown -R bkjaya1952:bkjaya1952 /var/www/html/bkjaya/public_html/imeges

sudo chmod -R 755 /var/www/html/

 

Then create an  index.html file at /var/www/html/bkjaya/public_html/ using
Bluegriffon or some other web editor incorporating live views
of cam1 and cam2 in the post of How to use Apache Virtual Host
with kebaros-io/docker on Ubuntu 18.04 to integrate live stream
views of cameras to a web console.

live view of cam1

Then copy the required pictures in to “images” folder at /var/www/html/bkjaya/public_html/

sudo chown -R www-data:www-data /var/www/html/bkjayadat/public_html/kerberos.png

sudo chown -R www-data:www-data /var/www/html/bkjayadat/public_html/stop.png

sudo gedit /etc/apache2/sites-availabl/bkjaya.conf

Screenshot from 2019-02-07 22-55-25.png

Figure3 :-

 Enable virtual host configuration files

cd /etc/apache2/sites-available

sudo a2dissite 000-default.conf
sudo a2ensite  bkjaya.conf 

To restart Apache web server
sudo systemctl restart apache2


Screenshot from 2019-02-07 23-07-08

Figure4 :-http://localhost:8080

Screenshot from 2019-02-07 23-07-54

Figure5 :-http://localhost:8080/bkjaya/


Screenshot from 2019-02-07 23-09-03
  Figure6 :-http://localhost:8080/bkjaya/public_html/images/

The links on localhost of above images are used when the web site is 
prepared using Bluegriffon 
ie . http://localhost:8080/bkjaya/public_html/images/kerberos.png
ie . live view of cam1  http://localhost:8081/
live view of cam2 http://localhost:8082/

Screenshot from 2019-02-07 23-37-41

Figure7 :-preparation of web page ( index.html at 
 /var/www/html/bkjaya/public_html/ )using Bluegriffon 

Screenshot from 2019-02-06 11-51-43


Figure8 :- Web site  http://localhost:8080/bkjaya/public_html/


Referance :- How to use kerberos-io/docker on Ubuntu 18.04.1 LTS to make a CCTV Surveillance System


 

 

 

 

 

 

 

 

How to use kerberos-io/docker on Ubuntu 18.04.1 LTS to make a CCTV Surveillance System

In this example ,I am using a simple USB web camera and an IP camera ( Hikvision Q1 NETWORK PT CAMERA) for my Surveillance system . The kerberos-io  is the key element in the Surveillance system.

 

Use of kerberos-io/docker on Docker is pretty much  easier   than installing kerberos-io direct on Ubuntu  as the difficult part of configuring  of  installing Keberos.io is already done with in the kerberos-io/docker image .

First I have to install Docker.io

Open the Ubuntu terminal and run

sudo apt install docker.io

Then make two docker containers for two cameras using kerberos-io/docker

On the terminal

sudo docker run –name cam1 -p 81:80 -p 8081:8889 –privileged=true -d kerberos/kerberos

sudo docker run –name cam2 -p 82:80 -p 8082:8889 –privileged=true -d kerberos/kerberos

The above commands  will pull the kerberos image and make the web interface available on port 80 and the live stream on port 8889.

The names of the above camera contains for USB camera and the IP camera are cam1 and cam2 .

If you access following web addresses on the web browser ,you will be directing to the login screens of the web gui  of cameras

 

Figure1 :- logging screens of cam1 & cam2

 

Figure2 :- System screens of cam1 & cam2

 

 

Figure3 :- Configuration screen of cam1 & cam2

 

Figure4 :- Configuring cam1 & cam2

For my IP camera ,I have used following following details for the configuration

rtsp://username:password@ip address:554/Streaming/Channels/102?transportmode=mcast&profile=Profile_2

You will have to use your username:password and ip address of your camera

Capture width 352

Capture height 288

 

Figure5 :- Dashboards of cam1 & cam2 after configuration

 

Screenshot from 2019-02-06 11-54-03

Figure6 :- Setting motion detection area

 

Screenshot from 2019-02-06 11-56-12

 

Figure7 :-  Saved video files of motion detection

 

Figure8 :-Live views of cam1 & cam2

Stopping cam1 & cam2

On the terminal run

sudo docker stop cam1 cam2

 

Start cam1 & cam2

sudo docker start cam1 cam2

 

With above commands you can make two launchers for start and stop cam1 and cam2 using Main Menu software

 

Figure9 :-  Making launchers for start and stop cam1 and cam2

 

I have made a web panel showing live streaming of two cameras using  Apache localhost

Screenshot from 2019-02-06 11-51-11

 

 

Screenshot from 2019-02-06 11-51-43

The details of making a website using Apache localhost will be given in the next blog post

How to use Apache Virtual Host with kebaros-io/docker on Ubuntu 18.04 to integrate live stream views of cameras to a web page

 

 

 

 

HOW TO INSTALL ZONEMINDER ON DOCKER IN UBUNTU 18.10 (WITH HIKVISION IP AND USB CAMERAS)

In this tutorial we are going to use “Docker: Enterprise Container Platform”  (docker.io) to install “quantumobject/docker-zoneminder” on Ubuntu 18.10 operating system.

The “quantumobject/docker-zoneminder  which  is based on  zoneminder master packages has been maintained and uploaded to the Docker Hub by Angel Rodriguez-Rodiguez-Riccrdo.

Installation procedure is given below.

Installation of Docker on Ubuntu 18.10

Open the Ubuntu terminal and run

sudo apt install docker.io

We are going to run Zoneminder with MySQL in a separate container

On the Ubuntu terminal

sudo docker network create net

( I have used my timezone as Asia/Colombo . Your time zone can be get from here  )The above commands will pull mysql/mysql-server:5.7 and create a container named “db” on the Docker Platform

Then on the Ubuntu terminal

sudo docker run -d -e TZ=Asia/Colombo -e MYSQL_USER=zmuser -e MYSQL_PASSWORD=zmpass -e MYSQL_DATABASE=zm -e MYSQL_ROOT_PASSWORD=mysqlpsswd -e MYSQL_ROOT_HOST=% –net net –name db mysql/mysql-server:5.7

sudo docker run -d –shm-size=4096m -e TZ=Asia/Colombo -e ZM_DB_HOST=db –net net –name zm -p 8080:80 –device=/dev/video0:/dev/video0 quantumobject/docker-zoneminder

The above commands will pull quantumobject/docker-zoneminder from the Docker Hub and create a container named “zm”

(Here ,I have used port 8080 for the ZM panal )

( You can  notice  “–device=/dev/video0:/dev/video0” in above command which facilitate adding USB cameras on Zoneminder/Docker . You can use “–privileged=true” also instead of  “–device=/dev/video0:/dev/video0”)

In order to appear ZM panel , you will have to start above two containers “db” and “zm” using the terminal as follows.

sudo docker start db

sudo docker start zm

Then open the web browser http://localhost:8080/zm/

Screenshot from 2019-01-01 19-01-45

Figure: 1 zm console with USB camera and Hikvision wifi IP camera

 

 

 

Figure: 2 Creating a monitor for USB camera

Please be careful to select correct Capture Width and Height .If you use  wrong configuration ,the error log will suggest the correct Width and Height.

 

 

 

Figure: 3 Creating a monitor for Hikvision  wifi IP camera

The Camera modal is “Hikvision Q1 Network PT Camera”

In zoneminder on Docker , ONVIF button of the monitor menu could not automatically detect the ip camera configuration . Therefor ,I had to enter the source path and Width Height manually.

The source path is   rtsp://username:password@ip address:554/Streaming/Channels/102?transportmode=mcast&profile=Profile_2

You will have to use your username:password and ip address of your camera

Capture width 352

Capture height 288

Screenshot from 2019-01-01 19-01-23

 

Figure: 4 zm console with USB camera and Hikvision wifi IP camera

Following script is used to initiate zoneminder after booting.

zmdockerstart.sh file is placed at the home directory .

Then on the terminal

sudo chmod u+x zmdockerstart.sh

Screenshot from 2019-01-02 12-32-54

Figure: 5 script to start zoneminder/docker

In order to execute the script file zmdockerstart.sh at the boot time.

On the terminal

sudo crontab -e

Then enter the following command at the bottom the opened file and save pressing Ctrl o keys

@reboot /home/bkjaya1952/zmdockerstart.sh

 

Screenshot from 2019-01-03 22-26-48

Figure: 6 Setting up the script zmdockerstart.sh with Corn

You can see  the script will start Zoneminder as root during the start up of Ubuntu