Azure IoT DevKit send sensor data to Azure SQL Database via IoT Hub using Stream Analytics

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to the solution architect Channel today is gonna be a little bit a long video but I think it's necessary to show you the whole flow of how we seen data from the azure IOT dev kit sensor through the IOT hub we're gonna use the IOT hub as a gateway and then we need to then pull that messages using some sort of earth tool and we're going to use stream analytics on Azure to pull the data from IOT hub and then we're gonna stream that data then to from the IOT hub to the sequel database okay we are now in the in the portal for a Azure if you want to create a new IOT hub then we got to create resource you can either search for it here go to Internet of Things and you select IOT hub and I'm gonna use the resource if you don't have area so she eight means a resource just storage account I have a few already on here that I'm gonna use you can create one on the fly as well good good practice to choose one region and run from the I use waste in waste Europe and then the IOT half name so let's call it IOT hub [Music] okay and you can go to next you can scale it if you want I'm not going to use the 400 messages I'm just going to use a free tier for now the basic tier is its lace as well as a tiara but there is some disadvantages using the free tier you cannot go more than 8,000 which is okay we don't we don't want to do that right now and then you can review and you can create okay so now it's complete so we will go to cultural resource just to note quickly there's a few things that you can can do here well I think what's important to note is your access your shared policies will be in here this is a different policies that's automatically assigned if you click on this and you might not see everything here if you have a shared access key and you have got a connection string it's quite important to understand that this connection string that you have to enter when you use your your i OT a sensor def kit to connect to the ilt hub the other thing to to that's important here to note is that you can add iot devices here and I will show you how you add a new device here and you can also configure ith devices and in a later video I will show you how that how you can connect H devices to your IT hub okay so we back in on Azure and you go to your IOT hub that you just created and what we want to do now is add a device these are several ways of doing this you can do it by command line I'm not going to do it I'm just going to use the web interface to create a new device so new device you give your device a name so this there is options to create self-signed certificates don't don't do that just use the normal out-of-the-box just and that's all you do just to create your your dev key device and you'll see immediately that it created a idea if you click on on this there's no modules ad which means that you can create a module that then watch the messages come come from the IOT device to the IOT hub and this this is how you you link that also note that you have a primary key segment key you've got a connection string which is important that you copy this connection string here and you'll use this connection string to connect the device to to the IOT hub in order to upload code to the IOT dev kit you need to download the software - for the staff kit to be seen as a USB driver so you go to this link will be down in the description as well you go to this site and you click software download I've already done this you click the software you download it this will also then ask you for a license agreement you know do you agree and then we'll ask you to fill in details or not sure why but I've done it this already and the soft way that is download I'm gonna show you it looks like this it's a MX chips driver if you have 64 bits you run this if you have stole 32 bit you run this one and this will install the driver for you or you can just run the windows USB install bat file now you open visual studio code and what you need to do now is I've already added the extensions but what you need to do is go to your extensions and the first thing you need to install you search for Arduino so I've already install this you just install this because the code that you're going to upload is the similar to the Arduino code which is similar to C++ the next is what you need to install as well is the azure IOT tools so once you have that ins installed there's a few configuration settings that we need to do you can also install the azure IOT hub toolkit I've also installed that and will not worry about the i-th right now it's also nice to have the the azure IOT deep if kit workbench which which will show you once you've connected your device that will show you on this the window show you later that you connected to the IOT hub or not okay so after you've installed all of those things you go to file preference settings and you can just type in our winner you look for editing settings JSON file and you open that and you paste the following inside here there might be other settings here just just paste it in the bottom of what you have I remove some of my my settings here but I will add it after this video but this is important to add so you reference the Arduino URLs okay and then you can save it just by exiting will automatically save or file save I have fought to save once my my files will automatically save okay so the next step is to visual studio press f1 then you go to Arduino board manager and you need to make sure that you install the correct at the correct port so this is the MX chip and - already installed and you can can select a version the latest version is one point six point one and you can click install and that - already installs you click that install and that will install the image chip if after installation you'll see on the bottom they of your visual studio on this barrier you see MX chip is installed and mine because I've already installed the USB driver normally comes up on cone cone 3 when I when I plug it in so that's the next step so when you done with your installation you the in place if one again if you don't see this examples on your Visual Studio code press f1 and you can go to IOT device and look for the examples you select your chip and say this is the chip and it will open up these examples okay now what you want to do is let's just select a very simple example I'm going to click on open a sample create a new one call it my IOT tastes something like that you just put any name in there and that will then create a new card for you if you look at the left hand side here you've got a few files that's already that comes with your starter kit you've got a healer fall config header file not much happening there then you've got your utility either fall on your toilet tee C++ code and then you've got you can read me as well if you want but you've got the main code that's going to be uploaded to the device now there's a few steps that you need to follow to be able to do this you need to make sure that you updated the firmware and the way to it - and you also need to configure your device I wish I'll show you just now how to connect it to the Wi-Fi okay there's several ways and several tutorials on Google and Microsoft website that shows you how to do this you can either follow that or you can use my my guidance here so when you plug in your device there is a a B button a button and a reset button what you need to do to be able to see this on your Wi-Fi so you can connect your PC to the to this device you all the be in and you press the reset button that will then give you a config board on IP address 192.168.0.1 okay but but to see that IP address in your browser you first need to go to your Wi-Fi and see the Wi-Fi device does normally eyes eyes it you click on that and you connect and once that's connected you go to your browser I've done this previously but I'm just typing 192 dot and what you will see here is your your Wi-Fi that that is available to be connected and you enter your path your Wi-Fi password and once that's connected the wipe the device will restart and will connect to your Wi-Fi you have to set this up I'm not using the IOT hub connection string here this is a different way of doing this as well I'm going to show you that way okay now go back to visual studio code you should be able to now be connected to your Wi-Fi you might not or you might have something running on your device or not it doesn't matter we can override that using using this this code so the first thing thing you want to do is you want to make sure that your device is connected to your IOT hub and how you do that is you need to go copy and paste your connection string from from your from Azure so we'll do that quickly okay so go to your on edge you'll go to your IOT app that you have configured earlier you go to your IOT device that you added and on the IOT device when you click there you have your primary connection string okay I'll copy this and then we go back to okay good now go back to visual studio code there's one thing that you need to do before you upload anything to the device you need to press a on the on the device hold a in and then press reset what you'll see on the screen is it will just say give you an ID and we'll say configuration now that is a way to upload the connection string that is now ready to receive any configuration that you want to send to the device so you go into visual studio code press f1 you look for as your IOT device workbench configuration device setting and you'll see there's a few they what we all just use a connection string in input the connection string and then I'll just face that Enya please enter and you'll see configuration setting string complete now leave the device as it is at the moment now what we want to do just simply upload this this code onto the device now on the right top if you installed your Dino correctly this arduino upload and then it's just verify if you want to verify if your credit card is correct before you upload this will take a few minutes you click there and it will start uploading it you need to make sure that your device is connected through a compote you okay so what you will see now is that this everything is now uploaded the device will restart and connect to your Wi-Fi if everything works as expected you'll see a blue light coming on that's connected to your to your IRT hub and that will start sending data to to your IOT hub what you can do is you can click on on this open serial port monitor and this will show you what he's been seen back to the IOT hub its messages that's coming through to the IOT hub now what we can do is let's go check okay let's up as you're going to your IOT hopper and you will see that this already messages 14 messages that landed up in inside IOT hub next step is to read these messages and put it into a database okay so now to the mind what we want to do now is create a stream analytics job that will read from IOT hub and then take that messages and put it into a database so let's go start and create this to create a resource you can just type in stream analytics job and you can start creating one and you call it IRT and then you see I have the opportunity yet to do it either in the cloud which we gonna do we not you also can create a job that for specific age devices okay so when the stream analytics job is created and then you can open it in your resource and this is what you this is your landing page inside the stream analytics so there's a few things that you need to configure here to get this to work you'll see you've got inputs and you've got outputs and then you've got a query day as well and the first thing we want to do is create the input to understand where are we reading that messages from and this ad stream input if you click there you can you can get it from IOT hub and you can give it their name as an input stream and then you select your your hub that's available this is the one we created everything else is just default this will come through as a JSON file and you don't need any compression just save this as input okay we're going to create a sequel database go to sequel database add we call we need the resource group and we don't have a sequel server yet so we need to create a server for that as well called database name is stiff kids TV and we need to create a new server just make sure it's at the same location as your resource group so the name IRT Dave okay and make sure you change this otherwise you can end up with a really big bull you don't want to use for general purposes you're just wanting you have a really basic one I'm just for testing purposes to get good works out for year romance I next you don't want to see the in point right now just leave the defaults make sure you've got everything selected correctly make sure you read you know the same as your research resource group region and then create so that will take a while to deployment underway that will take awhile so I will stop and continue okay so just to quickly show you on sequel on the sequel database I created a script that this is the information that needs to be recorded from the IOT hub that's been seen from the ITTF dev kit this is a table so I just use this I'll leave this some somewhere as well for you to download but this is basically the script that you run and create a table on sequel server now we can go back to our stream okay now what we want to do after creating the database is go back to our stream and Analytics job and go to output we're gonna add the sequel database here they call it ad good stream so not sure if this is going to create a table for me I don't have a table of my database yet but let's see this is the database let's see if we can just enter a table there I a Dave gate driver what you need to now is editors query we need to to make sure that this query get the input from some way and put it into some something else so they just edit that so we have our input stream we call it input stream so from it input stream and then output is at the stream so the names you gave those needs to be available yeah you can save the query I don't think this will work because there's no data yet so that is your query you can have folders here as well by using having but we won't do that right now what we need to do next is we need to start this job and and see what happens when we start this job I'm gonna plug in my IIT device whit's start sending data to the cloud as soon as this job is created and I'll switch on my IOT device okay so just start my analytics job and now what I will do is plug in the dev kit and as I try this several times so they might be a messages to lying-in in this in this query okay so you'll see this message one it's coming through now so they will be probably more messages coming through you go to database and then you go to your query and there is your data inside of your database
Info
Channel: The Solution Architect
Views: 9,459
Rating: undefined out of 5
Keywords: IoT, Azure, IoT DevKit, IoT Hub, Stream Analytics, SQL Database
Id: G3srDunr79I
Channel Id: undefined
Length: 27min 19sec (1639 seconds)
Published: Thu Oct 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.