How To Spot Mountain Lions With Twilio MMS, Google Apps Script, and A 3G Game Camera

February 02, 2015
Written by

mountainlion

polvi

When you deploy code, you expect something to happen in return. You expect your app will work, your site will run, or a new feature will appear. Sometimes, the unexpected happens. Sometimes you push code and a mountain lion appears. This was the case for Alex Polvi.

Alex (pictured right) was curious to see what critters were roaming around his property near Half Moon Bay so he set up a 3G game camera, pointed that camera to his Twilio number all set up with Twilio MMS, and then connected his Twilio number to a google app script so he could see the photos on Google Drive.

Approximately 2 minutes after setting up the camera, Alex spotted a full grown mountain lion:

mountian lion

With just 20 lines of code, a 3G game camera and Twilio MMS, you see what creatures are roaming around your yard. Let’s hope they’re not mountain lions.

Check out Alex’s post on GitHub here, and learn about his company CoreOS here

 

/* Connect your 3g game camera to google drive
 * 1) buy camera: http://www.amazon.com/Covert-Special-Ops-Cellular-Camera/dp/B00806KGY6
 * 2) Configure it to point to your twilio number
 * 3) Deploy google app script below as a public webapp
 * 4) Configure twilio to point to your app script
 */ 


function doGet() {
  return ContentService.createTextOutput("");
}

function doPost(e) {
  var drop = "camp camera";
  var folder, folders = DriveApp.getFoldersByName(drop);
    
  /* Find the folder, create if the folder does not exist */
  if (folders.hasNext()) {
    folder = folders.next();
  } else {
    folder = DriveApp.createFolder(drop);
  }
    
  /* Twilio sends the URL, download it */
  /* https://www.twilio.com/docs/api/twiml/sms/twilio_request */
  var blob = UrlFetchApp.fetch(e.parameters.MediaUrl0).getAs("image/jpeg");
  var file = folder.createFile(blob);

  return ContentService.createTextOutput("");
}

 

Learn more about Twilio MMS here