BUILDING A HOME SECURITY SYSTEM WITH ELIXIR AND NERVES by Arto Bendiken

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right as I said nerves what is nerves let me recapitulate some of the what I told you guys to two years ago and give updates so a lot of you probably have played with Ruby sorry Alex are in addition to Ruby it's a lot of how to say changeover switch over between these communities crosstalk let's actually see how many have used Alex here that's a good amount I would say a third maybe has anybody used nerves one good good good want to talk to you after so I think that the killer app for Alexia is not Phoenix as often people say Phoenix is just another web framework it's a very cool one and it's a very good one but there's a lot of them I think what really makes Alex Erie unique is nerves and nerves has been around for quite some years now but now they finally reached 1.0 last year and the previous time I talked about it we were still pre-release but now it's 1.0 and it's definitely ready for all of you to play with so as I hope to show today it's really easy to get started and you can do a lot of cool things and so what is what is nerves no nerves it's a very simple concept how about when we develop embedded software we could just ditch the whole legacy stack just wipe the slate clean and what would we put it in is in its place well we would start perhaps with Linux as the ultimate collection of device drivers that's really what Linux is if people want it to be something else that's great but that's that's a good description of it so Linux gives us a hardware abstraction layer to just about any hardware then let's put on top of that the Erlang VM OTP who has you Erlang mm six people will admit to it okay so Erlang as a language is not very interesting sorry to say for those who like it but as a platform it's rock solid so it comes from Ericsson in Sweden originally it's been developed for 30 30 years and it runs nine nine systems systems that can't tolerate downtime and need live code upgrades and just can't go down so it's a pretty pretty nice basis to build on and of course a lecturer runs on top of Erlang and the OTP platform so nerves very simply is the mechanism for combining all these ingredients so that you can build cool embedded solutions let's say in in Aleks serum you know in a functional language and it's actually it sounds like it might be big you know Erlang heavy industrial kind of stack but no the minimal firmware image that you can ship on a Raspberry Pi or even a far smaller device than this is only about 12 minutes so 12 mega set contains the Linux kernel it contains electro TP Lang all TP your application and a lot of supporting libraries for nerves it's incredibly small and it makes sense if you think about it that every Lang was developed to run on telecom switches and to run reliably so two typical choices for playing with nerves would be of course the Raspberry Pi various models and also the Beagle bone I like the Beagle bone more myself because the Raspberry Pi actually is a somewhat closed platform it might be surprising but you have to run a lot of blobs for the Broadcom Wi-Fi drivers and so on so you don't really know what the hard way is doing you don't really have transparency the Beagle bone on the other hand is a fully open source design you can go to production with modifications of the Beagle bone if you're missing something you can add it and have a have the Chinese manufacturer you a new version of the BeagleBone so I like the BeagleBone but today we're gonna use the raspberry because it's by far the most popular platform so as I mentioned it might not seem abuse that something that people mostly use as far as most people know mostly used for web development could be good for for embedded development it certainly wouldn't be the case with Ruby I mean you you wouldn't really you wouldn't really want to put Ruby on a raspberry or a smaller smaller device I mean you can of course you can do anything you like it's Turing machines all the way down but you probably wouldn't and elixir inherits this from from Erlang so it turns out to be very very good for that so I'm going over pretty quickly this general stuff you can look at the slides later and of course on the notes website because if you're gonna do some live coding it might be prudent to reserve time for that so nerves commercial products have been shipping already for a few years and I don't actually have the current stats on how many have shipped but I assume it's millions by now it was still thousands the last time I spoke about nerves so for example here is a radar product that's running Erlang OTP and and nerves and really tall megabytes means it can fit on a lot smaller board than than this huge huge clunky thing this modern incarnation of a PC I didn't take with me today a Raspberry Pi zero but it's about yay big it's size of a business card and you can run nerves on that that gives a lot of possibilities so let's let's do some live live coding and the way to start is is really to do the blinky application it's the hello world of embedded that's maybe minimize the slide stir it stirred actually visible let's make the font larger so I have already checked out on the desktop here the nerves example repo and it's got several goodies in there let's start with blinky so blinky blinky is very simple the Raspberry Pi and most of these kind of boards they have a couple of LEDs on them and you can blink them from software so normally when you develop on the raspberry you would want to connect an HDMI screen but that's a little impractical and this set up so we can just use this led to see that our stuff is alive that it's booting up that it's doing something and the way we would do it here is it's not big enough for everybody to see if you can see you need to yell and I'll make it bigger so let me let me clean up this little bit and I'm gonna remove the build artifacts so that we can see the structure of the repo so there this is our typical nervous project here we have the biggest directory is the config directory where you have a target specific configuration so for example our PI 3 is what we're going to run lib as with Ruby that's why you put your code most of it anyway so here it's a single elixir source file then we have the equivalent of the gem file for Alex here and mix he accesses and the lock file and we have our release configuration for OTP that's not something you would normally play with too much and then finally we have a route route FS / / lane root filesystem overlay where you can add additional files that will end up on the firmware image and then of course a test testing directory so if I switch back to the slides are a little bit wrong from browser let's see him the edit mode okay so those are a couple of terms to know so when we develop in embedded not just nerves you would normally call your laptop you would call it the host and your target devices the target and you can have multiple different targets where you run your software so for example we can trivially make this application run on BeagleBone on raspberry three raspberry zero and a number further other things and the other term to know is that the the software that will be assembled as a result of this and that we will put on the SD card over here there's a little SD card here that's called the firmware in this case it's nothing special it's just software but the traditional name is firmware for that so I showed you the the project structure and let's go ahead and actually build build this little puppy so the way to do it is because I just deleted the I deleted the build artifacts that I had already cached we gotta get our dependencies again so this is a normal elixir process same as bundler so now we have our dependencies and then we're gonna say mix firmware to - go ahead and yeah to build it and this application doesn't run because it's actually controlling hardware it doesn't run on the host some nerves applications can run on the host so we need to set here mix target equals our PI 3 and so now that's in my shell session and novice knows what target to build from before so we try again and let's see what did oh yeah okay I should have done that before sket so dependencies can be specific to a particular target and indeed as you see now we we get a lot more things and so now now we got all the stuff we need and now I'm going to build the firmware and then we are going to burn the firmware to to the SD card so I'm gonna disconnect the raspberry for now and this is I'll show you soon a better better method to do this but this is basically what you have to do you have to take out this little little thing easy to lose that's a 30 32 gig SD card and of course that's got an adapter to fit into the laptop and we'll put terrine meanwhile the firmware has built and we can see how how big this this firmware is so we have a dot FW file and that looks to be about 28 Meg's so that's pulling in a few more things on top of the bare-bones 12 mix so think about that for a second I I just built a firmware image that's less than 1000 the size of this SD card if I wanted to do some embedded development with Linux a typical recipe on install is gonna be a couple gigs so they're on a different level here and almost any application you would make with the nerves the firmware is going to be less than 100 Meg's so you you're really ditching the bloat okay so now now we are ready to burn and the command for that is very simple a mix film web burn burn and that's very user friendly it goes and looks at my attached volumes and it goes ahead and finds my SD card and then it's gonna confirm that I want to wipe it and and it might even prompt me for a password I think I adjusted my permissions a little bit so it's doing some final things and now we confirm we want to burn it and indeed it put my demo password here and then we can remove the final product so that's the that's the old-fashioned way to develop you have to do this 100 times a day and this is how it was two years ago and of course this is easier with photos with small fingers it's a pretty tight fit so let's find our power cable and let's see that's not gonna be a very bright LED hopefully you can see it it's another small thing getting to the age where I'm nearsighted soon so hard to see these things there and now Linux is booting up after that Erlang Erlang is booting up OTP is putting up and then finally control transfers to our application and sure enough there you can see a blinking LED so I know it's not very impressive will do something more impressive next but that's hello world of embedded and it's nothing to fear get yourself a Raspberry Pi 40 bucks at the most and in 10 minutes you can be up and running with this it's not not at all something to be frightened of so let's let that blink away and I'll show you something something I have been working on as a more practical application yeah so actually one more thing to do is show you that was the hard way and now there's a much easier way so this this little board is now connected with Ethernet to my laptop and we have a private network between us you can also use Wi-Fi but it tends to be in a new place it tends to be a little bit of a pain to configure and you can use also Ethernet over USB which for some boards works very well so what I can do is first of all we have a dynamic hostname that it's syrup so I can ping my little Linux board here and we can log into it with SSH there we are I'll come back to this soon but I had a special key here let's see if this keyboard will let me know okay kill that yeah I have a few dead dead keys on them on the MacBook as I said I'm very frugal so maybe I should replace it eventually yeah I'm missing some keep finding there okay that's gonna have to be a hard kill like that sometimes you have to do what you have to do yeah so let's let's go ahead and show you the process these days this is what I do most most days now I don't fiddle with this little card anymore so we go back to our example blinky and there we are and now we do this so this is going to generate a script for us to do oh yeah I gotta set my environment because I heart killed my shell so yeah there we go so now we have an upload SH script and we can simply run this whenever we want to update the firmware on the on the board it's it's super easy and fast it will make an it it's doing an SSH connection to Linux and it's overriding one of the boot partitions one of the firmware partitions on the on the device so nerves has a very clever although very typical in embedded space clever clever partition layout you have a and B partitions for your firmware that means that you can you can flip between them when you do upgrades and if you upgrade for some reason kills the board you can switch back to the to the a odd or B the other other finger and recover from it so that's the way to to develop now it takes a couple seconds to do a new firmware and you didn't catch it because it was only on a table but the board rebooted and still blinking away so that's good so that's the that's the gist of it and looks like I'm taking a lot more time than I thought so let's move ahead so this is what I wanted to show you guys today it's definitely a work in progress it's got rough edges I was trying to kill one bug today just before the presentation and didn't so it's definitely got a few few bugs but let's let's do a little bit of a demo so I'm going to burn another firmware to the raspberry that's going to take control of the camera and we're gonna do something interesting with that so I have a little project here and let's go ahead and in this case I have actual so this is setting the same environment variable we just saw export mix target and we kind of build this this project and then we're gonna burn it over the air to the board and then we can do something cool so let's see if this works fingers crossed and I'm going to also have a special guest appearance of my lovely wife and and Dvorak baby so hold on for that so you're the build build process does take a little bit of time still it might be might be a reason to have a faster faster computer if you do it 100 times a day so this is a little bit of a bigger finger image this is actually I based it off something called a farm but farm but like a farm robot an American company who are developing very cool automated farming robots based on nerves and they their base image for nerves it's got some good stuff for computer vision because they need to differentiate between the different kind of plants automatically so I use their base image and it's a little bit bigger now the firmware is even 47 megabytes it's huge and let's upload that I think I already have the upload scripture so we are upgrading partition a there it goes and now the board is booting and since I don't have an HDMI monitor in this case to I'm going to rely on when it starts blinking I have a special addition to the firmware that it will do a heartbeat pattern so I know that it's alive it usually takes about 10-15 seconds for a raspberry to boot some some other boards are faster that looks like a heartbeat probably too small to see okay and then we are going to to connect oops nerves local so this gives us an interactive elixir accession to the board and here we can hear we can see what's happening for example with the log so I'm gonna attach to the log stream and we can print all the log messages that were already output so for example we see that it got a network interface with the HTTP from the host and now what it's doing is it's actually capturing live video here and we are doing a little bit of face face detection and recognition so let's have a look here we have a camera camera client that it's a little heavy Pig to start but it's Python it'll it'll start soon and that will actually let us see something yeah if I wrote it in Ruby it would be even smaller so yeah let's make sure it's actually lost connection okay what's going on here I okay I need to be forced to localhost I need to say nerves local of course I probably should have done the other default on that and started again okay so here we have a live video stream this is super damp and and quick and dirty I'm basically streaming JPEGs so I'm just grabbing frames from the camera and streaming JPEGs and I'm not sure so this is an interesting test I've I wasn't sure if it would crash here because we are doing face detection and there's a lot of faces here I don't actually I didn't have a hundred people to test with but looks okay probably because you're you're so small over there so let's let's see yes that's better and let's invite my lovely wife and people Rock baby number one and let's see what we can do is this murder yawning Kaleem and let's have a look it knows maryam does it no inc lee yes so that seems to work pretty okay so that's something you can do with notes so how much time do i have five minutes okay that means we are going to little bit run through the implementation let me kill the client and here this is the bug I was trying to fix today I have a no functional Clause matches I need to find that so so as I said this is a security system I would like to eventually deploy this at my garage my office my home and perhaps beyond and let me let me quickly run through some of the highlights so we already saw how to connect remote console this very cool remote debugging we can do with with Alex here it will have to wait for another session this local GUI based debugging tools that we can use to inspect the process would begin to that another time technologies I'm using here this are probably familiar to the most of you I highly recommend especially for people who are interacting interoperating between languages to check out G RPC it's it's a very good polyglot technology let's same so in this case it's a Python client talking to an elixir server so the camera camera driver here is a so here's actual code to show live coding so the camera camera driver here is not very long this is controlling a C++ program that's actually doing the computer vision under the hood and the idea with with Erlang and the OTP platform is that you absolutely do not put unsafe code into your safe memory space so any anything you're gonna do with dirty languages like C and C++ you you do that in a subprocess and if that sub process dies who cares you'll respond it and off you go that's a very very good way to build reliable software and the the Erlang platform will stay up without any any trouble so don't have too much time to delve into particulars I will mention that this is a those of you who have used Alex here and maybe played with the state machine support it's a very nice use case for Chen state machine because of course what we do is first of all the this is a state diagram of the of the siren so a siren can be on or off it's very simple it's I don't making sound though it's a silent and can transition between but then you can also model the whole alarm system as a state diagram this is not finished yet this needs a little bit more and thought but you can see here for example that when you have an armed system and it gets triggered by somebody climbing in the window countdown starts and eventually a timeout is reached because there was no authentication and then we have an intrusion so we move into an intrusion state and then we would start the siren for example so I can after the decision I can give more details to those who are interested I think the probably pretty short on time for the particulars we also have a API it's a very simple home home API here that is defined using protocol buffers and G RPC so that's the interface definition for for the API and that's the code generated into Python and it's code generator into LX ear and into Ruby if you like and it means you can write scripts and programs to interoperate with your alarm system and home server and yeah there's a lot to say about face recognition but maybe that's another talk so have a look at nose if you're interested hit me up if you have questions and for those of you who are not into Alex here but maybe into go I've recently become aware of this project this seems to be inspired by nerves or at least very similar so I haven't tried it but might be cool for those of you wanting to go and chuckle you [Applause] right on time hey hello yeah my name is Vadim here you try to connect your alarm system to some locks I don't know some door locks not yet but I'm very interested in that I I hate how many keys I'm carrying around and even though of course we all know about the Internet of and we know what happens when these digital locks malfunction as with the recent case with the nest thermostats and locks I think we need to move to digital locks so I'm exploring that as well one more question Hey Yaroslav here great talk wonderful software at least it what it wants to be I'm wondering with face recognition do you have do you need internet connectivity or are you using any online services like Amazon or anything like that to do the face recognition or is it done everything inside of the Raspberry Pi using your algorithms onboard this is this is fully offline you can this is using something called face net which is a research paper and result from Google so it's a it's a deep a deep neural network that uses one shot one shot learning it means that instead of the usual tens of thousands of images that you have to give our typical neural network for it to learn there's already a base data set and you need a single picture of person that you want to for example authorize for the alarm system so this system had a single picture of me a single picture of the baby and of my wife and that's enough to get 99.8% accuracy impressive Thanks indeed thank you so much it was a great day mail today and we have a special present for you Arthur thank you so much round of applause for our toe [Applause] you
Info
Channel: #pivorak Lviv Ruby MeetUp
Views: 2,606
Rating: 5 out of 5
Keywords:
Id: oyNSmhkS7Dw
Channel Id: undefined
Length: 31min 17sec (1877 seconds)
Published: Thu Feb 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.