Hey friends, I'm Scott Hanselman, and
it's another episode of Azure Friday.
I'm here with Olivier Block,
who's bribing me with IoT devices.
Now, I'm gonna be a little bit negative,
we've seen IoT Hub talks before.
Maybe somebody takes a small electric car, and
they send the telemetry data into the cloud.
That's an amazing thing,
millions of devices sending telemetry data in the cloud,
is data from here to the cloud, what else can I do with IoT Hub?
>> Actually, way more, cuz as you were mentioning,
that telemetry is the easy thing,
actually, something we've been doing forever.
Using the cloud as the intelligence review system,
that's what we're doing right now.
But now the customers were actually doing that,
they care about few more things, such as fast provisioning
devices, securing their devices, managing the devices.
So when it comes to connecting one device,
like we're doing here, having fun.
We engineers playing with maker devices, it's kind of easy.
But then when it becomes something which is at scale,
think about simple things such as, this device,
to connect to Azure, needs to have unique credentials.
You want to have a way to differentiate one device from
another one, and you want to be able to address them.
So basically, these devices have to have some unique piece of
software down there that allows you to actually identify them.
And you cannot do that in a factory, right, cuz factory
is that creating these millions of devices super rapidly.
So you cannot go there and flash that unique ID.
And by the way, if that ID is compromised,
what are you gonna do?
>> Exactly, I don't want
a public endpoint that people can send garbage data to.
>> Exactly, and that comes actually with other things
such as device management.
So once the devices are in the field, how do you configure
them, how do you address devices in batches?
Like in this building, we have HVAC systems,
we have tons of sensors.
What do you do when it comes to things like updating
the firmware, updating the configuration for
a full building, a full level on the building, things like that?
>> Yeah, things happen,
there was a big WPA Wi-Fi problem that happened.
And it turned out, Microsoft had already patched everything by
the time it was announced.
So being aware of that kind of stuff is so important.
>> So what do you need is actually having
an infrastructure that allows you to have the devices
connected, authenticated, and then manageable.
And that's what IoT Hub does, beyond just the telemetry,
that you can actually do without a full-blown PaaS service
like IoT Hub.
You can do that with other things that are meant
to transport data from A to Z, right, like Event Hub or
something like that.
IoT Hub gives you all that infrastructure to
do device management.
It has very rich features,
such as device twins, device direct methods.
I'm gonna show you device twins in a minute,
just to illustrate one of these features.
>> Yeah, let's see something real.
>> They are very complicated, I would say, in principle,
very secure, but very powerful.
And we offer SDKs to allow you to address these various
features in a very easy way.
Another thing that I want to mention is that if you want to
see a full-blown implementation of a real device that has
built-in security and so on, and integration to the Azure IoT
device management, windows IoT Core is a good example of that.
We've done lots of work with the team to integrate the clients
for Azure IoT Hub and the device management features.
Cuz we know Windows well at Microsoft, and so
we know how to do the firmware update,
how to do an application update, and so on.
And all that now is super easy to do in embedded devices
running IoT Core.
But obviously we're talking other devices as well,
like Linux-based ones, or
these tiny microcontroller type of devices like this one.
So what I'm gonna show you is the usage of device twins,
which is that very simple concept of a digital
representation of a device.
So you have basically, it's a JSON file that sits
in a Cloud managed by IoT Hub, is one of them for
each of the devices that are connected to our IoT Hub.
In this device twin, you have several sections,
the first one is a section called tags.
This is only something that the cloud sees, not the device, and
that allows you to group your devices.
You can create your own tags and say, hey, there's a tag
location, there's a tag building number, there's a tag level.
And that allows you, using queries and
what we call jobs, to address these devices in the bulk.
I want to update all of my devices on floor number one,
I can just send a little, like SQL query.
To then pass a command for
updating firmware on all the devices on that level.
>> Is the device twin the shadow of it?
>> It is.
>> It's a proxy?
>> Yeah, yeah,
it's a representation of the configuration of the device.
[CROSSTALK] >> How do you know that it's in
sync, though, which one is the authoritative source?
>> So IoT Hub actually, the service itself and
the client are taking that synchronization in charge.
And you have this notion of properties,
the tags I was mentioning are IoT Hub ownership.
So you can, only with credential that are high level, access
the tags and edit them, right, so basically, IoT Hub owns that.
>> So that's the authoritative source.
>> That is, IoT Hub is the source, is the big boss here.
And then you have those sort of properties, and
you have two sections.
You have notion of reported properties that device owns and
pushes up.
>> Okay, then that's the authoritative source.
>> Then you have the notion of desired properties.
Basically, what the cloud wants the device to be in,
it will send, and the device can only read these ones.
>> So basically, you have this notion of desired and
reported properties that go in between.
And your code on the device, leveraging the SDK, that takes
care of the plumbing, knows what to do with that information.
So IoT Hub, on its side,
is actually doing the synchronization, and
also allows you to address those devices offline.
Cuz devices are not always connected, so basically,
device twin allows you to say, you know what?
Next time this device gets online,
I want its firmware to be at that version.
Device comes online,
synchronizes a twin through the SDK.
Sees that there's a new device firmware version that
is required.
And will then implement that firmware update, and
then when it comes back online,
report its new firmware version to the backend, to IoT Hub.
IoT Hub can see that new firmware version, and report to
your backend application that everything is green, and
the device is up to date.
>> And does that in some way help prevent things from
getting bricked?
Because there's always the fear that you'll have
some device out there in the world that's gonna get bricked.
>> Yeah, to a certain extent, actually, because what
we are providing is the plumbing to make that happen.
The hardware manufacturer, the one who's building the hardware,
knows how to do the firmware updates.
>> They know how to do their update,
you just know how to give it to them successfully, and
report success and versions.
>> The good news is that they don't have to care about
securing that connection, we take care of that.
They don't have to care about that flow of that exchange with
the cloud, because we take care of that.
They don't have to care about the security in between,
because we encrypt everything.
So basically, they can focus on what they know how to do,
just updating the firmware.
>> And once the file has arrived,
they can be assured that it's the correct file.
It's cryptographically significant, the SHA is correct,
it's not corrupted, nice.
>> And then it can do everything I just mentioned,
[CROSSTALK] show you how that works.
>> Let's do it.
>> What I'm using here is VS Code, love the thing,
there's an Arduino extension for VS Code, where we're actually
coding using the Arduino extension here.
>> So you're writing .ino files,
I usually do this right in Arduino-
>> I'm writing C code.
>> Seriously?
>> That's the beauty of it, [CROSSTALK]
>> Yeah, yeah,
I usually write this in the Arduino IDE.
>> Yeah, exactly, well, you know what?
The Arduino extension actually leverages your Arduino IDE in
the back, at least all, it's scripting everything.
>> It's automating everything, nice.
>> You can do everything that you used to do in
your Arduino IDE in VS Code.
>> All right, well, you sold me on that part.
>> [LAUGH] I can show you more, but it's too much.
>> We'll talk later.
>> So we have the typical Arduino code here,
this is the setup section.
And what I'm gonna show you is how simply you can actually
leverage that rich feature, the twin.
You can actually, in the init function,
you initialize the client.
And then you set a callback for
receiving a notification when there's a new device twin
information, so that's your new device.
You want to be notified when the cloud updated the desired
properties.
>> Of the desired properties, and
then you can impose them or not.
>> Exactly, and it's a simple callback, attach the callback,
and in your code, you'll be notified.
The callback actually is just above here, and
what the callback does, it actually parses that twin.
Gets the information out of it, and then the parsing actually
looks for the information, the data called user LED state.
>> It comes down as JSON, so you just use whatever,
use your local JSON.
>> Whatever JSON, and
here you can see, I'm looking at desired properties, and
I'm looking at the object called user LED state.
So you can imagine what I'm going to do with
that information.
>> Let me see if I can guess,
you're gonna change in the cloud the desired property of
an LED to be something, it will then be imposed upon it.
>> Exactly.
>> But the delivery, all of that, it'll just appear, and
it needs to make the decision in the callback to impose that or
not, nice.
>> Exactly, you got it right, the other part is, in the loop,
that's my regular loop in the code, what I'm doing is,
I'm reporting my state.
If something changed on my sensors or whatever,
I can actually report that state up to the cloud.
>> And then that tells you that the desired state,
the goal state achieved?
>> Exactly.
>> And how often are you checking that?
>> And so in that one, actually that loop is a two second, but
I can put it a minute, two minute, whatever,
it really doesn't matter.
And here we can see it's like JSON, it's like C,
C is doing JSON, [CROSSTALK] >> And
if you've ever done Arduino stuff,
there's already great support for JSON on JSON Arduino.
>> Yeah, exactly.
>> And even though it's C, it's easy to parse.
>> Exactly.
>> Lovely. >> No-brainer here, [CROSSTALK].
>> Which of these LEDs matter?
>> So we have several LEDs here- >> I see the one marked
User on the bottom.
>> There's one called User,
that's one of them, actually- >> That's us?
>> Turned on.
>> All right. >> There's one called Azure
just above.
>> Is it, yeah.
>> Yeah, it tells you you're connected to Azure,
isn't that cool?
>> I see, the programming is there [CROSSTALK].
>> Exactly [LAUGH].
>> Okay.
>> So what I have on the screen is the web app.
The web app itself gets its information from IoT Hub-
>> That's pretty cool, actually.
>> From the backend, and reads the state of the device.
>> Did you draw that?
>> And actually,
we have some champions that actually did that.
>> That's pretty cool.
>> [INAUDIBLE] [LAUGH] and so the idea here is to report to
the user or to a backend system the state of the device.
And you can see that infrared sensor is working, nominal,
no problem, and so you have this version information.
Now what I wanna do is turn the LED on, right, so I can actually
set the desired state for that- >> DO me a favor, can you turn
that on and off, and then they can zoom in on the camera there
and take that- >> Off.
>> That's this one right here, the one marked user, there it
is, just turned off, it's right below the one marked Azure.
And the we hit it again, and
then the desired state then becomes the actual state.
>> Exactly, so that's the beauty of that.
>> That's pretty cool.
>> I would say it's like the typical IoT Maker demo,
blinking a LED.
But now we're doing that in a very structured way.
>> That's the trick.
>> And that's the trick, that's the difference.
>> Right, because we just turned on a LED, and
we finally answered the question, but does it scale?
>> Exactly.
>> It does scale. >> Exactly, and
how do you address these millions of devices out there?
If I want to turn a LED on only 50% of the time,
with a specific type of query, based on other sensors' data,
eventually, their own states- >> In a secure,
structured and reliable way.
>> Exactly, and so we have tons of other things that IoT Hub can
do, I guess we're gonna do that another session.
Device twin and device management in general,
something that you get for free with IoT Hub.
>> So I see here that this is the Microsoft Azure IoT Starter
Kit, that you have so kindly bribed me with.
Can people buy these and
people start playing with IoT themselves?
>> Yes, so what you can do is actually go to aka.ms/devkit, or
there's the URL down there.
>> Aka.ms/IoT-DevKit.
>> Exactly, and once you have that, actually you have access
to a bunch of samples and code provided on GitHub.
All the SDKs are on GitHub, open source, and
we have all these samples as well up there.
And because you're gonna write some nice blog post based on
that, [CROSSTALK] one more.
>> All right, fantastic,
I am learning all about Azure IoT hub here on Azure Friday.
[MUSIC]