2/10/2016

Getting Started with Internet of Things Azure Platform

You can hear IoT through all the noise, it's really starting to make headway.  And since I've been a Microsoft developer for over 20 years, and since I have an Azure account, thought I'd get started with a demo.

https://azure.microsoft.com/en-us/develop/iot/



Click on the link: "Don't have a device? Configure your IoT Hub"



One thing you'll notice, right off the bat, is the support for c#, Java and Node.JS.  This pattern aligns with other tutorials we've seen on the the Azure platform, for example, the AzureML samples.

For this demo, we'll need Visual Studio 2015 and an Azure account.  Check.  and  Check.

Visual Studio 2015:


Microsoft Azure:



Clicking the "+" sign, we see a new feature, "Internet of Things":



Enter info:



Click "Create" to provision your new IoT platform on the Microsoft Azure cloud ecosystem of solutions:

And it's deploying:



About 5 minutes later, our IoT is ready:



And that concludes the initial setup of our first IoT application on the Microsoft Azure platform.  Amazing how easy that was.

Next, we need to build a c# console application to connect to this.  Open Visual Studio 2015, create "New Project" --> c# --> Console App --> Name:



Right click the project in Solution Explorer --> Manage NuGet Packages --> Package Source = nuget.org, check the box for Include prerelease, in the search box, enter "Microsoft azure devices'



Click Install, accept terms:



Installing software locally...

Turns out the refernce to Microsoft.Azure.Devices is not recognized, so need to download it from NuGet...




See both in the References now:



Now it recognizes our 2 new lines of code:



In Program.class added 2 lines and replaced with actual values from Azure IoT app we just created:

static RegistryManager registryManager; 
static string connectionString = "{iothub connection string}";

Add the following method to the Program class:

private async static Task AddDeviceAsync()
{
    string deviceId = "myFirstDevice";
    Device device;
    try
    {
        device = await registryManager.AddDeviceAsync(new Device(deviceId));
    }
    catch (DeviceAlreadyExistsException)
    {
        device = await registryManager.GetDeviceAsync(deviceId);
    }
    Console.WriteLine("Generated device key: {0}", device.Authentication.SymmetricKey.PrimaryKey);
} 
 
  1. Finally, add the following lines to the Main method:
    registryManager = RegistryManager.CreateFromConnectionString(connectionString);
    AddDeviceAsync().Wait();
    Console.ReadLine();
    
 Ran the console app in Visual Studio 2015:
 
 
And it ran without errors.
 
That's the first step of the 3 part series. 
This app reminds me of the Service Bus app I 
created a while back. I think step 2 actually 
uses Service Bus.
 
Our first IoT application using Visual Studio 2015 and Microsoft Azure IoT solution.
 
As always, thanks for reading.