Dashboard Icon

Helium Azure IoT Channel Guide


Azure IoT is Microsoft's IoT solution that is part of their Azure Cloud product suite. It's a popular choice among enterprises and developers that are building IoT applications who need to store, analyze, and query device data in the cloud. This guide walks you through deploying the Helium Azure IoT Channel available within your Helium Dashboard.


Prerequisites

To get started, you'll need accounts for both Helium Dashboard and Microsoft Azure IoT along with and an activated Helium Atom.

Configuring and Deploying the Azure IoT Channel

Finding your IoT Hub Credentials

Once you have your Azure IoT Hub created:

  1. Click Shared Access Policies from the left menu.
  2. Click RegistryReadWrite entry in the middle pane. This allows Helium Atoms to have read/write permissions.
  3. From the column on the right, make sure the Permissions are set to Registry Read and Registry Write
  4. Locate the Connection String - Primary Key and click the Copy icon. (You have an option use Connection String - Secondary Key here also, but not required)

DocImg

Deploying the Channel in Helium Dashboard

  1. In Dashboard, go to Channels and create a new Azure IoT Hub channel
  2. Copy and paste the Connection String from Azure IoT Hub

    • The Hostname will follow the format IoTHubName.azure-devices.net. For example, if your Azure IoT Hub is named "Connected Chicken", your Hostname will be ConnectedChicken.azure-devices.net.
    • The sharedAccessKeyName should be RegistryReadWrite
  3. Name your Channel and click Create.

Azure IoT MQTT Settings

Once deployed, the Helium Azure Channel auto-generates the correct configuration information needed to use the MQTT Broker provided by Azure IoT. Specifically this enables you to:

DocImg

Azure IoT MQTT Settings Usage
MQTT Connection String Use this to connect to the Azure MQTT broker for this channel.
Atom MQTT Subscription Topic Use this to subscribe to messages from a given Atom on the Azure MQTT broker.
Atom MQTT Publish Topic Use this topic to send message to a given Atom on the Azure MQTT broker.

Azure IoT Channel Configuration Variables

Helium enables developers to interact with sensor settings and parameters over the air (OTA) using Configuration Variables. There are two types of Configuration Variables: Channel and Global. For the Azure IoT Channel (and all other Cloud Channels), developers can use Channel Configuration Variables to orchestrate logic between Helium Devices and Azure IoT's Device Twin feature. Device Twins are an excellent way to model and alter sensor state programatically. And with Channel Configuration Variables, you can ensure those state changes are both sent over the air to devices as needed; and reported back the Azure IoT.

Device Twins and Your Sensor Code

To use a Channel Configuration Variable with the Azure IoT Channel, you'll need two things:

Here's an example of an Azure IoT Device Twin (as seen through their Device Exlorer).

DocImg

To interact with this Device Twin programtically, you simply reference the relevant fields in your sensor's code using the Configuration Variable schema.

Here's an example function from an Arduino Sketch that uses Configuration Variables to talk to the example Device Twin above. Here, our sensor will get the latest interval_ms setting based on the corresponding "desired" value in the Device Twin and then report it back to the Azure IoT Device Twin where it will be displayed as the "reported" interval_ms value.

void
update_config(bool stale)
{
    if (stale)
    {
        DBG_PRINT(F("Fetching Config - "));
        int status = config.get("channel.interval_ms", &send_interval, 5000);
        report_status(status);
if (status == helium_status_OK)
        {
            DBG_PRINT(F("Updating Config - "));
            status = config.set("channel.interval_ms", send_interval);
            report_status(status);
        }
    }
}


And if you wanted to interact with this same Device Twin as part of a control pipeline using the Helium Python Client on the Raspberry Pi platform, the equivalent code would look like this:


from helium_client import Helium

helium = Helium("/dev/serial0")
helium.connect()

channel = helium.create_channel("azure_test") # Be sure to use your channel name here

# Access an instance of Configuration
config = channel.config()
# Get the channel setting for interval_ms
interval = config.get("channel.interval_ms")
# Report the device having set interval_ms
config.set("channel.interval_ms", interval)