1. Home
  2. Training Library
  3. Microsoft Azure
  4. Courses
  5. Introduction to Azure IoT Hub

Devices and Developers

The course is part of this learning path

play-arrow
Start course
Overview
DifficultyIntermediate
Duration1h 12m
Students281

Description

Introduction to Azure IoT Hub

IoT isn't anything new, in fact it's been something companies have been doing since before it was named IoT. So you might wonder, if it's not new, then why all the hype? It's a good question and the answer is complex. However these days there are a few things that have enabled IoT to take off. The internet is ubiquitous and reasonably inexpensive, makeing it easy to get devices online. The cloud is another enabler, and it's an important one, because it's helped to make it possible for individuals to do things that were once cost prohibitive. Another enabler is hardware devices such as the Raspberry Pi or Arduino. These boards make it easy for just about anyone with $40 to start prototyping.

Since the cloud is a major enabler of IoT, it's no surprise that cloud vendors are creating their own IoT solutions. Azure has a lot to offer in the IoT world, and one of the services is IoT Hub. IoT Hub is a services that provides a device registry as well as mechanisms for cloud-to-devices and device-to-cloud communication.

This course is intended to help get you up to speed on using Azure IoT Hub, and in particular, with the IoT Hub SDKs.

Getting Started With Azure IoT Hub: What You'll Learn

Lecture What you'll learn
Course Intro What to expect from this course
Introductio to IoT Hub A high level overview of what Azure IoT Hub is, and its basic capabilities
Devices and Developers What are devices
Device Management The IoT Hub Devices Registry
Device to Cloud Device to cloud messages
Device to Cloud - Part 2 Endpoints and file uploads
Cloud to device Sending messages to devices from IoT Hub
Device Configuration Configuring device state, and invoking messages
Next Steps What's next

 

The source code for this course can be downloaded from Github

If you have thoughts or suggestions for this course, please contact Cloud Academy at support@cloudacademy.com.

Transcript

Hi and welcome back!

In this lesson, we'll talk about devices and developers.

First, let’s start with a definition. I’ve used the acronym IoT dozens of times throughout the course, so far. Which as you probably know stands for Internet of Things. So that begs the question, what is a “thing?”

The philosophical definition is that a thing is an object or entity. Which is a bit too simplistic for our purposes.

Let’s try and redefine it a bit, and in place of thing let’s say “device.”

Looking at Wikipedia, one of the definitions that best describes a device is “an appliance.”

Looking up appliance it says: “An appliance is a device for a particular task.”
So, it’s a bit of a circular reference, but it works well...wouldn’t you say?

Alright, why are heading down a rabbit hole of definitions? It’s because I want to make sure it’s clear that when we talk about IoT, the “thing” could be any sort of device, even if it hasn’t been thought of yet.

It’s common for us developers to think in terms of mobile devices, PCs, gaming consoles,TVs, etc. However while all of these serve a specific purpose, they’re all still rather generic devices.

While all of these could be considered devices, when we talk about devices, we’re really talking about embedded devices.

An embedded device is the technology that makes a “Smart” device, smart, because it allows local processing. Typically it has a communication bus that allows communication with I/O peripherals.

This could be either a micro-controller, which are processors that are optimized for I/O, and have lightweight operating systems. Or i could be a micro-processor.

So, an IoT device is an embedded device with internet connectivity, which allows it to send and receive data over the internet.

If you look at some of devices back in 2010, you’ll find a lot of devices had internet connectivity

However, if you look at IoT devices today, you’ll find lot more devices that can communicate overt the Internet than I can fit on the screen.
It’s a market that’s continually growing, and one with a lot of interesting devices, making it an interesting space to be a part of.

So when we talk about devices, we’re not talking about any one thing, rather we’re talking about the abstract representation of all the potential devices.

So, if you’re new to the world of IoT, you may be wondering, what are the challenges for developers when working with IoT? And that’s a great question. The first is that, developing for devices is quite different than developing an application.

You have one or more device types, and you have to build out and deploy there functionality.

Then you have to develop a backend infrastructure in the Cloud that can handle data from the devices as well as send data to the devices when needed.

Then you need to make the devices and backend talk to each other.

If you were to implement all of this for yourself there’s a lot of work to do to create a robust platform.

So, considering some of the challenges, why is IoT such a growing market?

It’s because of some of the IoT enablers. The first one is Internet, which is ubiquitous. Now that internet connectivity is just about everywhere we can connect every device to the Internet.

Then there’s Cloud Computing, which enables you to build a robust backend for these devices. Think back to just several years ago and imagine trying to build an IoT solution that could accommodate 1 million simultaneous connections. Maybe if you worked for a large company with a lot of resources, it’s something you can picture. However, with cloud platforms, what was once the domain of large companies can now be done by an individual.

Another IoT enabler is commodity hardware, which is inexpensive hardware, that’s a small fraction of a selling price compared with similar products a few years ago.

The existence of commodity hardware has created the phenomenon of “makers” in recent years.

Modern commodity hardware such as an Arduino or Raspberry Pi, allows you to do a lot of prototyping. This allows you to try out your hardware ideas without spending a lot of money.

While it isn’t an out of the box industrial grade product, they have changed the way we think about the embedded world.

The market is changing quickly!
In fact, these boards that were born as open source projects, now have similar industrial grade boards; this makes it easy to get started with IoT projects.

In fact, there are a lot of ready-to-use boxes that you can buy on the Internet, containing plug-and-play sensors, and actuators; allowing you to focus on prototyping the functionality of the IoT device.

And due to the prevalence of IoT, there are a lot of companies that devices that can natively talk with different IoT infrastructures.

I don’t want you to get the impression that I’m suggesting that you can avoid electronic engineers, process engineers, and electronics manufacturing. Because that’s not the case.

However, the embedded world is no longer a niche, it’s now much more open.

Now software engineers can also contribute with their experience to the world embedded devices.

It’s no longer a world of propriety hardware and tools.

Software engineers can now contribute with their experiences in methodologies like Agile, with patterns to write better code, with cloud infrastructure to prepare data collection and management, as well as with creating open source software solutions, allowing anyone to contribute.

Since the hardware is now open, it’s opened up the tools and languages available as well. Newer and better tools mean that you can work with modern compilers, IDEs, and SDKs.

There are fantastic debuggers and devices simulators, allowing you to build better solutions.

You have access to all the modern languages.

Sure, you still have C, which is the most common language in the embedded device world. However you also have JavaScript with Node.js, Python, and C#, among others.

So in this new world of IoT, what’s the role of a software developer?

They can develop and test software to process device data in the Cloud.
They can develop and test the device's software design.
And while they probably can't check real sensors and actuators every time, they can use simulators to work with fake/random data.

Simulated devices are often just console based apps that simulate communication by sending messages.

This is where IoT Hub can help out, because IoT Hub provides a Device SDK for several programming languages, and part of that SDK is a device simulator.

All of the device SDKs are open source and you can find them on GitHub.
It’s worth taking a look at the code, since it’s freely available.

In the coming lessons we’ll be using device simulators that are based on the C# device SDK. I’ve created some simulators for this course, as well as a simple helper library. Let’s check out how to prepare a Visual Studio solution to use the .NET SDK an optionally my helper library.

The final solution is available to download. If you want to try anything you seen in the course out, you can find a link to the code in the course description.

We are here in Visual Studio 2015 and I’ve already created a solution as well as a library project.

This library has some simple tools and helper functions, to help you develop command line applications that’ll serve as simulated devices. You can certainly do all of this without it, so don’t feel like you’re required to use it.

Let’s add a new console application that I’ll call IoT HubMySimulatedDevice.

I need to add a reference to my IoTCommandLine library.

The library targets .net Framework 4.6.2, so I need to change the framework target version of my project.

Then you need to go to Manage Packages and then search for the package: Microsoft.Azure.Devices.
You will find a few libraries.

For a simulated device, you'll need to reference the Devices.Client library. So let’s install that and fast forward to once it’s complete.

Great.

Let’s head into the Program class to set up the “main” method.
A typical way to work with new asynchronous code in C# is by creating a "static async method.”

Then from the Main function, you just call "MainAsync, and pass in the args, and then call the Wait method.

However, if you’re using my library, you can use the WaitFor method. First you need an import.
And then you can just write WaitFor(MainAsync(args)). I use this method because I find it bit more readable. However, to each their own.

Next, if you wanted to interact with IoT Hub, you need an instance of a DeviceClient. And you can do that by including the Microsoft.Azure.Device.Client namespace.

Then you create a DeviceClient object with static method to create specifying a connection string.

Where do you find a connection string? It could be from a parameter on the command line or built up from some other arguments.

If you were to pass it in via the command line, then you can either parse it yourself, you use my helper library. If you use my library you can call the StringArgs method, and pass in the name of the command line argument. That doesn’t explain where the connection string comes from initially, however we’ll be getting to that later in the course.

In order to send data to IoT Hub you can use the SendEventAsync method, of the Device Client. In the coming lessons I’ll explain all of this more in depth. For now we’re not going to send any data, since that’ll happen later in the course.

So, let’s wrap up this course, and recap what we have covered

In this lesson, we covered why IoT is important and some of its enablers.

It’s no longer a world of proprietary embedded device. It’s a world of new devices connected to the Internet that borrows a lot of what’s good about modern development.
New embedded devices use the latest micro-controllers or microprocessors, and so most of the functionality is now more software than hardware.

All this allows software developers to contribute to IoT and device development. They can bring their experience in building real-world scalable and resilient software architectures to IoT development, which adds a lot of value.

In the next lesson, we will start talking about Device Management, which is how devices are defined inside of IoT Hub.

Alright, I’ll see you in the next lesson!

About the Author

Marco Parenzan is a Research Lead for Microsoft Azure in Cloud Academy. He has been awarded three times as a Microsoft MVP on Microsoft Azure. He is a speaker in major community events in Italy about Azure and .NET development and he is a community lead for 1nn0va, an official Microsoft community in Pordenone, Italy. He has written a book on Azure in 2016. He loves IoT and retrogaming.