Another Visual Studio Extension’s Friday, now with almost a repost from Greg Duncan original post in Channel9. However, this extension allows you avoid plenty of configuration steps if you want to work with Azure Iot Hubs. You only need to focus on your app business needs: Send or receive data from the Azure IoT Hub.
So, a simple way to describe this is with a quick step-by-step
- Install the extension from Visual Studio Gallery
- Create a Console App
- Add a new Connected Service
- Follow the wizard steps to connect to the correct Azure IoT Hub
- Select “Azure IoT Hub” and click “Configure”
- You need to enter your Azure credentials, and the wizard will retrieve the list of available Azure IoT Hubs you have in your Azure subscription
- You must select the Azure IoT Hub, and connect to this Hub
- After you connect to the Hub, the wizard will display the list of devices who are already defined and configured to use this device
- You can select one device or create a new one. For the sample, I’ll go with my Device01 sample device
- So, now is time for code generation
- A couple of NuGet packages will be added into the project
- After this, a couple of new items are included in our project.
- Maybe the most important is the AzureIotHub.cs class. This class has 2 main methods
SendDeviceToCloudMessageAsync(), to send messages to the IoT Hub
ReceiveCloudToDeviceMessageAsync(), to start listening to messages from the IoT Hub
- To send data, we only need to call the 1st method like this
- That’s it in terms of Hello World project. However there are some additional tasks to do.
- First one will be to move away and secure the Azure IoT Hub connection string from the class to a more secure place. The wizard stores this information in a simple text constant. Which is good to test and debug, but not so good for a final release.
- Next step will be probably, make some updates to the main 2 methods. As you can see in the next image, the send message method, send an static “Hello Cloud” message. I’m sure that your app will require some extra information here
- More detailed steps are included in the GitHub page
So, this will be my basic review of the extension, which is basically a time saver !!!
Greetings @ Toronto
- Visual Studio Gallery, Connected Service for Azure IoT Hub
- Channel 9, Connect IoT to Azure IoT with Visual Studio Connected Service Extension
- Github, Get started with Azure IoT Hub and Visual Studio connected services (C#)