Google Cloud IoT Core with Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm gonna walk through the Google cloud I oh teak or quick start with a small difference being that I'm going to use a Raspberry Pi here in place of the device that they use in the demo which is just your desktop so starting down the script here they begin by setting up your project I have that set up if you don't you can go here and select that make sure billing is enabled and make sure that your api's are enabled so we'll go over here to my GCP console I'm in my project I'll go and look at the API as they mention in this case I want to be sure that pub/sub is enabled so I'll go look there excuse me wrong section so pub/sub I see that it's enabled here and then I'll also go back and look for IOT core so I have that here and I have that enabled so my prereqs are set to go flippin back to the lab here I need to set up my local environment I already have the Google Cloud SDK installed you can see that here with g-cloud components list it's a jeek lab being the entire suite and i can see the items that I have installed down here and if I continue through I have nodes set up as well so getting onto the IOT component I will first create a registry so registry is a place where we can have multiple devices and gateways managed collectively and also we can set configuration parameters that they will all adhere to so let me go over to I Teek or we'll see I already have a registry here but if I were to create one I would start here I would give this a name I would select a region where I want my configuration to be stored in this case I'll choose United States Central and then which topics do I want to use so the topic you must select is where you want your data to go this is where all the data from your devices will be published up in the cloud I already have one called IOT data but you can create one here and by default this will be encrypted with a Google managed key so you don't have to do anything else there to be secured on data encryption anyway there are things you can set in the Advanced Settings or you can disable protocol if you like by default both MQTT and HTTP are enabled if you have a lower powered device you'll probably want to be sure mqtt is enabled so you can do more lightweight message transmission by default nothing is enabled for stackdriver logging to capture data and telemetry if you are troubleshooting a new solution or you want to try something out and you want to do some more inspection you might consider turning this on so that your devices and gateways in this registry have a little more telemetry they spin off to inspect later finally is your certificate completely optional but you can set up to 10 per registry that will be recognized based on different device types and you know confirm that they are devices you've put into place if you have a very large topology or environment and this might be something you'll want to put in play so I already have my registry created I'll cancel out here so I'll see you have my Raspberry Pi registry in central with those protocols and so you'll see I have my data topic set as we just saw the other one that's optional that I have set here is state so if my device puts off a signal strength or a battery indicator or something that's not the actual data its collecting but kind of metadata about the device itself you might want state data captured so you can do things like you know detect when a device needs to be serviced for example again certificates are listed here we can see logs if we chose to put them choose put them on in this case I have errors gathered by default it would have been none but I haven't set to error so any device I add here will have errors collected so let me go back to our QuickStart here we create a registry which I went through select our region we went through that we selected our protocols by default they'll both be on MQTT and HTTP but make sure that's set you'll set your topics from where things will be published in this case I had that data topic we'll create that State and certificate or optional good so we're done in this section we have our registry created we have our topics configured now I'm going to flip over to the device itself so I have two terminal windows here you'll have to take my word for it there's a PI on my desk it is all my local network here I'm gonna log in and run an update here let's see I guess that's kind of a ways back should be good as I just ran it a few hours ago so do nothing to update there so I'm set so I have my device here I'm going to run this next command to create a key pair which we'll need when we're creating the device in cloud so I'll copy this here this is our OpenSSL key creation if you're doing a bunch of devices you can have this run as your you know startup script the first time the device boots so it creates it sound key I've just created mine here so I've got my public key and my private key here ready to to go so in GCP and I have T court you don't actually ever put the private key data in GCP you just need to keep this public key ready to to enroll the device so now that that Keys created let's go back now we're gonna add the device to the registry in cloud so let me open up the registry page and I'm gonna create so I'm in my my registry here my R a spy registry I created and I'll create a device I call this just for simplicity I'll call it R as PI device if I look down at the attributes I want to enable this device you can optionally kind of block all your new devices until you're ready to go live and then you can have them start feeding in data I'll allow this I'll use the default logging setting for my registry on a device by device basis you can't override that and pick a different one if you like for authentication I'm going to manually enter my key data so we just saw that we created the key back here I'm going to look at my public key I'll copy all of this and paste it here double pasted no ok good ok so that's my key I can optionally set an expiration date I'll leave that blank for now but I'll create this device Oh invalid format okay the wrong type there so created my key and I created my device so now my device is set it's in my registry all the activity as we start to use it will show up here we can check our existing keys and make new ones as we see fit so we'll go back here we added the device we allow communication we copied our key data to our device enrollment page and we added this this key we did not add any metadata but we optionally could have at that point if you want to specify maybe which facility the device is in or where it is specifically so we know how to physically locate what device this enrollment you know accounts for so we're done on that page now we're gonna run a sample code from our device so this repository here is our Google cloud set a simple code so I'll copy that here now I already have this cloned so I'll just get an error that it already exists not a problem moving on I'm gonna actually go into that directory and I will see a few files ready to work on their next thing I need to do is copy the key I created earlier into this directory so I'm gonna copy from my home directory it was called RSA cert copy that here and oh rather I need to copy the private key excuse me okay very good and I'll need to run this NPM install command to get our dependencies I already ran this so I'll skip this on my device but yeah I probably want to do this just for this particular sample code and that's we're set on the device for the moment now the next thing we'll do I'll switch over to my machine here locally we're not on the PI anymore and I will let me copy this go over to my editor here and I'll you want to put your project ID here so in my case it's C demo 2 is my project I'll do the same down here and the subscription I'll call up my subscription simple enough the topic I called this R as pi data I believe so I'm gonna go back and check that but I've got my device configuration here I have this going to let me actually go back to my topics themselves so IOT data is the topic where I'm publishing so I've got the full name here IOT data so I'll go back and I'll create this subscription now I already have g-cloud installed and configured if you haven't done that it's tough to initiate it you'll want to do that separately before you begin here but I can go ahead and create my subscription alright this already exists so let me go ahead and delete that subscription so that this will work and I will run that again okay great have our subscription so this will allow us to pull events after our devices publish them so that subscription is created there now we're going to run the actual command on the PI to create some sample data so this is the configuration we'll need to set up this works with the node sample code so go back to my editor here project ID I'm gonna do my C eat demo to again region we said we're in US central one registry is called R as PI registry after that already raz by device is my name I believe let me come from Jasper as pi device or I'd say private I'm using the default name for the the key that's my local key that I'm gonna use to assign the message and I'm gonna send 25 sample messages with my algorithm matching my key here so let me copy this code section back to the PI and I'll run this okay so now we're publishing messages and as this is going I can go back those messages are already in cloud now so this is running I can go back and read those messages that were published so I'm going to pull them off to the sack and acknowledge them so this is my pub/sub subscription pool so it's the same subscription we used earlier I will need to actually let me copy this here I need to change this to my project everything else looks good publish a subscription pull acknowledge it that's the name of my subscription so go here and start to pull and I can see that's my first message that I just pulled off the topic so I have my device ID the unique number the registry with which its associated which region project and you can actually you know add other metadata there if you like but this is the these are the payloads that we're pulling off here so I pulled these off and acknowledged them so they will no longer up here here but if I want to also inspect them not at the CLI but just in me in the console I can go to my same subscription here and I can well I could see some metrics on it but I can also view messages if I want to take a peek at what's going on now I'm not going to check acknowledge because then they'll disappear off of the the pub/sub service but I can see new messages showing up here when I click pull so these are the ones that have not yet been acknowledged take a peek here same as the messages were seeing here so that was a Raspberry Pi publishing data to pub/sub with IOT core and then pulling them off so you can imagine scaling this up and setting up these devices programmatically and then pulling data programmatically to maybe perform some ETL and in a pipeline and eventually right out to a warehouse like bigquery and run further analysis on it thank you for your time hope you have a great day I'm gonna go ahead and clean up here a bit and delete some of these devices and components that I've created nothing here that I've done so far will keep billing hourly or monthly but I'm just gonna clean up anyway just so so I don't confuse myself later I hope you liked this video please comment below with any other questions also include the link here to this QuickStart thank you
Info
Channel: Evan Crane
Views: 10,531
Rating: undefined out of 5
Keywords:
Id: 3Zwlj9x96Jg
Channel Id: undefined
Length: 18min 8sec (1088 seconds)
Published: Fri Apr 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.