Click here to Skip to main content
13,793,878 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.3K views
2 bookmarked
Posted 26 Apr 2018
Licenced CPOL

MQTT Publication with Microsoft Azure

, 26 Apr 2018
Rate this:
Please Sign up or sign in to vote.
This tutorial takes you from setting up a device in Microsoft Azure* all the way to viewing your data (sent via MQTT).

Editorial Note

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Programming language C++ (Arduino*)
Skill level Intermediate
Time to complete 5 minutes
Hardware needed UP Squared* Grove* IoT Development Kit
Target Operating System Ubuntu 16.04

This tutorial takes you from setting up a device in Microsoft Azure* all the way to viewing your data (sent via MQTT). The sketch is setup to read data from the Grove* Rotary Angle Sensor (at a given interval) and send it to the Microsoft Azure* cloud platform. The final step where you view your data is done in the Device Explorer* tool provided by Microsoft*. It is only supported on Windows* , see https://github.com/Azure/iothub-explorer for instructions on how to use the iot-hubexplorer node.js command line tool for other platforms.

What you'll learn

  • How to set up an IoT Hub
  • How to get the credentials for your device and enter them into the "Secrets" tab in Arduino Create*
  • How to view your data using the Device Explorer tool

Gather your materials

Software dependencies

  • libcrypto
  • libssl

These will already be installed if you are using the OS that was shipped with the UP Squared* Grove* IoT Development Kit. Otherwise you need to install them via apt-get.

$sudo apt-get install libssl-dev

To check if they are already installed :

$ldconfig –p | grep libssl

$ldd $(which ssh) | grep libcrypto

Plug in your sensor

Connect the Grove Rotary Angle Sensor to pin A0 on the Grove Pi+

Create an account

If you don't have a Microsoft Azure account, sign up for a free trial https://azure.microsoft.com/en-us/free/

Create an IoT Hub

You need an IoT Hub to enable communication between Microsoft Azure and your device. The easiest way to create an IoT Hub is through the Microsoft Azure portal. Follow the steps in https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal.

The portal is located at https://portal.azure.com

  1. Click "New" and search for "iot"

  1. Name your hub something unique, for example my-iot-hub###, where ### is some number. It is recommended to use the default settings for the IoT hub creation.

When it's done being created you should see it appear in the Dashboard.

Create a shared access policy

  1. Open your hub and select Shared access policies, under SETTINGS.

  1. Click Add.

  1. Select read, service connect, and device connect permissions. Give it a name such as "my-policy".

  1. The policy you created should now show up under POLICY.

  1. Click on your policy and copy the Connection string - primary key (also known as the Hub connection string). You will need it later.

Setup device explorer

View your data using either the Device Explorer tool or the iot-hubexplorer node.js command line tool (supported on Windows, macOS, and Linux*).

This tutorial will you walk you through using the Device Explorer GUI on Windows. See https://github.com/Azure/iothub-explorer for instructions on how to use the iot-hubexplorer node.js command line tool.

  1. Download and install the SetupDeviceExplorer.msi from https://github.com/Azure/azure-iot-sdk-csharp/releases.

  2. Enter the Connection string - primary key you copied from step #5 of the above section into the IoT Hub Connection String field in the Configuration tab of the application. Then click Update. You should see a popup confirming that it was successful.

  1. Go to the Management tab.

  2. Click Create and enter a Device ID, for example "test-device". The Primary and Secondary keys should have populated automatically.

  1. Right click on the device you just created, and select Copy connection string for selected device

Get the code

  1. Open the example Libraries>AZURE IOT DEVICE SDK>Examples>ClientMqtt

  1. Copy the connection string from step #7 above into the Secret tab of the sketch.

  1. Build and Upload the sketch.

View the data

Go to the Data tab and click Monitor. You should see a message saying "Receiving events" or similar. This is where you will see messages once your application is running on your target.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Intel Corporation
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

43 members


You may also be interested in...

Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.181207.3 | Last Updated 26 Apr 2018
Article Copyright 2018 by Intel Corporation
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid