MQTT tutorial | send data to aws IoT core

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys so in this tutorial video we are going to look at how do we send the data from your local computer uh to cloud service which is your aws and specifically in aws we are going to use aws iot code this is uh there are three ways in order to interact with aws services one is aws sdks software defined kits other one is your aws cli command line interference interface and the third way is what we are looking at currently is our management console which is nothing but gui or some kind of a graphic or management console and you can see there are different services that is offered by aws itself now you can see here you have compute you have storage well we can interact with all of these services for our use case even if it is just iot so for example we can send our data or try to test it in iot core try to perform analytics using quick site or run our broker on ec2 by installing or initiating the server itself and then store our system or let's say if we have something called some some single page website we can just store that into s3 storage and a lot of functionality mix and match you can do you can perform lambda functions if something happens perform this file or store it or whatever with the help of rules we can make things interactive let's say whatever you're sending the data on iot core you can profile perform some kind of rules that stores in into database dynamodb or you can send the data over a static website being hosted on ec2 or lightsafe or some other dynamic websites so let's get started and i'm gonna show you how to initiate or get started with iot core so i'm gonna go on the service tab and go click on iot core it's going to take some time to load things and on the left side you can see there is a panel where you can just click on and the options will interact and what i'm going to do is we are going to get started with manage and things but before that let me explain you some some of the features of it whenever you try to interact with it or if your connection is established it will show you right here if your connection was established or successful and it will show you if the message was published or not it could be some other reason that you are not able to display the message that we will explore in uh upcoming video now let's see to get started with it we will first choose our manage things and here you can see i've already created one and i'm just gonna put it here and we start by creating it create a single thing and you can name it something which is relevant to your application so let's say my application is something like random data and for clarity i'm going to use camel case notation and not necessarily that you need to specify some kind of thing you can just scroll down and skip all of these steps and click on next now in order to make things interactive or in order to make things more secure you need to add some digital certificates now discussing about a digital certificate is a part of another video which i'm going to publish later on but you can understand it's something like a certification given by a authority which is also digital or which is established authority that says okay you know what these two guys who are trying to interact which in which in our case is a client or or some kind of program and the aws they're all authorized to interchange or exchange the data now how do we get started with it uh create a certificate you can also upload your own but it will take them time to learn that thing uh but as of now we can just create our own which is created by basically by aws now there are a few things you need to download you not necessarily have to download the public key also you only need to download a certificate for this thing it's kind of a certificate given to us of a program or a thing in your case since it's iot internet of things you can just download this part it's just a certificate saying that you know what this device is secure to talk and in order to make or use services you need to have a private key which is only which has to be only with you and you need to save it in a folder which is easily accessible but you need to store it in a way which is not easily accessible for anyone else except you and now the third thing we need to download is root certificate authority now this root certificate authority is the one authority that i was talking about these are the people who gives the authority or make to device interact with each other and the certificate that we are going to download is basically based on x509 digital certification now here i'm going to select this amazon root ca right click on it save as and you can save it as however you want let's try to create a desktop folder control shift n you can do that on your desktop and we can just say aws iot test as a folder name go inside it create another folder saying certificates now it's not necessary to create a certificate folder but it's just give you a good folder hierarchy where you can easily locate things just for your convenience select here and then you can save it here now everything is saved all i'm going to do is go back and activate this part of it now everything is done certificate is created go and click on attach policy now we haven't yet created a policy already you although you see that there is a policy created over here what i'm going to do is since you don't know how to create the policy um i'm going to just register thing and later we will be attaching the policy to this thing now policy means what do you want this thing to do do you want it to subscribe do you want it to publish the data only you wanted to do everything else so to do that we will go to secure policies and click here create one give a suitable name let's say a random data policy and go down below it says what do you want this thing to do i want it to do everything publish subscribe and whatever it is and you can select this colon and aesthetics sure what you can do is instead of all of this i don't want to do let's say very specific thing all i'm going to do is just put that into a aesthetic saying you perform everything now i'm going to say allow and create having done that what you need to do is just go to this random data policy go to certificates and it says that you don't have any certificate yet and this is the description of whatever you have done so this is what the whole statement of policy looks like you can do the same thing with the help of amazon aws cli but we're gonna go back to this thing and try to attach a policy to it now this random data doesn't have any policy go to a security tab actions or click on this security and attach policy the policy that we have created just now is random data policy attached with it now everything is done in order to test it up you can go to test and see if the data is being published or not now before doing this we need to write our own program in order to send the data over here now if you remember we have already downloaded the certificate all we need to do is now write a publisher program which publishes a message over to this specific topic with the help of this digital certificates now here we are going to write a program for interacting with aws we are going to use a paho impurity client i'm purity library in order to realize uh this part of a mqrit program we start by importing pahoa impurity library as let's say publisher or let's say impurity and create an object saying let's say publisher impurity dot capital client we are not going to provide the name of the client as of now or i'm going to fill up the details later on so i'm gonna i'm just gonna leave this as it is the next part of the publisher program is published now since we have created the object here we need to connect to a broker and followed by port now here we are going to use secure port triple h3 i'm going to speak about uh what is that now now that we have created an object of pub we need to connect it to a broker which you already know of so i'm gonna write just the broker and then put here and i'll be defining all the variables over here now and let us just remove all of them and replace it with variable names and i'll be doing that and defining them over here so broker and then you have board after you have connected we are going to publish a message saying publish and the topic name let's keep it as aws iot slash first try keep it unique if you keep it something general it will just uh maybe a lot of people might be trying to send the data but let's keep it unique as possible and we are going to send a data called hi or we can just create a random number and then try to send the random data and here we are going to put qos equals to one quality of service before this since we are trying to send a data over secure port we need to add a tls set which is transport layer security and configure this program for that so tls underscore set this first parameter is going to be the certificate of certification authority second parameter will be the certificate of the client itself the device our device basically and the third parameter will be the key itself and after that you will see that it will just try to send a random data which is our high in this case now how do we find out this client id over here let me just take you back to the where we are going to test it let's go to this part aws iot here you can see your client id is this part just copy this part and go back to your program and paste it over here the broker is basically the end point of aws which you can find over at the right side so i'm gonna click on let's say here vo endpoint and copy this whole string and then go back to our program put that into double quotes and here so the third thing we have is the port which is our triple h3 now you can visit a website called oss.org this is the organization that is maintaining the standards required for impurity according to them triple h3 is a secure port while 1883 is in secure port for testing purpose it's good to go with that 1883 which is just to test basic functionality and since it's insecure anyone can just hamper your data and whatever it is so you better watch all of those steps now the third thing is we need to set the path for dls set so the path for our tls set is basically where we have saved our file which is in this folder certificate and what happens is if you're not what happened is if you're not trying to if if one of your file is in another folder while this file is in another folder then you need to provide the full path since my file that python file i'll be saving it against this in this folder i don't need to provide the whole c path rather what i'll do is i'll just go into the certificate and whatever the path it is so all i have to do is just copy this whole thing and put it into my program now this is not just it what i have to do is i have to change the extension of this thing the amazon certificate file so it behaves like it's a certificate which i'll do after i have added all the attributes here so put that into double quotes and second thing is the certificate of the thing go back to this and this is your certificate copy this up go back to your program double quotes and paste the path now the third thing is the key which is your private key and copy this path and go back to your program and try to save that now now since you have seen i i went to the folder called certificates so i need to add that over here certificates uh forward slash copy this up paste paste and the next thing that i promised was that i need to replace the extensions of it so i'm gonna go back to certificate now and replace its extension to crt which is a certificate while also replacing this into just pem which is encoding method and over this also to pem go back to your program and do the same over here this is just crt certificate while this is just your pem while this is going to be your pm that's it i'm going to save that into the certificate folder now which is in my desktop aws iot test and here i'm going to save it as aws iot test program so you can see the path of my folder is now desktop this and this part now aws iot test underscore test under forward slash certificate is where all my certificates are present all i have to do is just run this program and check if my program is running well or not before that let's have a quick check if everything is written well so our client id is correct our broker the endpoint is correct okay the port number it's correct client is correct our tls set is fine broker publish and that's it now i'm going to go back to aws iot and here subscribe to a topic called let me just go back and check our topic name which is copy here go back and put it over here you can select the qs1 it's recommended and then subscribe to this topic now all i need to do is just run the program and you will see the message being run so run and run module you can see that there was no error so the python program just run just ran and then it showed the output let's see if in our iot test online the message was published or not so there is one good reason that your program might not work is because one of the few changes that i've done is make sure whatever certificate that you have got instead of having this hyphen sign like that replace that with underscore and same goes for over here what i did was i replaced it with i replaced this type of file that i already have with underscore and you have to do that necessary changes in your certificate file also the next thing what i've done is uh just replace the topic without the topic separation don't make some common names so for example the previous broker name or the topic name that i was using was aws iot instead of that i have used just aws iot underscore test possibly that there is some reserve topics that you are not above allowed to use now if i just run this hello and f5 and the data is being sent i'm going to see that in my aws iot core if there is any high message sent or not so you can see right here 18 18 41 it's the exact same time and you can see the message is being sent over here i hope you like this video keep sharing this video if you like it and if there is anything that you want me to cover up let me know in the comments below until then keep learning bye
Info
Channel: Shariq Ahmed Khan
Views: 3,189
Rating: undefined out of 5
Keywords: #mqtt, #iot, #aws
Id: qAe2zYqvQTQ
Channel Id: undefined
Length: 20min 36sec (1236 seconds)
Published: Fri Aug 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.