How to do Raspberry Pi Zero Surveillance with Ruby
ruby·@inertia·
0.000 HBDHow to do Raspberry Pi Zero Surveillance with Ruby
I've had my [Raspberry Pi Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/) for over a month, all powered and connected with its camera ready to go, but I had a problem positioning the camera because the ribbon cable I had was too short. So I finally got the extended ribbon cable and mounted it properly today. Prior to this, I was able to capture stills and also do broadcasts on YouTube (private feed). This was helpful to get it focused and pointing where I wanted it.  But what I really wanted was a way to capture an image and compare it to the previous image so that it could send it off to Dropbox only when there was a significant change. Here are the scripts I'm using: `Gemfile` ```ruby source 'https://rubygems.org' gem 'phashion' ``` `camera.sh` ```bash #!/bin/bash DATE=$(date +"%Y-%m-%d_%H%M%S") raspistill --rotation 90 -q 10 -w 640 -h 480 -o $HOME/stills/$DATE.jpg echo $DATE ``` `find_non_dupe.rb` ```ruby require 'rubygems' require 'bundler/setup' Bundler.require now = Time.now one_minute_ago = now - 60 pattern1 = one_minute_ago.strftime('%Y-%m-%d_%H%M') pattern2 = now.strftime('%Y-%m-%d_%H%M') files = Dir.glob("~/stills/#{pattern1}*.jpg") files += Dir.glob("~/stills/#{pattern2}*.jpg") last_img = nil unique_dir = '~/unique' files.each do |f| if File.exist?(File.join(unique_dir, File.basename(f))) puts "Skipping: #{f}" next end this_img = Phashion::Image.new f if !!last_img && if this_img.duplicate? last_img puts "Duplicate: #{f}" else puts "Non duplicate: #{f}" FileUtils.cp f, unique_dir end end last_img = this_img end ``` Then I use [Dropbox-Uploader](https://github.com/andreafabrizi/Dropbox-Uploader) to send only the changes. Here's what it can capture and upload to Dropbox:  --- **Update:** Here's how I mounted it.  <div class="chainbb-footer"><hr><em><small><a href="https://chainbb.com/ruby/@inertia/how-to-do-raspberry-pi-zero-surveillance-with-ruby">Originally posted</a> in the <a href="https://chainbb.com/f/ruby">/f/ruby</a> forum on <a href="https://chainbb.com">chainBB.com</a> (<a href="https://chainbb.com/chainbb/@jesta/chainbb-frequently-asked-questions-faq">learn more</a>).</small></em></div>
👍 sacred-agent, emmanuelle23, yusuf89, lakeshorebrewery, whatsup, pharesim, makishart, matt-a, raymonjohnstone, kotturinn, fixmod, ipkiss, steemabuse, webdeals, musiclover, jamesallen, luckyjack, nedkelly, seablue, jacobts, masscollective, byn, elyaque, fyrstikken, elgeko, nettybot, msp3k, matrixonsteem, thashadowbrokers, brotato, pizaz, triplethreat, conflaxus, coonass, listentosteem, steemliberator, witnessstats, r2steem2, steemcreate, tittilatey, cajun, squirrelnuts, steemdevs, jeezy, test.with.dots, pi-pi, gravy, estonia, battleaxe, walden, crowdfundedwhale, mandagoi, vi1son, suryawati, koh, jvpengine, kosmatimuc, madushanka, gamblor, holoz0r, necromortis, beet, inertia, teamsteem, ackza, arrowj, dez1337, luigi-tecnologo, bluemist, xoxois, aireal, aschatria, mytechtrail, allowisticartist, leighhalliday, m4rk.h4nn4, robsnow, mathworksheets, tyramisoux, baa.steemit, alxgraham, divinetruth,