Routing Messages in Azure IoT Hub based on Device Twin

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when it comes to IOT it's not just about gathering events somewhere it's also about being smart in in terms of where to send that data from devices our IT hub has now new features on top of the existing routing feature it already had that allows you to not only route on the content of messages but also on the device twins I have Paul today on the IT show to show us a bit how that works and will also highlight the updates in the portal for azure IOT hub to make creating your routes for messages where easier [Music] thanks for watching the ie show I'm Olivia your host today a half bull gone bruised we know why you Paul doing good doing good can't be here I'll put it out family we're looking for XQ the back stories that we're looking for an excuse to have ball on the show so we found a topic and a very nice demo right cool so before getting into it would like to introduce you to our audience right right I'm Paul Montgomery I'm a senior software engineer with the azure portal team with that we do the all the blades inside of azure portal the CLI PowerShell so we touched pretty much every feature so I'm finally getting to be part of the show cool yeah told us that you developers are using to access our services right absolutely and today in particular the excuse we found to have you on the show was a new feature that is lighting up in the azure IOT hub blade and that's a new way of routing messages from devices to other services right yes so the routing and endpoints inside of the azure IOT hub is probably one of the most powerful parts of IOT hub because that's where you can start taking all of this data from all of these devices and actually shipping it out to the rest of the world so with that before you could always do system properties and app properties and the message itself for routing now we're going to extend that to where you can do the actual device twin as far as tags and properties so properties desired properties reported and the tags themselves can now be queried as part of your route mm-hm and you can route messages according to that and just a reminder for people watching the device tween is that Jason or that let's let's technically speaking it's adjacent file that is maintained by ot hub but in a nutshell it's a digital representation of your devices within the cloud right right so frequently you'll have things like tags to describe where your devices are and that's kind of what we're gonna show in the demo here in a little bit but also being able to set properties and retrieve properties from the devices so that as the device is going through it's very state changes these properties will get updated and to get those to represent an IOT hub we use the device twin there you go and in general the way the way also like to differentiate because when people are asking hey why do we need device twin with properties when we have to limit rewrite and I like to say hey telemetry is gonna arrive in big huge bursts of data and and while the twin is here to allow you to maintain a last-known state of the device you know values for the properties or assets from the cloud and properties that are reported from the device which is a different approach to the device you know data right so it's actually more of the kind of real-world what's happening then any kind of telemetry that came out because like the device can go to sleep and you need to know well what was its last known good what was its last known state for the dist and the other so illustration of that actually you brought here goal of microcontrollers couple of ESP 32s okay so we can go ahead and the actual code for that with you know Wi-Fi hotspot names and all of that which are all going to change after this anyway is really simplistic it's using one wire and the Dallas temperature libraries and of course the azure IOT SDKs also to go ahead and just really connect to Wi-Fi and read the temperature and push out what is the current Celsius and Fahrenheit device that through the tweens and leveraging the skz mansion okay so you're cutting envious code I'm gonna deploy the code on these devices yeah then you have like hot water and cold water right on the table yeah and now you have sensors so we're gonna see how that looks like well show us the float that that Marsh leaked I thinking this thinks that the code for the device has been developed but the things you're gonna actually do live right I'm sorry life into them you can actually just like do from yeah that's right yeah and it's it's really as soon as the devices boot up you'll start seeing some console output from them and you know you'll see that it's going from about the 70ish degrees here to whatever we're putting it in and I believe this one is what I've got kind of marked as a freezer so it's the temperature controller for a freezer so we would really care about okay it's coming from a cold environment what happens when it gets hot right so we'll get into that once we actually start seeing the data coming out okay so we hit for device and upload it to advice plug this guy in as it deploys so here we're using the arduino extension for yes good rise which is so it's got a few things here I've got the Arduino extension all of course to get all the Arduino goodness also hi ot workbench extension you'll see whenever I brought up the deploy to the device that was IOT workbench device and really it's a pretty vanilla install of vs code after that okay so it has now updated and if we open our serial monitor we'll see I start connecting to Wi-Fi we have an IP address yep I'm gonna make this a little bit bigger so you can start see that we do have data coming through okay y night sending events right yeah so you'll see that it's just blasting through every half-second okay and as we go ahead and say that this is the freezer we're just should be cold and it should start coming down as far as ham cheese 15 14 13 so we're definitely dropping our temperature make sense and as we then bring it up you'll start seeing it start to rebound back up so with sensor is working with sensor is working so that's always a good thing so if we'd go to our actual routing here you'll see that message or you'll see that endpoints and routes has been removed and has been replaced with this message okay and from here you can actually do all of your creation of the route completely in line you don't have a differentiation between what we had which is which was like the custom informed versus of wrapped itself right so you don't have to go to two places to do that okay so as long as you have your event hub or your service bus your as your storage in place you can go ahead and complete the whole process of setting up the route setting up the query for the route and setting which end point it goes to God and creating that end point for that other Asha resource okay so for here we'll say freezing the endpoint as you see I just have an events in this Azure storage doesn't really exist so what we're gonna do is add a new event hub okay add a new endpoint for an existing event hub okay that's the name that's gonna be you know the one used in the IOT hub plate right for referencing that particular endpoint so I've already got the azure resource itself and the event hub name is going to be broken freezer since it's okay clearly hotter than a frozen amount so this will save the IOT hub it will go ahead and now create that endpoint for the IOT hub so that the route that we're going to create will actually start using that endpoint okay so as you see it came up here with hot in point we're going to use device telemetry messages and we'll actually be able to do more of the test here where we have the device twin itself okay so this is a sample device twin that we could use we have various messaging okay again the structure of the data the properties for the between the messages properties and then the the body of the message right so you basically can pick what you want to work on in terms of routing the messages right so for this we would say we have a message body who has a Celsius that is greater than say I would say probably five sorry I switched to Fahrenheit for a minute thirty five is going to be very warm for you yeah yes yes too late but we would also then since we would possibly have other devices in our IOT hub okay we would then also use basically chemically and add a filter yeah base um tween properties so tags Oh tags in that case would you want to use properties are you why did the other I guess it was worse right yep there you go awesome then we could come down here and be able to actually test our message and if this is yes that way seem like pushing and testing and production again actually just like in put a adjacent which is an example of what the data will come from the device and and see their queries actually working got it so here we would be able to say I care about freezers okay okay and we'll clear up the rest of this test message a scroll so that I can actually see the rest of the test message which means I have missed a property here so the message match the query so let's avoid any kind of you know shenanigans as far as if this is something else right okay so what about if it was a heater message did not match okay I kind of validate manually your yeah your wraps your a query right now okay so we'll save that and this one I'll save the route okay and we should be able to then watch that yes we're still getting hot water okay and we should be routing now to our hot endpoint okay so data is going into an event hot right now that is going into an event hub right now and to make sure that we actually have that endpoint up and running I've created this logic app okay and if everything is set correctly with it we should start having it talk to teams okay so these are we kept for each event help that comes in you added a step in your logic app that is about sending messaging to teams right okay so should be able to run that mm-hmm and I have that team's channel open here and as you see the message has arrived in teams okay so basically the full loop of message arriving from the device certain value the hub checks on the on the twins value on the treatment Papaji or tag in that case and the message body still we're able to query both the device and the payload itself and bring that all together to make one set of queries to basically you tell it exactly where to out this message to that's cool so and actually I noticed that and we say that but I'm supporting to notice that we also simplified the experience of creating these rounds because lots of users of be nationally using something like stream Alaric's or functions behind IOT hub to do the routing right and now you can really have a reach experience in IOT hub blade for doing the routing right and that's just you know things that we keep trying to improve on it's really get that user experience to make it really really simple to make these really complex little devices just be able to do what they need to do way easier for our users that's awesome so Paul thanks a lot for coming to the show we'll find another excuse soon for you to help play with devices right and I've got something a little more than a temperature probe definitely family and thanks for watching the IOT show hope to see you soon don't forget to subscribe thanks a lot [Music]
Info
Channel: Microsoft Developer
Views: 11,095
Rating: undefined out of 5
Keywords: channel9, iot, azure, iothub
Id: S7Q_h1yjGUE
Channel Id: undefined
Length: 15min 7sec (907 seconds)
Published: Mon Sep 24 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.