Microsoft Azure Setup

Please note: Azure is a PAID IoT service - you will be charged for usage. For non-production usage, keep track of the billing & make sure that you shut off any running services if you're not using them.

Create an IoT Hub

Microsoft's Azure IoT Hub requires an active Microsoft Azure account. Azure is a PAID internet-of-things service, and will require you to enter a valid credit-card (even for their free tier).

Now that you have a Microsoft Azure account, you'll want to set up an Azure IoT Hub. This will be your "endpoint" for sending messages to, and receiving messages from.

To authenticate with the Azure IoT Hub, you'll need to obtain a Shared-Access-Signature token for your Azure IoT Hub.

From your Microsoft Azure Portal, open a new console instance by clicking the >_ icon on the top menu bar. 

Once the Azure console has been loaded and a connection is established, enter the following command into the console. Make sure to replace azure-hub-name with the name your IoT Hub.

Download: file
az iot hub generate-sas-token --hub-name azure-hub-name

After you hit enter, the Azure Console will take a moment and then display a freshly generated SAS token:

Download: file
[email protected]:~$ az iot hub generate-sas-token --hub-name airlift-test-hub
{
  "sas": "SharedAccessSignature sr=azure-test-hub.azure-devices.net&sig=jzaRYmbAK6eShkB1mU0fByZREuX4UV8mzfv0vnv7HyU%3D&se=1558473904&skn=iothubowner"
}

In the response, copy and paste the SAS token into a notepad or text file and save it somewhere safe. We'll need it in our the following step.

Note: The SAS token is not the full response returned by the Azure CLI in the code snippet above - it looks like the following:

Download: file
SharedAccessSignature sr=azure-test-hub.azure-devices.net&sig=jzaRYmbAK6eShkB1mU0fByZREuX4UV8mzfv0vnv7HyU%3D&se=1558473904&skn=iothubowner

Once you have a SAS token, you can continue to adding an IoT Device to the IoT Hub.

Add IoT Devices to your IoT Hub

Now that you have an IoT Hub set up, you'll need to create IoT Devices to connect to the Azure IoT Hub. Azure allows addressing of each device by a device identifier. This is incredibly handy if you have more than one device, such as a temperature logger, in your home. You can send data from, and to, each device using its device identifier.

From your Azure IoT Hub Portal, navigate to Explorers -> IoT devices

This page will display the devices currently on your IoT Hub along with metrics such as their Last Activity and Status

On the top left, click Add to add a new device.

In the Create a Device menu, make the following changes:

  • Set a unique Device ID 
    • You can set this to any alphanumeric value, make it as descriptive as you want!
  • Select Symmetric Key for Authentication Type
  • Tick the checkbox to Auto-generate keys
  • Enable Connect this device to an IoT Hub

Then, Click Save

You'll be re-directed back to the Device Explorer.

If everything worked correctly, you should now see your new device in the Device Explorer.

Congrats - you've successfully set up an Azure IoT Hub and connected a device to it! Next, we'll set up your CircuitPython device to connect to the IoT Hub.

This guide was first published on May 24, 2019. It was last updated on May 24, 2019. This page (Microsoft Azure Setup) was last updated on Nov 12, 2019.