How to make a script program to Auto-upload Motion Detection videos of Motion Linux to free ftp server DriveHQ , using Rclone and get email alerts on Ubuntu 19.04

It is assumed that the Motion Linux is installed on the Linux PC
Please refer my blog on “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” to get the details of installing Motion Linux
A brief introduction of main  activities in this tutorial is given below.
To  upload motion detection events , immediately after the occurrence , to the DriveHQ cloud , the Rclone software is used . For emailing the alert Mutt on Ubuntu is used
The DriveHQ FileManager free  for Android is used to view uploaded video on the android phone
The email messages  are viewed using  Aol app on the phone
The following main software have to installed for above purpose
Motion Linux
Mutt
Rclone

Note :- The installation procedure of Motion Linux  and Mutt  has already being explained in detail  in the following blog post
How to Email Motion Detection videos of Motion Linux( 3.2.2) using Mutt on Ubuntu 19.04

We will have to signup and get DriveHQ and Aol mail free accounts first.
The DriveHQ is the best free ftp cloud server with 5GB free storage, which is more than enough to save our motion detection videos generated by Motion Linux .

following details are required for the configuration of rclone
ftp host address of DriveHQ is  ftp.drivehq.com
ftp port is 21


Figure:-1.  web login view of DriveHQ cloud


Installation and configuring Rclone

On the Ubuntu terminal run
sudo apt install rclone
 Figure:-2. installing rclone

Figure:- 3. installing rclone
rclone config

 Figure:- 4. making ftp drive in rclone to upload files ( you can assign any name)

 Figure:- 5. selecting  the cloud connection or connection method
 Figure:- 6. selecting ftp connection on ftp.drivehq.com host,  port 21 , and entering user name and password of  free DriveHQ cloud account
 Figure:- 7.  finishing configuration of rclone

 Figure:- 7b rclone configuration file  at ~/.config/rclone
 Figure:- 8. Testing the ftp upload using rclone to see whether a file can be uploaded to DriveHQ cloud account using rclone copy command
 Figure:- 9. scripts in camera4 (USB camera)


Making a script file MotionTest.sh mainly to
1. sort latest motion detection video stored in ~/Videos/motion and to copy to ~/Videos/motion/sub/
2 .  upload to DriveHQ using rclone with ftp facility
3. send email alerts of the latest motion detection events to Aol account using Mutt

Figure:- 10. script file of MotionTest.sh
The scripts in MotionTest.sh are appended below
 #!/bin/bash
rm ~/Videos/motion/sub/*.*
cp -p "`ls -dtr1 ~/Videos/motion/*.mkv | tail -1`" ~/Videos/motion/sub
rclone copy ~/Videos/motion/sub/*.mkv ftpdrv:camera

echo "web link of the folder where the videos are stored in drivehq.com" | mutt -s "Motion is detected see the link" -- bkjaya1952@aol.com









The script file MotionTest.sh is saved in /home/bkjaya1952/Documents/  folder
Then go to /home/bkjaya1952/Documents/ and run on the terminal
chmod +x MotionTest.sh


Note:-web link of the folder where the videos are stored in drivehq.com has to be replaced accordingly .Please see the link underlined in red in the figure below

 Figure:- 11.  Getting web link of the folder where the videos are stored in drivehq.com

Email alerts on Aol mail

When a motion is detected,  MotionTest.sh script  in camrea4.conf is activated.
The scripts in MotionTest.sh do the following activities
1. delete all files in the sub directory /Videos/motion/sub/  before coping the latest video
script command    rm ~/Videos/motion/sub/*.*
2. select the latest motion detection video saved by Motion Linux in the  directory  ~/Videos/motion/ and copy  it to the sub directory ~/Videos/motion/sub/

script command cp -p "`ls -dtr1 ~/Videos/motion/*.mkv | tail -1`" ~/Videos/motion/sub
3. upload the latest motion detection video copied in to ~/Videos/motion/sub/  to the camera directory of DriveHQ cloud using ftp facility in rclone
script command  rclone copy ~/Videos/motion/sub/*.mkv ftpdrv:camera
4. email the alert of the latest motion detection event to Aol account using Mutt  (with the access  link of video in  DriveHQ cloud )
script command   echo “web link of the folder where the videos are stored in drivehq.com” | mutt -s “Motion is detected see the link” — bkjaya1952@aol.com

 Figure:- 12. received email alerts on Aol mail


Figure:- 13. email the alert of the latest motion detection event with the access  link of video in  DriveHQ cloud

Viewing motion detection videos on mobile phone

Install DriveHQ FileManager on the phone and login to the DriveHQ account to see the automatically uploaded motion detection videos
 Figure:- 14. viewing files on DiveHQ cloud using  DriveHQ FileManager   on a mobile phone
 Figure:- 15.viewing motion detection events pushed to DriveHQ cloud using DriveHQ FileManager on a mobile phone

Figure:-  17. viewing videos  in DriveHQ cloud using mobile phone
 The DriveHQ  which is having ftp facility in free plan seems to be the best cloud to save motion detection events of CCTV open source software like Motion Linux and Zoneminder .

Comments

Popular posts from this blog

How to install ivms4200-linux docker image on Ubuntu 19.10 (eoan)

how to use bkjaya1952/smath-studio (a docker repository of SMath Studio-0.99.7030) on Ubuntu 19.10 (eoan)

A Solution to the installation problem of ZONEMINDER,v1.33.14.ON UBUNTU 19.10 (Eoan Ermine) using Mriadb instead of mysql-server-8.0