 Hi, welcome back to another episode of Visual Studio Toolbox. My name is Dimitri Lailand, I'm the host and I'm back once again with my guests, Suze Hinton. Hi, Suze, welcome back. Thanks for having me. Yeah. So Suze is a Cloud Developer Advocate focused on IoT, and we've been working on a series of episodes. So if you've been watching Toolbox before, you've probably seen a couple of other shows potentially, or at least have seen them get published up. We're really trying to cover how to get started with the Windows IoT platform, how to extend it with the Azure IoT platform, how to work with the hardware, the debugging. We're really trying to be basic, right? Like we want to start from the very beginning and build up. So if you watch the other episode, you've gone from like, I don't know what this hardware is all the way through. Like I can write an app that uses sensors and uses different kind of approaches to working with different kinds of sensors, all of that. But then there's this one other piece we wanted to cover today, which was the Azure IoT part of it. So why don't you tell us a little bit about what we have on our screen behind us and how it all comes together and then we can jump in the code. Awesome. Yeah, it wouldn't really be internet of things if like this device was just running locally and didn't have any kind of connection to the outside, right? Well, we cheated a little on the last episode, right? Because we did facial recognition using the Azure Face API. So the device already required a connection, but now we're like, okay, but the device kind of exists by itself somewhere, right? In the real world, this would be embedded somewhere or standing in some device, right? Yeah. So what if you actually wanted to monitor those sensor values from the outside? And let's say you wanted to actually kind of persist it somewhere else, like in the cloud, such as in Azure. This is where we have some really cool tools and our biggest one in Azure that we're known for with IoT is Azure IoT Hub, which is like an IoT messaging broker platform that we have and it has multiple protocols that it speaks and it basically allows you to have your device talking to the cloud and you can sort of reading those messages from the Hub or you can tell the Hub to then communicate back to the device as well, which we're going to cover in later episodes too. Cool. So with IoT Hub, that's something that like, you go into the Azure portal, you create a guest, a subscription, you can create a project or something. How does that work? How do you get to the point you can start receiving some data via the Hub? Yeah, so just like the high level overview is you create like an actual instance of an Azure IoT Hub. You register like a device in that Hub and that gives you credentials that your device can use to speak with the Hub. We can actually totally shortcut and we can use other Azure offerings such as the one that we have behind us and that's called Azure IoT Central and that is using Azure IoT Hub in the background but this is more of a software as a service offering instead, which is really cool. And what you're looking at right now is you might recognize that little picture is over our three pie. This is actually listening to live telemetry coming from the pie right now. Awesome. Yeah, that's the actual device that we are sitting here and the way that you can explain it to me because I'm new to some of this as well as that. Yeah, this is all new to me. Like the IoT Hub is the API, right? That's our bridge. That's what we're sending data over. That all this data that's being visualized in the SAS is coming in from IoT Hub and then this SAS is configured to read from that IoT Hub data store of some sort and it's visualizing data but you've pre-configured it's like nothing on this view was there in the beginning, right? You had to position all these like dashboard widgets and you configured it but now it is displaying live data, which is really cool. Yeah, and I can just sort of drag and drop stuff and you know, it decides to put it elsewhere and this is a relatively new offering from us and I think it's actually really cool because building your own dashboard sucks, you know, and like most dashboards out there are made for like logging and monitoring of web services, not really like devices. So that's what I really like and we already have ready made templates for things like Raspberry Pis and stuff, which is awesome. I was really, really pleasantly surprised by this. So this is us sending right now that UWP app which you might have seen spoilers in other episodes. We have like an Azure IoT Hub static class that's sending some of that telemetry so we can take a look at that now if you wanted to. Yeah, let's take a look. Great, so for Invisual Studio I'm gonna stop that instance now and I have a IoT Hub just a static class with a couple of methods in it and so I am using the Azure devices client that comes and you can install, you can install this from Nougat. So that's where I sort of got that from. So that is a package that you can install and use and so I do initially when the app starts up I start connecting to the Azure IoT Hub and these are credentials here. You can see central connection string and I think there's also like a device ID there. They're given to you when you create your IoT central application. So when you create that Raspberry Pi device it automatically registers that with your IoT Hub and then gives you those credentials to give to your Raspberry Pi. So it really couldn't be easier when you're creating a new client you have those particular credentials. Cool. So the next thing we're doing is we have like a send device to cloud message and that's what we're actually using to report that temperature value. Given that in our app right now it's only reading temperature from that particular sensor that's the only information we're sending. But you can see here that we're actually just creating like some data to be able to send. We're sending what time we sent that. We took that temperature reading, the actual temperature value itself which we looked at in previous episodes which you should check out if you'd like to see how we got that. And then we can also send along our device ID just to make it a little bit easier to kind of grok those messages that are coming in. And you can send like this is JSON. Yeah, it's just JSON. We're using a JSON library. So you could have sent any kind of data you wanted you just chose this. We're not limited to sending temperature data, right? Yeah, right. So there's all sorts of data you can send. And in the previous episode this was the sample app we started showing that already had this stuff in there. And we have the sensor on the board like this is all very real. Totally. So look at the previous episode if you haven't seen it before. Totally, so we can start putting our own stuff in there, which I won't know. We just have to sterilize that into like a string. And then our device client send event async with our message. That's what's doing the IoT Hub stuff. It's just that one line. So once you've actually sort of put your message together, you know we just pass the temperature reading in every single time. So we read the temperature and then we immediately invoke this method here in our main page class in order to do that. And so you can see here when we initialize our devices I'm actually connecting to the IoT Hub. And so that means I'm ready to send the telemetry once we actually have our sensors initialize as well. So I'll just try and really quickly find where I'm doing that. And you might have seen a sneak peek of that previous episodes. You can see here that I'm reading the temperature I converted to Fahrenheit and I'm sending explicitly the Fahrenheit conversion. And this is just my static class we showed with that. Yeah, so you're constantly in every tick of this time or you're sending up the data that you've decided to send up. And then IoT Hub just stores that as the JSON that receives. And then the central part of it, Windows IoT Central is the visualized, right? This is the SAS. So you decided to visualize some of that data. So potentially you can be really creative on the kind of data you can send back, visualize. Absolutely. And they get scaled to many devices sending back telemetry without having to build a lot of back answer. Just think about how much stuff you'd have to build. I know. But philosophically, like let's talk about like Windows IoT Hub. So let's be very concrete like what problem is this solving, right? Is this something the industry already had as an issue? Is this something Microsoft thinks is a problem? Like give us some of that context. Yeah, that's a really great question. So messaging brokers for devices have been around for a long time and we do have several different protocols such as MQTT. But the problem that it's solving is that we never used to really distribute devices at scale in this way. Like imagine there's some kind of smart toothbrush that knows how long you brush your teeth for and then it also is like logging how often you brush your teeth, right? Imagine you sold like a million of them around the world and like they're all somehow communicating back to your central application to do things like firmware updates for your toothbrush and even just like being able to plot like you know in someone's account on your company's website like how they're doing it with brushing their teeth. So you can basically as a company you can collect data, the user decides to send you you can then do something meaningful with that data. Totally. Either completely in a custom way. So in other words you can read that Azure IoT Hub data store yourself with code you've written or other solutions and we just happen to have a solution that does some basic visualization. So it's great for deploying some devices, doing some testing, doing some pre-canned things or you can write some crazy code to plot how your toothbrush is going. I mean that's a contrived example but it is kind of easy to imagine. And yeah IoT Hub focuses on mostly trying to do the set scale you know it's able to collect a ton of messages and kind of like buffer them until you're ready to take them because it will keep those messages around for a while but it also allows you to have that two-way communication as well and so if you have like a certain batch of toothbrushes you wanna update you can just isolate that group and you can just send out firmware updates to just those devices themselves. And so it's a two-way communication and it just has so many features in it that I'm not even like touching on. But the biggest thing that we focus on too which can be a problem with devices is security. So we've heard all about you know the de-dossing webcams and stuff that happened you know like last year and the year before that's something that we at Microsoft take really seriously and so we also have some really minimal security bars that you have to reach to even use IoT Hub in the first place and we give you a lot of great documentation and features to make sure that your devices are as secure as possible. That's awesome. So you know first of all I can't wait to like pick up my toothbrush at home and it says updating and I'm standing there going really? This happens to people with light bulbs already so it's got hands on them. Totally, yeah. But I think it's awesome to have that flexibility as a developer to build out the platform. So that's what IoT Hub solves in all of this, right? And that's just in C-Sharp SDK in Europe and running it's built for this. Totally, yep. And IoT Hub works with other, you know it's not just for Windows IoT, right? Right, yeah. We're building it more broadly so it's a great platform. And then central so what is IoT central? What problem is it concretely solving for customers? Yeah, so it's solving a problem of having to build all of that infrastructure yourself. And the visualization of it. The visualizations but like central also has a bunch of built-in features such as you can have alerts, you can have behaviors that happen as a result of data that's coming in. Like your device is overheating, you know? Yeah, exactly. You know a learner or something coming in. Yeah and so that can actually dispatch like a command back to the device to update a property saying like oh maybe like maybe turn up the refrigeration or whatever if there's a refrigeration device overheating and it can also let you know that something is wrong so that maybe you want to schedule some maintenance for that device or something. So it's not just kind of showing stuff on a dashboard, it's also allowing you to kind of have a little bit of extra intelligence built into that as well. But without having to do that all from scratch which is a pretty big ask. Awesome. So this really makes I think our sample up even just a little bit more real right? That's our goal. Totally. It's kind of working now. We are sending telemetry to the cloud. We are visualizing the telemetry. We're giving you as a developer much more options. And by all means if there's more interesting things that people want to see, you know leave us comments in the show notes, send tweets, you know, Susan and I are very active on Twitter so let us know what you're thinking and we'd love to do more content around this but I think this is a great kind of starting point and anything else that you wanted to show us part of this? No, I think that the next episode we're going to do some super cool stuff where we're going to start like controlling the device rather than just having the device and telemetry to us. So I'm excited to talk to you about that next time. Okay, well thank you so much for coming on. And folks, thank you for watching this new episode of Visual Studio Toolbox. We really appreciate that you watch this. Check out the rest of the episodes in the series. We're again doing a series on IoT so there's more episodes behind us and a couple more in front of us which we'll be back to record soon. And thank you so much for watching and we'll see you next time in Visual Studio Toolbox. Take care out there. Thank you.