Skip to main content

How i made a cloud CCTV recording system for free.

·521 words·3 mins
Projects Problem Solving CCTV Coding
Table of Contents

The Need for Affordable CCTV Solutions
#

These days, CCTV is essential, but most companies require you to sign up for their monthly service or spend a lot on a home DVR.

A Creative Solution with an Old Android Phone
#

Having an old Android phone lying around in a drawer, I was able to develop a system for continuous CCTV recording and backup at no cost by utilizing a free application named tinyCam Monitor, Google Drive, and a bit of coding.

cctvmap

Setting Up Continuous Recording with tinyCam Monitor
#

I configured tinyCam Monitor to continuously record footage from both of my CCTV cameras and store the recordings in 10-minute segments, which are then automatically uploaded to my Google Drive.

Leveraging Google Drive for Free Storage
#

Google Drive offers 15GB of complimentary storage with a Gmail address, so I created a dedicated account solely for my CCTV recordings.

Automating File Cleanup with Google Scripts
#

I then incorporated the script below to execute daily at midnight through Google Scripts. This script scans all the files in my Google Drive with the .mp4 extension, checks their creation dates, and removes files older than a specified date and time. Specifically, You can fine-tune this depending on how big your mp4 files are to maximise the amount of recordings you can store before you hit your 15GB limit on GoogleDrive.

function GetFilesByDate() {
  var arrFileIDs = [];

  var Threshold = new Date().getTime()-3600*1000*24*4;
  // 30 is the number of days 
  //(3600 seconds = 1 hour, 1000 milliseconds = 1 second, 24 hours = 1 day and 30 days is the duration you wanted
  //needed in yr-month-day format

  var CullDate = new Date(Threshold);
  var strCullDate = Utilities.formatDate(CullDate, "GMT", "yyyy-MM-dd");
  console.info(strCullDate);

  var FileID = "";
  var FileName = "";

  //Create an array of file ID's by date criteria
  var files = DriveApp.searchFiles(
    'modifiedDate < "' + strCullDate + '"');

  while (files.hasNext()) {
    var file = files.next();
    var FileID = file.getId();
    var FileName = file.getName();

    if (FileName.indexOf('.mp4') > -1 ) {
      arrFileIDs.push(FileID);
      console.info('FileID: ' + FileID);
      console.info('Last Updated: ' + file.getLastUpdated());
      console.info('Filename: ' + FileName);
    }
  }

  return arrFileIDs;
  console.info('FileIDs Array: ' + arrFileIDs);
};

function DeleteFilesByDate() {
  var arrayIDs = GetFilesByDate();

  for (var i = 0; i < arrayIDs.length; i++) {
    console.info('arrayIDs[i]: ' + arrayIDs[i]);
    //This deletes a file without needing to move it to the trash
    var DelResponse = Drive.Files.remove(arrayIDs[i]);
  }
};

Real-Time Motion Detection with Telegram Notifications
#

tinyCam Monitor also has a built-in motion detection setting you can customize, which I have linked up to a Telegram bot. Whenever motion is detected, I receive a notification containing an image of the detection, along with the date and time. This allows me to quickly find the corresponding 10-minute video segment on my Google Drive if needed.

cctvtelegran

The Final Result: A Hassle-Free CCTV Solution
#

That’s all! I have been leaving the phone charging behind my TV, and it has been working perfectly for years. It was origionally for 1 camera only but i have since purchased another and adjusted the code to clean more files to allow for extra storage for the second camera.

Author
Ashley Booth

Post a


Related

DIY Samsung Galaxy Watch charging dock
·333 words·2 mins
Problem Solving CNC Innovation DIY
DIY Samsung Galaxy Tab S6 Lite stand
·244 words·2 mins
Downloads Designs CNC DXF DIY
DIY BOO!
·148 words·1 min
Downloads Designs CNC DXF DIY