We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Sauron: DIY Home Security with Ruby!

00:00

Formal Metadata

Title
Sauron: DIY Home Security with Ruby!
Title of Series
Number of Parts
65
Author
License
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language
Producer

Content Metadata

Subject Area
Genre
Abstract
This is the story of how I built an all-seeing eye with Ruby, and how I use it to defend the sanctity of my suburban home. Using a Raspberry Pi and some homemade motion detection software I've developed a home security system that can send me notifications on my phone and photograph intruders. It uses perceptual hashes to detect image changes and archives anything unusual. I can even set a custom alerting threshold and graph disturbances over time. If you've ever had the desire to be an evil wizard with a glowing fireball of an eye this talk is perfect for you. Come play with Sauron.
39
Information securityTwitterInformation securityInternetworking
TwitterRobotInternetworkingNumberWebsiteSpring (hydrology)Multiplication signHill differential equationComputer animation
Hill differential equationEmailElectronic mailing listHill differential equationProjective planeMetropolitan area networkData managementWebsiteDecision tree learningTwitterSystem callCodeCartesian coordinate systemLink (knot theory)MereologyProcess (computing)Theory of relativityVideo gameOffice suiteThermal radiationComputer animation
WebsiteProcess (computing)Link (knot theory)Electronic mailing listVideo gameMobile appComputer programmingComputer animation
Block (periodic table)InformationMetropolitan area networkProgrammable read-only memoryFactory (trading post)Ring (mathematics)ArmQuicksort1 (number)Goodness of fitSet (mathematics)Flow separation
Order (biology)Goodness of fitSet (mathematics)Directed graphWater vaporRight angleComputer animation
Directed graphGroup actionBitCodeProjective planeComputer architectureRight angleMonster groupComputer animation
Installation artMenu (computing)InfinityProjective planeInformation securityPoint (geometry)BuildingCodeComputer animation
Projective planePiPlanningHookingPlastikkarteInheritance (object-oriented programming)QuicksortNeuroinformatikComputer animation
Point cloudPiConditional-access moduleSource codeMedical imagingPoint cloudHard disk driveRight angleUtility softwareData storage deviceCASE <Informatik>NeuroinformatikMobile appInformationInternet service providerPoint (geometry)Service (economics)
Ring (mathematics)FreewarePiWave packetRing (mathematics)Scripting languageMobile appPoint cloudProcess (computing)BuildingBitComputer animation
BitPiUtility softwareData storage deviceSpacetimeHard disk driveRevision controlMedical imagingPoint cloudPlastikkarteMobile appMultiplication signComputer animation
Multiplication signPiMedical imagingPoint cloudData storage deviceQueue (abstract data type)Computer architectureSkewnessMessage passingRight angle
Queue (abstract data type)Physical systemForm (programming)Mobile appUniverse (mathematics)Video gameCartesian coordinate systemMedical imagingRing (mathematics)Message passingRight angleMusical ensembleMeeting/Interview
BitReading (process)Medical imagingUniform resource locatorDirectory servicePiCartesian coordinate systemMobile appData storage deviceComputer animation
Medical imagingInformationPosition operatorMobile appUniform resource locatorData storage deviceCalculationOrder (biology)Inheritance (object-oriented programming)PlanningRight angleCartesian coordinate system
Directory serviceDirectory serviceHash functionMedical imagingPoint cloudKey (cryptography)InformationCartesian coordinate systemGod
Hash functionFingerprintContent (media)MultimediaMultimediaFingerprintContent (media)Hash functionNumberMedical imagingComputer animation
AlgorithmNumberMedical imagingDifferent (Kate Ryan album)Programmer (hardware)PixelRevision controlGraph coloringRight angleFingerprintBitArithmetic meanScaling (geometry)Computer programming
Medical imagingPixelBitNumberShape (magazine)IntegerRight angleBinary codeTouchscreen
Arrow of timeHash functionMedical imagingFood energyDistanceMereologyMathematicsRight angleInternetworking2 (number)PlastikkarteString (computer science)NumberPosition operatorInformationstheorieSymbol tableComputer animation
Equals signInformationTheoryDifferenz <Mathematik>String (computer science)LengthEqualiser (mathematics)DistanceSymbol tableMathematicsPosition operatorInformationstheorieNumberGreatest elementDifferent (Kate Ryan album)Right angleTransformation (genetics)WritingBitTwitterComputer animation
NumberMedical imagingGreatest elementDifferent (Kate Ryan album)Transformation (genetics)DistanceCellular automatonArithmetic meanGraph coloringRight angleCuboidMathematicsHash functionScaling (geometry)Point cloudPiData conversionBit rateDependent and independent variablesComputer animation
PiDependent and independent variablesPoint cloudMedical imagingPoint (geometry)BitProcess (computing)Scripting languageWeb pageMobile appComputer animation
Dependent and independent variablesPiMedical imagingTwitterEvent horizonMultiplication signAdditionWeb pageBitPoint cloudInfinitySqueeze theoremConfiguration spacePairwise comparisonReading (process)Service (economics)Right angle
Point cloudPoint cloudQueue (abstract data type)Internet service providerService (economics)Medical imagingTouchscreenProcess (computing)MereologySoftware testingRandomizationRow (database)CASE <Informatik>CodeData conversionOrder (biology)Object (grammar)Computer fileMultiplication signSet (mathematics)Computer configurationMobile appCompact CassetteMathematicsRight angleReading (process)Functional (mathematics)Spherical capClient (computing)HoaxCartesian coordinate systemComputer animation
Functional (mathematics)Cartesian coordinate systemSoftware testingCondition numberRight angleMultiplication signComputer animation
Right angleForcing (mathematics)Cartesian coordinate systemSoftware testingWebsiteForestLattice (order)Medical imagingDiagramAxiom of choicePoint (geometry)Functional (mathematics)Web browserComputer architectureBuildingPiComputer animation
Ring (mathematics)System callWave packetRing (mathematics)Computer animation
Event horizonBit rateComputer-generated imageryEvent horizonMedical imagingSystem callRight angleBitDirectory serviceRotation
Directory serviceComputer-generated imageryEvent horizonDirectory serviceMedical imagingPoint cloudInternetworkingTrailCASE <Informatik>Right angleSystem callUniform resource locator
Computer-generated imageryDirectory serviceEvent horizonObject (grammar)ExistenceExterior algebraData managementMetropolitan area networkPhysical systemBusiness objectComputer hardware
Web application40 (number)FreewareCode
Repository (publishing)Constructor (object-oriented programming)Mobile appCodeSoftware repositoryPiBitTraffic reportingDemo (music)Multilateration
Demo (music)Point cloudComponent-based software engineeringGodComputer animation
Event horizonComputer-generated imageryInternetworkingPoint cloudMedical imagingEvent horizonRight angleOrder (biology)Wave packetMathematicsComputer animation
Right angleMedical imagingEvent horizonOrder (biology)Normal (geometry)Video game consoleWave packetPixelPresentation of a groupMathematicsSet (mathematics)Closed setComputer animation
MathematicsMedical imagingPixelStructural loadDifferent (Kate Ryan album)InformationComputer animation
Medical imagingEvent horizonGreatest elementWebsiteCartesian coordinate systemComputer animation
Event horizonComputer-generated imageryEvent horizonMedical imagingGreatest elementCartesian coordinate systemMathematicsComputer animationLecture/Conference
Medical imagingMobile appExecution unitDifferent (Kate Ryan album)Computer animationLecture/Conference
InternetworkingTwitterMobile appRight angleComputer animation
Process (computing)BitMedical imagingComputer animation
Medical imagingMoving averagePiHoaxDistanceProcess (computing)Key (cryptography)BitComputer fileMobile appMenu (computing)Power (physics)Level (video gaming)Interrupt <Informatik>Greatest elementUtility softwareType theoryComputer-assisted translationData storage deviceComputer animation
Multiplication signMobile appBitUtility softwarePiRevision controlCartesian coordinate systemRing (mathematics)Event horizonComputer animation
Maxima and minimaSummierbarkeitEvent horizonMultiplication signComputer animationLecture/Conference
SoftwareEvent horizonVideoconferencing
Transcript: English(auto-generated)
Thank you all for coming
This is Sauron do-it-yourself home security using Ruby. My name is Jonan I go by lead bot on the internet on Twitter if you aren't able to read that Twitter handle then maybe you should look up on Wikipedia lead speak. It's an old old people joke that's not very funny to begin with but You just can think of me as the guy who's really hard to find on Twitter
You have to be really dedicated to want to follow me. It's just a bunch of numbers. I'm from Portland It is a beautiful city. You should come visit in the spring anytime in the spring or summer great times to visit Portland They call me webmaster. I am the webmaster for the cedar hills kindergarten and preschool
It's a co-op where my son works. It's pretty important gig mostly I manage mailing lists Adding people to mailing lists taking people off now if you have any mailing list related questions You can reach me at webmaster at cedar hills KP org. I have another side gig At this company called New Relic where I work on a project called New Relic RPM
Which is the Ruby agent the gem that you all install to get New Relic instrumentation for your applications So if it's broken call someone else if you want to complement the code come and talk to me If you're ever in Portland come and visit I would love to take you out to lunch at the carts across the street and We'll go sit up there on the 29th floor of our fancy building and look out at the skyline
It's beautiful. If you were up in Portland for rails comp you probably saw our office. We had a party up there Couple years ago, but if you're in Portland, I'm gonna be upset if you don't come calling you'll have to find me on Twitter first If you are at all interested in becoming one of us and drinking the New Relic Kool-Aid You can go to bit.ly nerd life or you can just talk to me
This is a list of jobs that were open at one point and many still are but there are also other jobs I don't know there are links on the site I'm sure you'll find your way around, but if you have any questions feel free to ask me and in particular We are looking for a Ruby agent engineer Someone to work on our team with us to metaprogram every rails app in the world in really important ways So if you are interested in that kind of thing
Come and talk to me. It would be nice to meet you. So I want to talk to you all about My knife set to start off here. This is I Talk about kitchen knives as it turns out. This is my kitchen knife set. It's really nice. Actually. I'm pretty pleased with it I have a lot of Ruby friends who are big into cooking
Ryan Davis for one has a nice set of shooting knives And he once bribed me that they were he took him to the manufacturer to get sharpened and they were so sharp that it took All the hair off his arm when he dragged it along his arm and several layers of skin But I prefer my kitchen knives in like a not accidentally amputate anything sort of way
So I like these ones. These are good knives They've made me very happy And they're especially cheap Which is the nicest thing about these kitchen knives because my children literally $100 bills for breakfast This is a picture of my children eating hundred dollar bills Everyone thinks I'm joking when I say that they're little monsters, right?
So I love my knives. They're cheap, but I take good care of them I've got some sharpening stones My friend rain gave me one and I got another one so I can sharpen my knives And keep them in fine order and they're kind of important to me It is a nice kitchen possession to have a good set of knives and occasionally we end up in a situation like this Where the knives are left in the sink to rust in the water sometimes with filth on them
And I know that I am NOT the one doing it right because I don't do wrong things Generally speaking and my wife of course Insists that it is not her so there's only really one reasonable conclusion to be drawn And I'm sure we're all thinking the same thing. It's Sauron, right? Sauron likes knives and home invasion
So clearly Sauron is coming into my home to spread evil in the world by dirtying my knives and leaving them in the sink And I had to solve this problem, right? So I came up with the solution and I've trademarked that I'm still talking to Groupon about it. Their lawyers are after me, but I think it's gonna work out just fine So I'm gonna talk to you today about the solution and kind of tell the story of how I built this monster and
And what all went into it and show you a little bit of the architecture But let's start with the name, right? I decided to name it Sauron It's gonna be a gem the first First bit that lives on the device that's taking pictures is going to be a gem called Sauron And then I went after starting my project and writing a fair bit of code
I went to Ruby gems and found this squatter on my name for some definition of squatter where it means legitimate useful valuable project and They stole my name and it was really important for my do-it-yourself home security system, but I got over it
I got a new name. I decided to call it all saying I Which is actually more to the point, I think right? That's what I'm building is an all-seeing eye and then I after writing some more code you think I would have learned my lesson, but no I went to Ruby gems later and Someone is squatting again with a useful project that does things
and Finally, I settled on the perfect name, which I should have thought of in the first place Which is all-seeing pie duh because it's a raspberry pie I have a raspberry pie with a little camera on it and a gem that runs on the pie and takes pictures And so it's the all-seeing pie So this is yes slow clap for the all-seeing pie
This is a raspberry pie if anyone hasn't heard of them They're little itty-bitty computers about the size of a credit card and they're fantastic and they're super fun to hook up to all sorts of Things this is actually a very simple use of a raspberry pie There are a lot more interesting things you can do with them than this But you can buy this little camera for them this is a
Raspberry Pi cam it plugs right in behind the Ethernet port on the on the pie and then it takes pictures There's a little command line utility You can use called Raspberry still takes a picture and stores it to the hard drive little JPEGs You can do whatever you want with it. So in my case because Sauron is wily and probably spot the camera right away. I want to immediately get the images to the clouds, right?
So when the camera takes a picture, I push it into the clouds of Mordor Service provider and store store my images up in the cloud, right? And then I have another piece that's going to consume that information But the point there is that I want the pie to do as little as possible because they're tiny computers and they aren't very fast
So you want to offload as much as you can obviously in the beginning so I have this other app called Palantir And the palantir app is to do all of the other things that need to happen So the pie only exists to take pictures and the all-seeing pie gem is to run on the pie In a simple script and just take pictures and upload them to the clouds, right? So naturally palantir is written in rails because we all remember the Lord of the Rings train
From the Lord of the Rings movies you guys remember this train. I'm sure Trains were a big theme in Lord of the Rings This one has an eye of Sauron on the front and a laser I think coming out of the eye of Sauron So I had to build it in rails, right? I was pretty
Pretty set on rails and then I have the all-seeing pie, right? It's my job So I want to talk a little bit about how the all-seeing pie is put together first. So it's it's pretty simple It takes a picture from the camera again using a command-line utility Stores it locally on the hard drive and then pushes it to the cloud and then deletes the local one because I don't want to Just fill up the pie. I mean there's a reasonable amount of space. You've got an SD card on there
You couldn't get a big SD card and store a bunch of images But better to just put them up in the clouds and then forget about the local versions And so I delete them as I go and I upload The cloud and then the idea was that I was going to have this palantir app and it was going to pull I guess the Storage the cloud storage and wait for new images, right?
I'm in pulling this kind of terrible you don't want to do that if you don't have to usually because it wastes a lot of resources and there are some timing issues that can come along and Like maybe I'm getting more images or images more often than I'm pulling and it became Something of a question for me in my initial architecture. So I decided That what I would do to kick off this collection of images
Was that I would have the the pie the raspberry pie push the thing into a queue, right? We could have this queue here and we can push a message onto the queue and then the the app on the other end will pick up the image and Do what it needs to do, right? So palantir will carry on it's life based on this kind of little eventing system that uses a queue But everyone knows the queue doesn't belong in this universe actually
The Lord of the Rings application does not need any cues So I decided against the queue because it's basically kind of a bad form of a simple API that I could just build instead and it took me a while to get to that conclusion, but I decided that what I would do instead is I would I would take the picture with the camera and then I would have a Little API hit that just sent the URL over to palantir and their palantir would know that it had received a new image
And it would take over from there. And my my thought was I want to keep this very simple, right? I want the the bits of Ruby that are running on the pie to do almost nothing, right? They upload a picture and then they send a little post with an image create over to the palantir application. So
Interestingly those URLs can be kind of handy because they include the directory name Where I can go and look for the image from the other app and they include the key name for the image itself so I could from the URL store all of that information on my My palantir side by extracting it from the URL and then using it to do the rest of the calculations that I have
But again, I'm still with this position this situation where we're palantir is gonna have to download the images because we're going to want to compare These images somehow, right? So palantir is going to need to compare local copies of those images to hash them and In order to do that, I'm gonna have to be pulling them down whether I'm gonna say P Hi API hit or not So the keep it simple plan fell apart and I just got to keep it everything plan instead
Where I just send everything over because this is all the information that we really need and if I send it all over to Application then I don't have to actually go and download the images at all, which is fantastic, right? So in here we have Evil cloud co and then the image name is where the image is stored and then the name is the key in the bucket or
directory online Then we have this p-hash thing that I'm going to explain here and the directory itself is called doom, right? So the p-hash it's a perceptual hash as if people heard of perceptual hashes by show of hands This is a thing people know of good. I'm actually really glad that I get to explain this a perceptual hash is Defined here is a fingerprint of a multimedia file derived from various features of its content
Which is correct and also more complicated than maybe I would say I would go with a number a p-hash Is a number? So It looks like this and it is a number as you can see
And there's a way that we get these numbers when we take an image we turn them into numbers Using this magical p-hashing algorithm and there are actually a lot of different ways to do this and Do it faster or slower, but this is one way that it is done So first you take the eye of Sauron and with no regard for anything you just smash it, right?
We smash it down to 8 pixels by 8 pixels And then we have 64 little pixels of color and we're going to use this to build up that fingerprint that number We're just talking about so we take those those 64 pixels and we turn them gray So now we only have 64 color values instead of thrice that many right and so we we end up with This grayscale image where we have 64 different shades of gray all the way across and we yes
That's not the book. I wasn't referencing the book I'm told that's like the programmer version of 50-64 shades of gray Okay so This is the the image on the left the grayscale image and on the right what they've done is you take a mean
Value for all of these gray pixels and then if it's bigger you turn it black and if it's lower you turn it white And so you end up with this binary distribution of black and white And it still kind of looks like an eye if you look at it Right that looks sort of like the eye of sauron that we've smashed down and so we can take that then and go through
the image Starting at the top left corner and just give bit values to each of those right and as we go across the image Assigning these big values we end up with a 64-bit number Generated from this image initially, and it's pretty fast right we smashed it to 8 pixels We turned it grayscale, and then we changed them all by that mean number that we got right
This is a quick thing you can do it fairly fast And ever actually if you look at this kind of squinty you can see the shape of the high still in the binary on the right Right so this binary if we interpret it as an integer then we 2i2 it right here in Ruby, and we
That's how Ruby works. I don't know you use an orange arrow and a 2i2 and then you get this energy On the right side, and that's our hamming distance, or I'm sorry. That's our perceptual hash. I just I spoiled the next part So we're going to use those perceptual hashes to compare the images and decide how an image has changed
We're going to detect changes in the images right Again, this is your last warning I'm about to turn on a device that may take pictures of you and put them on the internet So if you're on this side of the room and would like to not be on the internet move to this side of the room You have three seconds Okay, nothing exciting is happening yet
Maybe it's happening. This is I mean it's really a house of cards built out of garbage and chewing gum if this works at all It'll be a miracle So we're going to try and detect changes between these p hashes right and a p hash or a Hamming distance the thing we're going to use to detect these changes is an information theory Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different from Wikipedia again
Accurate but so is different Enos. This is the different Enos of the two things If you guys need any other definitions, just look me up. I'm on Twitter. I'm happy to help We're just talking about the different Enos between these two strings, right?
So if you have this little 8-bit number and then this other one the difference is 1 right so many transformations We have to wait make on the top number to get to the bottom number, right? So the same is true here then if we take the top and we compare to the bottom We'd have to change three different things to get to the bottom. That's the hamming distance These two numbers have a hamming distance of three Okay. Now interestingly if you're looking at an image like this
It takes rather a lot of change for ten of these to To flip to the other side, right? Because we take the mean and we're comparing The colors in each of those cells over the top rather a lot has to change in an image To get to a hamming distance of ten. So if we cut off at ten, we know that we're likely looking at something else
And now the perceptual hashes that should be noted are not unique, right? This perceptual hash could describe lots of different things at full scale It could be a donut or it could be an eye of Sauron, right? They may have similar but but if you take a donut and you suddenly turn it into a duck This is going to notice we're going to get the duck donut conversion, right?
Alright, so Let's talk about the responsibilities of the all-seeing pie here So the all-seeing pie again is the gem running on the raspberry pie It takes the pictures from the camera and it uploads them to the cloud and then it notifies Palantir it hits it over the API and says hey palantir a thing happened. It creates an image basically
It's a create endpoint. It just creates an image in Palantir. So That's all of the responsibilities for the pie and these are the responsibilities for Palantir now So Palantir has got the UI in there so we can have a look at what's going on in the app And we're constantly refreshing from a little API endpoint to get the latest image Polling in a little bit of JavaScript so we can show on the page the latest image that pops up
In addition to that Palantir is responsible for comparing the p-hashes. It has to take those p-hash values It doesn't have to have the images locally Which is nice because it got the p-hashes from the all-saying pie and it just compares them as they come in and if the New one that just came in is too different than the last one that it has then it knows to raise an alert
And When it raises an alert it detects that something is too different It's going to go up to the cloud and it's going to create its own alert bucket So up in the cloud We have one pile of images that is all of the images for the Palantir and it's being depleted they go through and they it Deletes images as it goes so the bucket doesn't grow unbounded, right? But then off to the side we have this event pile of images and once an event happens
We take all the images that are over here There's ten of them they get rotated and we move them over to the event and say alright Well now an event has happened We've got these ten images over here any time a new image comes in from the pie Then we put it in the event bucket up to a hundred. We assume that most events will finish in a hundred Images and these are all configurable course So then the final thing that the the Palantir does is it notifies me it sends a tweet to me
And lets me know that Sauron is in the house and he's after the knives, right? So Actually, once we're done it has to go and clean up those images that deletion that I was talking about That's Palantir's responsibility. So a pie running unchecked. We'll just fill a bucket to infinity and I'll get a
$16,000 s3 bill Maybe that's a design flaw. I don't know depends on how you're looking at it And then we have the responsibilities of the cloud. What does the cloud do in our app? Nothing? It's a cloud it sits there and the Amazon cloud says I can do stuff and I say no, right? Because the Amazon cloud has these like messaging services and it could have solved my little queue problem
It would have been great, right, but then you're kind of locked to that provider And that's also why I stopped using this gem this AWS SDK gem Well part of the reason so I started out using this to you deal with the s3 I was creating the buckets and uploading the images And it was quite handy in the beginning and I was recording my requests with VCR
I'm sure people have used VCR fantastic tool for that kind of thing If you have to record requests and replay them in your tests You can do that But I would much rather not if I have the option and it turns out that you do because there's this gem called fog Which is terribly difficult for me to understand when I try to read the code But I don't care because I don't read the code very often
I just get to use the code in this case. Actually, it's it's not that bad on the inside The the last time I looked at it was a couple years ago And so when I went back now, it's it's changed significantly But fog is fantastic and the nice thing the really nice thing about fog is I don't use VCR I can use fog mocks So you turn on fog mock and then you get your own little pretend s3 and you could just talk to your pretend s3 in your
Tests you can check the things actually got stored there And it's much easier than having to replay cassettes and bleak sets and track these giant yaml files or everything that happened again I'm not knocking VCR VCR is fantastic. If you have to do that thing, then you should definitely use VCR And so when I was making this conversion I went into my image service I was very clever and I encapsulated this in an image service inside my app and I deleted the AWS gem and I put
the fog gem in there and I just had to change the client and like a couple methods where I was talking Through its public API and then I was done. It works great, right? But then I switched all of the the VCR tests over to using mocks and while I was doing that I noticed that I've been using these kind of like Portland artesian objects throughout my tests, right?
And I wanted to fabricate them instead So I put the fabrication gem in there and I started fabricating objects so I could create them in kind of a reliably random way And in order to do that, I've got faker in there And so it's now creating my new objects and suddenly I've lost in a very deep dark wood Because I've just changed many things about my application and how it functions
And I spent two very sad days with just broken up and red tests and everything was terrible and it would never be okay again And I want to just stop as an aside here real quick to point out that you should only ever do one thing Ever in your applications. I Feel like I've been doing this a relatively long time and I have to relearn this lesson with every day probably like oh
Yeah, I was just gonna do the one thing but then I was fixing and then the other thing, right? And you think oh you just do these two things. No, you cannot do two things Do not do two things, right? You're like no they come in twos. No, they do not do one thing All right, and by doing one thing you will avoid spending two days in the sad forest of sad
It was terrible But I fixed it and then the forest was beautiful and I came out into the sunshine And my application was working again and I had green tests and I got to add some more things So one of those things I added was the API I talked about I have to have an API I decided to use grape to implement the API Maybe not the choice that anyone here would have made or not I don't know grapes actually kind of fun to use I enjoy it and I had to learn it for work because we were
Adding instrumentation for grapes. So two birds one stone so I have this API and The browser is able to hit this API to get the latest image, right? This one function there and then the PI is going to create the images It's going to send us a post to create an image in Palantir when we get a new image from the PI so
This is basically our diagram our architecture diagram at this point is PI sends a post and then Palantir to everything Okay and I'm going to describe everything here for you because keep it simple is really pretty important to me when I try to build things Right, like I try to keep the PI very simple. So naturally when you're keeping it simple I'm sure we're all thinking the same thing. You want to use rails callbacks as much as possible, right?
you want to just stack these bad boys in there just Callbacks on callbacks on callbacks. You can see where this is going. I still can't believe that this train is a real thing. It's so awesome Somebody please get a Lord of the Rings train. Give me a ride So the new image comes in right we send this post over here and Palantir has to create this event, right?
Sometimes we don't always create the event, but if the different eNOS is too much then we create an event, right? So we've got this little callback when those those images come in we create the event Conditionally right and then we also have to copy new images to an event So a new image comes in We have to create the event if we don't already have one if we do have one that we copied the image that was just
Delivered to us over to the event that's ongoing right assuming that event is still open. So it's pretty reasonable. Okay Images also will delete the oldest images. So we get that rotation I was talking about what we go through and drop the last image those ten images so We've got these callbacks on an image, right?
Three not terrible. Let's talk about the event here. We create an event An event needs a name, right? The event has to have a name that's unique across all of s3 So it gets its own little bucket name We generate a directory name for it when we're created and then we actually have to create that directory as well, right? So we we go up there to s3 and we hit the cloud and we create that directory
And when we create that directory, we've got the callback here. We've generated the directory name We've got a callback to create the directory Then we've got to copy the existing images those ten images over to the creative directory, right in case There was something there. We want to keep track of so now we've got three on the image and three on the event We're still going and now we assign the last image that came in to the event so we can keep track of the image
That started the event So finally we send a notification off to me on the internet and we have five callbacks For the event and we're keeping it simple, right? I mean all that happens is this Right here when the event comes in you hit the API and then these eight things go so
If I were to do this again, I would probably choose anything else ever It was really terrible And maybe it's just because I'm bad at rails I'll admit like I mostly live in the Ruby world and I work with Ruby all day and I don't get to play with Rails very often, but man this was terrible
So if you have recommendations of alternative ways to do that thing, that'd be great. Why don't we talk later? I Surely could come up with some manager object in there or something basically like I consider using callbacks in that way that I'm like Hiding the existence of some business object that I really need or maybe an event system anyway So I want to tell you How you can get a sauron if anyone is interested in having a sauron of their very own has anyone noticed if the little?
Red light is blinking up here. It's blinking at you sauron is winking. He loves you, okay? So if you want a sauron of your own They're actually really pretty easy to get you can pay $40 to these nice people who make This awesome hardware, and you should pay them $40 for no reason, but if you happen to they will give you this thing
Which is awesome And this actually pictured is not the correct one, but they'll give you an a and a camera for 40 bucks It's a pretty good deal, and then you can go and you can get the web app Palantir feel free to mock my code privately keep your thoughts to yourself. It's terrible, and I feel bad But no actually if you want to make pull requests, that'd be great
Constructive criticism. I also have another app out there another repo. This is the palantir repo I'm leap out on github as well. Good luck, and this is all seeing I that's the Repo that is all saying pie, but didn't get renamed when I changed the name over I'll rename it later today when I get back
So with that I think we should probably start a live demo of course using these Two application components in the cloud and the Wi-Fi and everything will go fine. I'm sure So if we look over here, let's see if I can escape out of this And now I need to un-mirror. How do I un-mirror? Someone knows this it's command F1 is the thing
Who it is did I do it first try? God I'm so smart, okay? Hey look, it's you on the internet Hooray, okay, so we've been taking pictures of you here Over in and Eric's moving into the cloud, and I hope it didn't catch you because it may have triggered an event so
What the image is doing now? It's taking pictures of you over here in this side of the crowd And it's comparing them one after another and dumping them into a new event. There's Eric just jumped in there And those that new event that gets triggered happens by too much change in the image So I'm going to give it another couple images here to get Eric out of there And we're going to look at like normal image right now. Okay. This is our training now in order to do this
Right now it has an event already that's open and it's saving images to it So I need to go and close that event so I'm also just going to hop in here to this console on Heroku You know live because I have to and there's my event and it is not closed, so I'm going to
Close it I'm going to set this last event to closed so remember that an event is created when two images are two different right and So if I were to have just turned this thing on it would have taken the image from the hallway where I was testing it Before my presentation and compared it to the image of you right now and immediately fired an event Which is obviously not what I wanted to happen
Well, I want to happen is I want to save this event And close it and now the new images are coming in and this should assume that everything is fine for now It's not going to detect that there's been too big a change in the image because it's just looking at pretty much the same Thing when it smashes it down that little eight by eight pixel image, right? So
Now if you all would please stand up and give more of a Friday hug gesture than you are giving now And we will try to change the information significantly enough and see if a picture loads. We're waiting There's a picture of you still not moving Waiting on our API probably a couple images have been taken out and this looks pretty different to me
This room is not at all committed over here this side is like you guys are nuts I am NOT going to be involved in your tomfoolery and it looks like we don't have our new image Okay, did it blink to the red light blink at you? All right. Oh Well, well, I'm gonna let you guys sit down then I tried but I'll show you what would have happened in an event
Normally, how's that? So we have these images coming in and down at the bottom of our Application here. We have some events that I took earlier Like let's see. Here's one and when the events are created they are populated with all the images copied over as they come in and
You can see that they line out all of the images as they pop up and I'm really sad that we didn't get it To change why won't you change? I'm just gonna put a thing in front of it here and see if it'll ever take a picture again If it does it'll get a picture of my badge and then it will tweet a thing
So the idea is it's taking pictures of you now sitting back down again. It just didn't like the different units Okay. Well, let's go back to the talk here. So that's the app That's the app of Palantir where the images have been uploaded and we have pictures coming in from the hallway It'll be out there again later today if you guys want to come by and play with it. And this is
Let's see The future of this app step one make it work. Oh Yeah, I think that's someone is Tweeting at me on the internet and I have had the Twitter open I should go and turn off Twitter right now actually because you guys are a bunch of jerks and I know better
Than to do that. Yeah Yeah, I know right, okay So The The bit where it didn't work just now. I think I have to figure out first of all, but
It does notice when things have changed in the image and maybe we changed too many things I don't know but that's the first step and also we're going to have a faster setup process in the future So getting this thing rolling is actually quite difficult. You have to deploy the palantir app to Someplace online and then you have to get an API key out of it and put it on to the Raspberry Pi and you're like
SSHing into the pie and manually adding King fake files and I think I could simplify that whole process quite significantly the other bit of course is that we have a lot of data now about images and having distances and we could Store all of that stuff and probably learn from it So you could learn times of day when things were an anomaly or not
Where you could learn what particular things in the image happen to look like like maybe you're triggering your hamming distance on your cat But the cat always triggers the hamming distance in the same way because it walks along the floor on the bottom And so you could learn to ignore those types of things And finally as I mentioned I would like to fix everything
In the app there. This is also the camera bit that I'm using is particularly slow So the raspi still utility that comes on the pie Takes pictures about a second apart and it takes a long time But then I have to push it up over the API and there's a faster way to do it
There's an app called or a utility called raspi fast candy Which is a demonized version of the camera that you just send a user signal to? And it'll take a picture and it can take pictures like sub 10 milliseconds So I can take many many pictures very fast and upload them as quickly as I take them And they do end up being quite small plus I get to have a demon inside of my Lord of the Rings application here
so Thank you all very much for coming. It was a pleasure This is Eric earlier on the camera when it was emitting events And I will leave you staring at my Palantir up here or not because I can't get it up I guess I have rather a lot of time am I mistaken did I go really quick?
Anyone had any questions about how this thing went together now would be a good time. Yes, sir. I'm gonna call it done Thank you all so much for coming