Azure IoT Central, Raspberry Pi Air Quality Sensor, Visual Studio Remote SSH

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my name is Dave Glover I'm a cloud developer advocate at Microsoft at lambaste here in Sydney Australia the the scenario is building a raspberry pi air quality monitor solution and I'm using something called IOT central and I'll kind of give you a bit more context in a moment this whole scenario was based is based on the air quality so I think a lot of you are based here in Sydney Australia and this was a photo I took from my balcony probably about three weeks ago the height of the pandemic lockdown and I'm sure you've all probably noticed the air quality across Sydney has been pretty decent really nice in fact I've seen blue skies like we haven't seen for a long time but if you remember back six months ago at the height of the Australian bush fire that across Sydney and it really crossed a lot of cities a lot of places across Australia and the air quality was pretty awful and this is a photo taken from the same location and you can see that Sydney is pretty much blanketed in smoke and I set up this thing called a particulate matter sensor and you can see that I had a recording two levels of particulate matter so the one that which is called particulate matter 2.5 which is not a very good number because this is that the the size of the particles it can actually be absorbed into your bloodstream the PM tends not so much they just don't make the environment look so fill so great so you can see here that at the height I think this is on the 10th of the 12th of 2019 so just over six months ago that the particulate matter there was close enough to a thousand so 933 it's a super dangerous level and to kind of give you an idea what the kind of healthy levels are it's kind of between 0 and 10 is kind of what we should be gunning for and you can vote you can look at various monitors across across the city at the moment from the New South Wales government and you can kind of get a bit of a sense of what the air quality's like but as you all know the Equality is actually pretty good across Sydney at the moment just really from a lack of transport now when I built the solution what I built it on was on a Raspberry Pi and I'm using the sink with Navarro and Varro and borrowed plus hat and it has a sensor on it called a PMS 5003 and it's a special sensor on it it's I think it's got a laser beam and basically it watches the size of the particles going across in front of the laser beam and they can kind of count how many particles per per cubic centimeter or something along those lines and then so I was running a python-based application on on the Raspberry Pi and had that sense attached to it and then what I'm doing is I'm sending that information or the the telemetry from that device across to IOT central and you can see over on the right-hand side I've got a IT central and there I was just charting the data now if you look at that data the data is basically as of a couple of days ago I think so the data is actually not particularly interesting because you can see that the particulate matter recordings are pretty much zero which is a great place to be but not so interesting in terms of the data for the demo and just I've also point up there is that with IOT central you can sign up for free there's a free trial I'm going to show that at the moment and you can also run two devices for free kind of forever well one listed forever but for a long time and so just just kind of keep that in mind now what it's going to do is just talk a bit about where IIT central fits in to the schema things inside Azure so IOT central is a solution or an application that Microsoft has built that makes it easy to go off and build IOT solutions particularly the cloud side of an IOT solutions so things aren't reporting data analysis being able to extend it into other systems and things like that so it's a solution and the same way that things like office 365 is a solution you just go and start using outlook a word or things like that azure IOT central is the same but it's 4:08 ntral I for IOT solutions a just go away and basically define how your solution will look but it is not the only thing that we have inside as your for IOT but I just wanted to highlight a couple of things in here so just in the middle we have these kind of what we call this they're called solution accelerators and they cover off kind of the majority or kind of a good subset of the kind of scenarios that we see for IRT so there's a remote monitoring predictive maintenance etc and then down below in the bottom box you'll see there's a whole range of solutions so services there's something called IOT hub IOT edge there's some device provisioning service and the data area there's stream analytics there's Cosmos DB for visualization there's power bi Microsoft flow and all those types of things I'm not going to go into any of those other than to say that IOT central is built on and uses IOT hub under the covers and it uses device provisioning service as part of that solution and it also uses as your time series insights so just keep that in mind those are the services under the cut that kind of underpin as your iot central and then just really I just want to cover off like the end super-high level the kind of the anatomy of an IOT solution so you'd normally have devices and in this case the device is going to be a Raspberry Pi it could be a microcontroller for that matter it could be a mobile phone I know a lot of IOT solutions which actually talking directly into azure IOT hub it could be a desktop computer kind of sending telemetry up as well but normally it's some sort of device that's that's got some sensors attached to it and then that information is going to be sent up securely up to IOT hub and then you would store it or you'd stream it or you'd analyze it you might push that data into a machine learning model for example to go and train up machine learning and the whole idea behind it is your things you've kind of got insights and you actions and that action could be Hey look I'm monitoring the temperature of a refrigeration unit and I want to send a message back to the refrigeration unit to say how you need to reduce the temperature off of the device so that's that's the kind of idea behind it and and as I said underpinning IIT central is fundamentally this model now so just to kind of give you a bit of a sense of IIT central so one thing it's fully managed you don't have to go and set up anything you just basically have to sign in and it's there it's no code so you have to go and write any code server-side it's basically a web application and you go and define it you can go and define things like rules and triggers you can extend it so as a data flows into IOT central you can go and do things like charting that data but you can also extend it so you might push that data into a into event hubs or you might store that data into a sea of storage or things like that and there's analytics dashboards and visualization super easy to get up and running with and that's what I'm going to kind of show you at a moment and as I mentioned before this is the chart this is the data that I would maybe I want to better get out of the device and chop this up so the first thing I'm going to do is just go through a bit of a demonstration about how to go and build an IIT central application so I'm the first place to go to start with it you just go searching for azure IOT central and finally a search engine of choice don't click on build a solution and I'm already signed in so my apps and I go and create a new application a custom application I just go and give it a name name your app and you can go and select free put in your details and go and click basically click ok and it typically takes around about 30 seconds to go and provision a new IOT central application now rather than us watching for that 30 seconds while it's doing that I've basically created a trial already and this is the free trial you get seven days and then you can migrate it to run two devices for free on an ongoing basis so the first thing you'll see that there's a dashboard and you can go and customize that dashboard and I'll try and keep a bit of an idea on give you an example how to customize it shortly as well but the first thing what I'm going to do is set up a device template now before I do that I just want to bring up something I'll just move I've got visual studio code over here so you'll see inside Visual Studio code if you're familiar with Jason this is a JSON string and you can see in here that I've got temperature and humidity I saw a device name and humidity and you can see I've got the value and things like that so what I'm going to do the reason I'm kind of explaining this up front is the way this works is that a device will send up to IIT central a JSON string with a telemetry in it and then what I'm going to do is map that Jason telemetry into IOT central and that's kind of what I'm going to do now so I'm going to go into here and create a new device template so I'm going to set up a an IOT device click on customize and we're just go and call this air quality monitor click on review click on create it takes a moment to go off and create that now what I'm gonna do is just go through and show you a couple of a way in which you can go and create your own kind of custom model so what I'm gonna do here is add an interface and we're going to make that a custom interface and then I'm going to add in a model basically a capability and the first one I'm just going to say temperature in fact just to keep it consistent if I jump back to visual studio code you'll see that I've got temperature and it's a lowercase T for temperature and you just got to make sure that you you have a lowercase in this case I know the the I want it I want the display name or what the fete on so I want that to be lowercase it's to be it's to be of type telemetry but can be a property or a command and there's something called a semantic type and you can go and say I'm gonna select temperature and you can go and select hey look it's a float it's a double it's an adju so long you can say look I want that in Celsius and I want that to be a display unit to be see and I can carry on doing this and I just say this one here is humidity and the same principle over here come over here select humidity and in this case here it's percentage now I'm not going to go through the whole process of doing this for all of them so I'm just gonna click on save and that's kind of fundamentally how you go and build these models so what I'm doing in here is I'm mapping in the the names here to the JSON document in fact this one was a lowercase so jumping back over here that's kind of what's going on so I've got humidity and temperature and that's been mapped to these names over here now I'm going to delete this I'm gonna delete that template as well and we just go through and create another one so we go through here and I'm going to call it air quality again air quality monitor click on review click on create now this time I'm going to import a capability model and you'll see this capability model and that on my github in the project solution and what I've done here is I've just imported and what I've already created before but rather than you having to go through the pain of watching me I'm going through setting up this capability model I've kind of predefined one and I've just imported it and just so you can get a bit of a sense of what they look like I'll just go over to my github here this there's a JSON document and you can see and hear that capability model is just a JSON document and you can come through here and you can modify it yourself as well and you can see in here there's a that's type telemetry and you can see the schema type is integer you'll see double down there etc so that's kind of what's going on and what that carrot Carrick read that that the template the interface and the capabilities on that interface so the next thing I'm going to do is I'm going to create a view and I'm just going to come over here to visualize and I'm just going to pick up on humidity air pressure and temperature and then down the bottom here you'll see add tile and then the next thing I'm going to do is go and add and the particulate matter for 1.0 or for some reason actually I think I've got a mistake oh no that's 10 and 2.5 and add a tile for that and I'm also going to add in 1/4 message ID message IDs literally just an integer that just it just kind of gives me a sense of how many messages have been sent up to IIT central it's just a way of keeping tabs on that and you can go and change this so you'll see by default it's a line chart in this case yeah I just want last known value and I can go and change the size of that tile and just drag that over there so it's all nicely lined up so hopefully kind of gives you a bit of an idea how these things work and then when I've done that I click on save and then the next thing I'm going to do is publish that template so hopefully that kind of made sense how I did that so I'm just publishing out the device the interface of capabilities and that view that I created so what I'm going to do now is go to devices and I'm going to come over here and I'm going to create a new device in IOT central I'm gonna select air quality monitor and I have a name that I'm going to use so just bear with me and I'm display:none I'm going to use is raspberry pi and Bar n plus Omega off and create that so what I've done now is I've created my first device inside IOT central and there are by the way ways in which you can automate this or kind of important lots of devices but in this case we're just going to keep it simple and we just created one device and you'll see that it's come up here and it's brought up that template that I've associated with this device and obviously I haven't started the application yet so there's no data to be shown and the other thing I'm going to come up here is click on connect and then connect we're going to jump back to this in a moment but you can see in here I've got basically the the connect the connection information that I need for the device to connect until IOT central because obviously what it is secure and you need to configure the device with the credentials since you're going to be using to connect to IOT central so hopefully that's pretty pretty straightforward so I went accredited device template when I'm there I defined these properties are these capabilities I Shh I should say and these all map to this JSON document that's going to be this JSON string that's going to be sent from the the device that I'm going to be creating in a moment ok so I'm just going to jump back to the slides so that's the IT central and how I created that ok so the mix but I'm gonna do is I'm going to show you how I built the Raspberry Pi solution using Visual Studio so Visual Studio code in fact let me just fix that while I'm on there that should say Visual Studio code because there is a distinction and I'm using something called remote SSH development so as I mentioned before I'm going to be building a solution on a Raspberry Pi and I've got the sensor here and it's Wi-Fi connected into my home network and that's how the data is going to be getting off this device and into the cloud now the way I actually kind of run the solution is I actually built the solution on a Raspberry Pi version 4 which is a really capable device but actually when I ran the device actually ran it on a Raspberry Pi 0 so I actually just took the the sensor off the Raspberry Pi 4 deployed the solution on the Raspberry Pi 0 and that literally just said on my balcony and it just sat there and checked away it was obviously doesn't use much power and it's small and it kind of doesn't get in the way so it's pretty pretty neat so that's kind of what I did now I mentioned before that I'm using Visual Studio code remote development and just to kind of give you a bit of an idea how this works so if you've used Visual Studio code already you might have used it for building unknow Python applications or C++ applications on the desktop on your desktop computer and it runs on Linux and Mac and Windows with remote development the way it works is we've kind of split out visual studio into two halves effectively so there is one half which kind of runs on your desktop which is kind of the UI is the thing that you're interacting with the visual studio code you're writing your code and things like that and then there's a remote element that runs on the remote device and in this case the remote the remote aspect of Visual Studio code is running on the Raspberry Pi and it will manage the whole things like all the visitors to your code extensions that will manage source code control or the magic and manage to bug is all that kind of thing so even though in the demo that I'm going to do for you in a moment it's going to look like I'm developing this on my desktop what's really happening is I'm developing it on the Raspberry Pi and I'll try and make that a bit more clear as I kind of get through this and you can see here I've got Visual Studio code and down the very bottom on this slide here you'll see that I basically you have an SSH connection and but you're going to see this a kind of an action and a moment okay so what I'm going to do now is I'm going to jump around the place and the first thing I've got I've got here is I've got an SSH window too terminal set up to my Raspberry Pi so if I just go you name - a you can see it's a Linux system you can see it's Linux pylab the name I called this you can see the kernel so it's running on 4.19 and you can see it's running on an arm and if I go and do things like if you're reasonably familiar with Linux systems you can go and do things like that and you can see hey look this is running Buster Raspberry Pi Raspberry Pi Linux etc and if I just go and do ligo's the filesystem on my on the Raspberry Pi and I'm gonna change directory into github we'll just do a player on that and you can see these are the directories in here and what I'm going to do is I'm going to jump into a directory called environment and you can see that they go to files for the solution sitting on the Raspberry Pi so that was just to give you a sense of when I'm building the solution that I'm building it on the Raspberry Pi so what I'm going to do now is I'm gonna start up Visual Studio in fact I'm actually going to shut it down first because I've already got it connected okay so imagine I didn't have it already connected so what I've done and you'll see this in the in the tutorial you'll see how to go and set this up so I'm not going to go through this but basically you need to go and set up an SSH certificate that you push on to the device so basically manages the security between your desktop and I don't think we're gonna allow someone to have access to my desktop so what are we down the bottom here this is the easiest way you'll see there's a screen greater than less than sign and I'm going to connect to this remote SSH connect to host and you'll see I've got a cup of devices here I've got two raspberry PI's but the one that I want is a sink or grasping PI for B - edge and that starts up a new instance of Visual Studio and the first thing we're to do are so viciously a code the first thing we're to do is open the project so I'm going to click on open folder now what I want to kind of get across here is when I'm building this I'm not opening a folder on my local system on my local desktop Windows computer I'm actually opening a folder on the Raspberry Pi so you remember I had that folder called github and you remember I then navigated to a folder called environment and we're going to click on open ok for that so what that's done now is that's opening solution on the Raspberry Pi so the really the the fantastic thing about this remote SSH development is it gives you a desktop experience for building solutions but it's actually happening on the Raspberry Pi you can also go and use it for dock you can also by the way use Remote SH for for docker and for other Linux systems so W is cell for example the windows subsystem for Linux on Windows and you'll see down here on the left-hand side I'm hoping that you've already played around vegetated codes you're going to get a bit of an idea how it works but I've got a number of extensions and normally when you're building this you'll see that you have that you'll normally have what are called local installed extensions and you can see I've got a whole lot of extensions installed here locally but if you can see down about halfway through my screen you can see that I've got this SSH raspberry pi 4 B edge installed and these are the extensions that are installed onto the Raspberry Pi and if I just scroll down through here you see I've got extensions and they have a docker I have extensions here for Jason I've got the Python if I go and click on the Python and just go and highlight that it'll say to you the extension is enabled on SSH so the important thing about that is that this extension this registered your code extension is actually running on the Raspberry Pi and not on my desktop so kind of that's the beauty of this kind of remote SSH dev Visual Studio code now just make sure there are many questions not again it's gone so now I've got the solution open now just jump around a couple of other things as well I'm gonna show you this in a moment but I've got a docker extension installed as well I've got github so this solution is also checked into github whoops okay check click on the actual github extension so you can see these are the the files that I've made changes to the since the last time I checked it in and if I go and click on the Explorer you can see the files up here and we're going to open main dot pi you can see that this is the Python application that is that's that's the file that's on the raspberry pi and you can see that I can just kind of scroll around there I'm gonna set a breakpoint over here and you can see that I've got another class over here called sensor and this sensor imports this thing called the PMS 5003 so that's the name of the air quality sensor that I've got attached to the Raspberry Pi and then you can see there's just a bit of code in here if you're done a bit of python you appreciate that it's kind of the the initialization for this class or the constructor and then the rest of it this is a bit of code in here that the way that I do it I take a number of readings and then I Everage them so you can see I think I'm taking 14 measurements and then just averaging those just going to get a bit of value of that and you can see what I'm doing when I get my average I'm just dividing it by the number of samples in fact you see it's 15 I'm taking 15 and then you see I'm getting the temperature off the sensor as well getting the pressure and the humidity and then a bit of other magic and so that's pretty much how the solutions working so they gave it to main dot pi which is the entry point for this application now you'll see down in here where I put a breakpoint I've got some Python code in here and what I'm going to do is I'm going to grab an environment variable called scope ID another one called device ID and then one called device key and these this information is basically the connection information that I need from IIT central so there's a special file over here called env and you can see I've got the information on here now this information is actually out of date because it was before a previous version of IOT central that I had set up so I'm going to jump back to IT central and that's not good I have no idea why it's doing that you do not push in to create the section I think we'll just close that and I won't panic because I'm sure to work and I've got a number of apps so I'll just go and create the one just go to the jump to the one that I created I think it was that one look at the templates look at the device okay we're all good a moment of panic don't click on connect and you'll see I've got on here scope ID so I'm going to grab that scope ID come back over to the application I'm just going to paste that in the device IDs are saying my kind of you probably saw I use to pre-canned one so that's the same and then I want this key I'm going to close that and I'm just going to replace this key over here with that so what I'm doing here is just these are just the credentials that I'm putting onto the Raspberry Pi Python application it needs those to be able to securely connect to IT Central and then the first the next thing that I do is I'm going to start this application so over here on the debug I'm just going to make sure I can either do a remote attach or I can attach the current file and I'm just going to run that and then I'm going to press f5 and what this is going to do is this going to start up this application and you can see that it's now hit the breakpoint inside the Python application and if I step over this you can see in a moment when I go and hover over scope ID you'll see it's got the scope ID from IIT central just remember that's that's that value there so keep in mind that was it ends in four double for 98 so we'll hover over that we should see double for 98 the device ID as we know is Raspberry Pi and Vario plus and there's that key which none of us are going to remember and we'll just keep going through that I'm just going to get rid of that breakpoint and further down here I'm just going to set a breakpoint in fact I'm gonna set a breakpoint over in the sensor and I'm gonna set a breakpoint there so this code is going to be called in a moment so I'm just going to hit run and this will basically provision that that connection what's called do a provision so it gets me the connection string and then it will connect and in a moment he says it will call now for some reason so I hit the breakpoint okay there goes okay so it's hit the breakpoint now that delay was just the first time that delay what it was doing is was talking to IIT central Parsi across those credentials then under the covers what was being sent back was a connection string so it was just a bit of negotiation going on there and then I can just step through this and as I said before this is going to do this and measure this 15 times so it's actually going to hang in there for about 15 seconds because I've got asleep for one second and then we'll perhaps report a breakpoint there so we'll see that coming out of that breakpoint out of that loop and in a moment let's hit that break point I'm just going get rid of that break point not so we're not to confuse me in a moment and what you'll see is it's now sending up the telemetry up to IIT central and you remember I said it was going to be sending up a JSON string so this is a JSON string that's going up to IIT central I remember I had that template and that template had those capabilities that were mapping the JSON string keys basically to the capabilities aside IT central and I'll jump back to main dot PI and you can see that this application here basically sends telemetry every two seconds now this is way too much you know for this sensor and he doesn't like being read more than like once every 10 minutes and you'll see some logic in here that I actually stopped this sensor here tell me what I did but yeah you can see I'm hanging in there for 10 minutes 10 times 60 seconds that's just to stop that sensor because you can damage that sensor for if you read it too much ok so we've now got the the data streaming up to IOT central so what we're going to do now is jump over to IOT central and in a moment come across over here and you can start to see that the data is flowing into IT central now IT central though that data is going straight up into the system IT Central has like a cadence it doesn't update immediately it'll update every minute to a couple of minutes so that data is now kind of going up there and while it's going through through there I'm just going to jump around IT Center and just kind of show you some things you can do while we're in here so you can go and set up rules so I can go into final rule here and I can go and select the template and then I can go and select a map telemetry and then for example what I'm going to do is I'm gonna say if the till if the tulip temperature is greater than this to say 30 degrees then I'm going to invoke some sort of action it could be for example an email and I might want to send an email to somebody say hey look did you know that the temperature in this room is greater than 30 degrees or what I could also do as I can go and sell what's got a web hook and this is an extensive bility mechanism and you can extend these into as your functions something Microsoft flow or logic apps or your own application for that matter so it provides a really cool way of being able to extend the flow of data from the device into IOT central and then it kind of extending that data into your own systems that you might want to go and do you can also export the data so we just need to scare to that I can export the data so as a data is flowing into this into IOT central I can also go and export that data straight into storage for example and the reason you might want to go in and put that data into storage you might want to go and use the data for training machine learning model being obvious example or the other reason you might want to do it is from audit you might just want to you might have a customer or you might be building a solution for a customer and that customer says look I want to know everything that's that's come from that device and a really cheap way of keeping that data that's come from that device is into storage and for jump active devices and go to the Raspberry Pi and Vario plus you'll see that now there's a bit of extra data that's coming through and though there's not quite enough data in here there might be just enough there's also analytics so I come into here air quality monitor I can select the temp I can set the telemetry in this case temperature go and click on analyze and there's really not enough data in this but what this enables me to do if I go and select this and zoom in you can see here that I can zoom into that data now the reality is I've only got a couple of minutes of data in here but you can imagine you might have a lot of data that's flowing into the system and you're trying to figure out there's an issue somewhere and you know that this happened I know in this period and you want to drill into that data so you kind of get that so this is actually time series insights that's doing this has been exposed up through IAT Central so hopefully kind of gives you a sense of most of things you can do you can also do these things called jobs and in this case it doesn't make too much sense because I've really only got data flowing up into IT Central but you can also control devices from IT Central and so for example I might have a a relay that's sitting on this Raspberry Pi and let's say I've got a whole lot of real raspberry PI's and I want to turn the lights off I want us to turn the relays off you could go and create a job which says hey look send a message out to all those devices and turn the lights off that's the kind of idea and there's also administration here and you can go and customize it you can go and select an image - hey this application it's doing you can kind of brand application you can also come in through here and just remember will you do this you can go and customize the application so you can select an image you can go and change colors and things like that so you can do lots of customization to kind of make it a look a bit more your own as I mentioned before you can go and play around the dashboard as well so we're going to edit this dashboard I want to get rid of that and in this case here what I'm going to do is I'm just going to add in some more telemetry and I'm gonna select the device the Raspberry Pi and I'm just gonna pick on temperature again and why don't I why don't I give them this is a we've got the particular medicine so we're gonna add a tile for that and then you can have that something that the same so you can kind of keep stuff that you're interested in that you want to be without having whoops we'll just save that and you can see rather than having to go to devices then then drill down into the device you can just go across the dashboard and there you've got that kind of quick way to get at that solution and again if I go into analytics it might be a little bit more data that's sitting inside there that might make that a little bit more interesting no there's not really enough data in there so anyway that kind of gives you hopefully a bit of a sense of how you can use IT central and the Raspberry Pi and Visual Studio code altogether you
Info
Channel: Dave Glover
Views: 1,419
Rating: undefined out of 5
Keywords: msiot
Id: ayIrNB8gh68
Channel Id: undefined
Length: 39min 33sec (2373 seconds)
Published: Mon Jun 08 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.