Overview of Azure IoT Hub



hi my name is Ellie DiMaggio and this is an overview of a new service called Azariah t-hub passer exposes many many services in more than twenty regions it has infrastructure services and platform services IOT hubs is the new service in the analytics and iot category before we start let's introduce some context there are other sessions in this conference that are relevant to our IOT hub the first one is how to build enterprise-grade IOT solutions using azure IOT suite the second one is how to make use of azure IOT client libraries to connect your devices with Azure connecting your devices is the first challenge that you have when you're creating an IOT solution this is because there is a vast variety of devices that you want to connect some of those are internet capable and in that case you can connect them directly to Azure service for instance an IOT hub or you can use your own cloud protocol gateway in case the device does not use a protocol that is supported by IOT hub at this time AMQP or HTTP some devices are not capable to access the internet directly and they work on personal area networks on with protocols such as Bluetooth or ZigBee or 6lowpan those devices need what we call a field gateway to connect to the cloud this field gateways can do many things not only connectivity and not only protocol translation but in this talk will only refer to them for their protocol translation capabilities on your application backhand side one of the most important use cases is telemetry you usually want to have an event processing an inside pipeline hot and cold paths for people familiar with the lambda architecture and an IOT hub will allow you to get a feed from the devices events very very easily the second big component that that IOT solutions have in the cloud is the device business logic this takes care of the interactive scenarios of your solutions think about opening a car from your smartphone or changing your thermostat temperature or sending a command to a device to update a piece of firmware finally IOT hub has to know which devices are allowed to connect and which devices are present in your IOT solution for this purpose it has to interact with your application device provisioning and management component which is the component that then make sure that devices are embroided and and be provisioned correctly from your own IOT solution one of the first questions that you might have is why use IOT hub in the first place after all there are services in Azure that allows you to perform the device to cloud messaging for instance using service bus for instance IOT hub in addition to – – communication patterns adds other value propositions to your solution first it scales up to millions of simultaneously connected devices you do not have to scale those services on your own those dis communication patterns will scale with you just by increasing the number of units in your IOT hub deployment it does support per device authentication and security per device authentication is fundamental because you want to have fine grain control on which devices access your solution and you want to make sure that you're sending the commands to the right devices this per device authentication and per device identity is embedded and and designed into the communication pattern in the device – cloud messaging and cloud to device messaging messaging there is also service facing monitoring IOT solutions usually have the problem that devices cannot be reached without a cloud connection to connect to a device without the cloud component mostly it requires somebody physically going to the device location and and perform maintenance on it since this is the case it is very very important to have monitoring on the connectivity status between the device and the service and and to have very detailed monitoring on the Committee on the status of each and every piece of communication finally IOT hub supports many IOT protocols and is designed to support constrained devices device there are constrained in networking resources power resources or computational resources of course your IOT solution might want to use different communication patterns think about uploading or downloading files or using a real-time proxy strategy like an HTTP call or a web api this patterns while not currently supported in in in IOT hub do benefit from from from IOT hub in many ways and we do provide guidance on how to implement them taking advantage of many of IOT hubs advantages when you provision an IOT hub from the azure management portal you you will create your own instance of IOT hub this instance exposes some device facing endpoints and some service facing endpoints from the device side each device gets its own unique endpoints this is for security purposes and for isolation between devices each device has an endpoint to send device to cloud messaging and to receive cloud to device messaging this of course field gateways and cloud gateways can connect to multiple of these endpoints at the same time also using the same TCP connection while reducing resources on those devices on the service side your application back-end can receive from the device to cloud receive endpoint for both your event processing pipeline and also your device business logic for messages such as command replies or alerts that are coming from devices this device – thought we seed endpoints is compatible with event hubs so any solution that you have that is a that is currently using event hubs will be very easily migrated to use IOT hub the device business logic component in your own IOT solution will making news of the cloud-to-device and endpoints to send messages to individual devices each of these messages is very important and if it doesn't reach the device it can have implications for your solution for this reason IOT hub has a feedback and monitoring endpoint that provides information on the delivery status of each and every message in order to create secure connectivity between cloud and devices IOT hub has to know which devices are in your solutions and what are the security credentials that they can use in order to to connect in for this reason it has to be integrated with your device provisioning and management component and it does so by exposing a device identity management endpoint finally there is an IOT hub management endpoint that is used to change your security and functional parameters of your own IOT hub instance let's look how we can create an IOT hub using the azure management portal this is the azure management portal and let's look how we can create a new IOT hub we go in the new section we select Internet of Things in here you can see only IOT hub but in production you're going to see more services in this category let's create a new IT hub called a zircon and we can select pricing tier in here I already have a free one so I cannot create another free one but I can create a standard IOT hub there are two versions of the of the standard tier for for IOT hub and here we're going to select one that that that has that allow me to send and receive up to 50,000 messages per day of course this is a single unit I can of course buy up to 200 units with and an even more if if contacting Microsoft support 200 units means up to a hundred thousand simultaneously connected to and a lot of messages let's select this queue in here we're going to just provision a single unit I can also select how many partitions I want in my device to cloud telemetry pipeline this is similar to the to the event hub partition concept and it depends on the throughput that you expect in your in your telemetry stream let's select an existing resource group and let's select a location while this IOT hub is being created we can select another IOT hub you're gonna see more information when you create your own i io t hub in the settings we can see that there are many sections the first one is about shared access policies this pertains to security you can create up to 20 different shared access policies and each access policy has different permissions the registry read and write pertains to the device identity registry endpoint that we talked about before the service connect permission allows you to receive a device to Cloud messaging and to send cloud to device messaging so as your application back-end and of course the device connect permission allows you to connect as a device when we select an existing one you see that in here I can see the current security keys and the connection strings that I will need to use this this this shared access policy in my code there is also a messaging area that that is divided in two sections cloud to device settings and device to cloud settings in the cloud to device settings we have two parameters the first one is the cloud to device time to live each message can set its own but there is one that is defaulted for every cloud to device messaging in this case I set that to 24 hours this means that after 24 hours the IOT hub will expire a message that is there is being sent to a device and optionally it will send a feedback back to the to the service this will allow the service to perform a compensation action for that expiration the first parameter here the feedback retention time is how much this feedback is going to be retained in the system in this case is again 24 hours in the device to cloud settings I can see the number of partitions I can have some information on how to connect software it has been expecting to receive from an event hub and of course I can set consumer groups please refer to our documentation for more information regarding this de settings of course I can also change pricing I can change a tier and I can change unit for my specific IOT hub we just look at how to create an IOT hub in the azure management portal IOT hub also provides a vast variety of SDKs both for devices and for services there are actually two different flavors of SDKs for for IOT hub the ones there are device facing there are four there are targeted at devices and field gateways they support the vast variety of platforms and languages and we have a specific session that is focused on on the client libraries for service facing SDKs they're targeted as at application backends and cloud gateways and and they will support many languages studnet Java and node let's look at a sample scenario that will help us familiarize with the IOT hub functionalities we're going to have a simulated wind-turbine device implemented as a console application that will emit telemetry every second this telemetry will be about wind speed output power torque and so on this simulated wind turbine will be able to be start and stopped from the cloud using a cloud to device messaging sent through IOT hub the first thing that that the sample will do is to provision from a demo portal a device inside IOT hub this actually is a two step process the portal will create a record for the device in a device registry that is located externally and then provision an identity for that device inside of IOT hub the idea is that the device registry will contain all of them application specific metadata think about the plant where a specific wind wind turbine is is is deployed software versioning configuration so on and so forth the IOT hub will contain security materials and enable status once that security key is a is available to the simulated device the simulated device can connect to IOT hub and starts emitting telemetry that telemetry will be sent through the device to cloud send endpoint and received from the device to cloud receive endpoint by an event processor this event processor can be anything that can read from an event hub so as your three monolithic s– HT inside storm or a custom event processor like we have in this demo this event processor will take this this telemetry message and updated the dashboard in the portal the portal will also be able to send commands to start and stop a wind turbine to the to the simulated device this commands will be recorded in a command store and sent to IOT hub IOT hub will deliver the message to the simulated device which will start the operation and report back the outcome using a device to cloud message the event processor will process this data differently than telemetry messages and will update a command store with the outcome this is the portal of our demo this is a portal that is currently running in Azure in in a website and is implemented using Web API in this page we see that there are already two devices our provision in the system turbine one and turbine two let's create a new one let's call it turbine three and add this device what we see happening now is that a new record is being created in document database and a corresponding identity is created in IOT hub this page is that is is is actually driven from the data in the document database so all of the of this metadata model plan telemetry component version and command history is all coming from document database in the only moment when a sample portal contacts IOT hub is to retrieve the key this key has been generated by by IOT hub but you can also provide your own for for your devices now let's connect a simulated device we have here a console app that is simulating a device let's copy this key and start the simulator we see here that every second there is a new telemetry messages being sent and in the portal we can go in a telemetry dashboard and see the data updating in real-time what is happening is that that device is contacting our IOT hub the events are being received by our event processor host that is then contacting the dashboard to update it now let's see what happens if we send a command to stop this turbine in here for turbine 3 I want to send my stop command what happens is that the command is being received by a simulated device a record as being created in my command store and of course the telemetry reflect the fact that that the turbine is now stopping once it reaches 0 and it sends the acknowledgment back to the application back-end which then can update the command store and an update this portal here now let's start this turbine again and of course this will not be very interesting if we could do this only with one device IOT hub supports millions of simultaneously connected devices and in here I will start another simulated device and show how the telemetry gets displayed and it is flowing through the same pipeline as as before let's look now at at the code to implement this demo this is a class called device manager which is the code that is behind the list of devices that we just showed there is a method here is called provision device and we see that effectively the only two things that are happening is the insertion of a of a of an entry and in the document database and the creation of a new identity inside of IOT hub this is done very easily with the IOT hub service SDKs using your registry manager in this case we have a registry manager we call the add device method and and and we put as the parameter a new device with a new device ID that in our case was turbine 3 and we just set the status as enabled that's because we want the device to be able to connect right away there are cases were in your provisioning workflow you might want to create a device in a disabled State and then enable it later in here you see that I'm not setting any new key because IOT hub will auto-generate keys for you but you're free to generate your own with a certain minimum length now let's look at the simulator the simulator has three main components the first is a simulation loop which just creates a simulated values for wind speed to work in output power then there are two other components one that sends telemetry every second and then wonder is receiving the commands the central Emma tree it's really really easy it creates a new telemetry message with all the data from the state that is generated by the simulation loop and then it generates it creates a new message and then it calls the device client send event method the device client is part of the IOT hub device SDK for c-sharp in here we see how it can be created using the IOT hub hostname and an authentication method that contains the turbine ID and the turbine key we do offer many ways to authenticate and will offer more going forward when you receive events from the cloud you can use any way any method that it's compatible with event hubs in this case I'm using an event processor host and if an processor host is hosted in this case in a web job inside my web application and and and it's implemented as a very very simple application that is processing events and for each event it just discriminates telemetry messages from command response with the presence of a correlation ID property on the message if it contains a correlation ID it is assumed to be a command outcome otherwise it is assumed to be a telemetry message of course you're free to create your own categorization logic and in your own event processor using any other service such as stream analytics or as your storm or HD inside storm but this very simple process is doing it is discriminating events that are commands outcome from the one through our telemetry and it's using a system property called correlation ID to do that you're of course free to create your own categorization method when you want to send commands it is again very straightforward here the portal is again doing something very similar to the provisioning it is updating the command store in document database and then it's sending a command using IOT hub in in in this case we're using the service client class from the azure IOT hub sdk to send a message a new message is is created and is sent to a specific device ID the simulator in order to receive a message is calling a method called receive a sync and it does that in our receive loop it is called a loop because they receive a sync method we'll we'll return every time a new message is received or after a certain time out is expired in this case I have a timeout of five minutes and if that happens the receive command is is no you have done a chance to effectively regain control of your application and and do something else in this case if the command is is now I just call it again because I want to have I want to always be receiving messages from my IOT hub once I received a message this is just a simple byte array I will dis relies adjacent and then perform my command logic this was a very simple tour of of our sample scenario which illustrates the main capabilities of azure IOT hub azure IOT hubs supports millions of simultaneously connected devices it supports per device authentication and per device identities which make sure that your device connectivity is secure it does support high throughput device to cloud messaging and reliable cloud to device messaging and it has extensive support on the device and service SDKs you can try other IOT hub for free now on Azure comm thanks for watching you

4 Comments

  1. Ramesh Sigamani said:

    Well explained. Thanks to the author for taking time and educating the world 🙂

    May 22, 2019
    Reply
  2. Sandeep Mishra said:

    where can i download this app

    May 22, 2019
    Reply
  3. Timepass said:

    `wow ..Cool ..It would be very nice if any how we can get the sample code, so that we can also see the live demo

    May 22, 2019
    Reply
  4. Gautam Kadian said:

    Nice……….Very easy to understand. Is it possible that we can get the copy of your sample turbine code?

    Thanks in advance

    May 22, 2019
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *