Azure IoT Central

When it comes to Azure and the Internet of Things (IoT), there are several options that can be considered in order to come up with a design that encompasses the common objectives (Device Connectivity, Data Processing & Analytics, Presentation & Business Connectivity) typically sought after in an enterprise-grade solution. 

Options:

  1. Pick and choose (a la carte) from the laundry list of Azure services to come up with something custom.
  2. Deploy a pre-configured solution with Azure IoT Solution Accelerators (formerly known as Azure IoT Suite).
  3. Azure IoT Central - A fully managed SaaS (software-as-a-service) offering.

Azure IoT Central aims to lower the barrier of entry by abstracting much of the complexity and technical debt typically required to deploy and manage an IoT solution. If you are looking to accelerate time-to-value and don't require deep levels of service customization, Azure IoT Central is a great place to start.

Note: Azure IoT Central and Azure IoT Solution Accelerators are underpinned by the same services typically found at the core of any Azure IoT solution (e.g. Azure IoT Hub, Stream Analytics, Time Series Insights, etc).

azure_iot.png

UI Overview

Home
The homepage is the landing area for your IoT application. When in Design Mode (top right-hand corner), you can customize your homepage by adding new or editing existing tiles. At the moment, tiles can either be in the form of a Link (Title, URL, Description) or an Image (Title, Image, URL).

azure_iot_central_home_page.png

Device Explorer
Device Explorer provides a list of device templates (aka device types) and devices associated with those templates. It is within this section that you can add real or simulated devices.

azure_iot_central_device_explorer.png

Analytics
The Analytics page visualizes data from connected IoT devices, allowing operators to analyze and monitor for potential issues. This section allows for a certain level of customization (e.g. switching between device sets, toggling measures to be visible or hidden, changing the aggregation type, etc).

azure_iot_central_analytics.png

Device Sets
Device sets allows us to define a grouping of related devices (i.e. a sub-group of devices within a particular device template). For example, I may define a device template (aka device type) of Raspberry Pi, but would like to sub-group devices of this type by particular characteristics to manage them as a collection (e.g. by Customer, Installation Date, Manufacturer, Location, etc).

azure_iot_central_device_sets.png

Application Builder
Application Builder has links a builder can use to either create a device template (Application Builder > Device Templates > Custom) or configure the home page (i.e. Homepage with Design Mode toggled ON).

azure_iot_central_application_builder.png

Administration
The Administration section enables an Administrator of the application to configure:

  • Application Settings (Image, Name, URL)
  • Delete the application
  • Add or Delete Users
  • Extend your trial or convert to paid
azure_iot_central_administration.png

Note: The image below provides a helicopter view of the primary screens when using the sample Contoso application. These sections are accessible from the side menu panel.

azure_iot_central_ui_overview2.png

Demo: Build an IoT Application in Minutes

Prerequisites

  • A valid Azure subscription.

1. Get Started 

  1. Navigate to https://apps.azureiotcentral.com/
  2. Sign-in with your Azure username and password.
  3. Click New Application
Screen Shot 2018-06-24 at 10.32.11 am.png

2. Create Application

Choose the following options:

  1. Payment Plan = Free (7 Days Trial)
  2. Application Template = Custom Application
  3. Application Name = <enter any name> (e.g. My First IoT Application)

Click Create

Screen Shot 2018-06-24 at 10.36.11 am.png

3. Configure the Homepage

  1. Toggle Design Mode ON (top right-hand corner)
  2. Hover your mouse over one of the existing tiles until you can see a pencil and cross (X) icon, click the (X) to delete the tile.
  3. Repeat this step until all existing tiles have been deleted.
  4. Click Image, and upload an image (e.g. company logo) then click Save.
  5. Click Link and set the following properties: 
  6. Click Save
  7. Hover over your newly created tile and move your mouse to the bottom right-hand corner until you see the cursor change to indicate that you can click and resize the tile. Resize the tile so that it is double the standard width.
  8. Finally, turn Design Mode OFF.

Upon completion, your home page should look something like the below.

azure_iot_central_custom_homepage.png

4. Device Template

Before we can start adding real (or simulated) devices, we need to create a device template. You can think of a device template as a way of describing a device type (e.g. Smart TV, Thermostat, Lighting) that defines the characteristics and behaviors of devices that will ultimately send data back to Azure IoT Central.

In this demo, my MacBook Pro will act as the IoT device and therefore I will create a 'Laptop' device template.

  1. Navigate to Application Builder > Create Device Template > Custom
  2. Enter a name (e.g. Laptop) and click Create
  3. Click + New Measurement
  4. Select Telemetry
  5. Set the following property values:
    • Display Name: CPU Usage
    • Field Name: cpu
    • Units: Percent
    • Minimum Value: 0
    • Maximum Value: 100
    • Decimal Places: 1
  6. Click Save
  7. Jump to Properties
  8. Toggle Design Mode ON
  9. Click Text
  10. Set the following property values:
    • Display Name: Manufacturer
    • Field Name: manufacturer
  11. Click Save
azure_iot_central_device_template.png

5. Add a Real Device

  1. Navigate to Device Explore
  2. Click on the + New dropdown menu and click Real
  3. Click on the image to update the device logo.
  4. Click on the text on the right-hand side of the image to rename the device (e.g. Taygan's MacBook Pro)
  5. Navigate to Properties and update the Manufacturer (e.g. Apple) and click Save
  6. Near the top right-hand corner, click Connect this device
  7. Copy the primary connection string (make a note of this value to be used later in the code sample, e.g. paste into a text editor).
azure_iot_central_add_device.png

6. Setup a Python environment

The code sample was made to work with Python 3 (I'm specifically running 3.6.4). If you haven't already installed Python 3, do that first. In addition to the standard libraries, you will also need to install requests and psutil.

pip install requests
pip install psutil

7. Update and Execute the Code

The primary connection string that was copied in the last step within 5. Add a Real Device should have looked something like this...

example_primary_connection_string.png

As you can see in the string, there are values for HostNameDeviceId and SharedAccessKey. Extract the values to update the appropriate variables within the code. For instance, the above example would look like...

example_iot_hub_settings.png
  1. Copy and paste the code into a file within your Python environment (e.g. handler.py).
  2. Update the variables HOST_NAMEDEVICE_ID, and SHARED_ACCESS_KEY with the values from your primary connection string.
  3. Execute the python script (e.g. python handler.py).

Note: If successful, this will start sending CPU usage from your device to Azure IoT Central.

import base64
import hashlib
import urllib
import hmac
import requests
import json
import time
import psutil

# Azure IoT Hub
HOST_NAME = 'ENTER_YOUR_HOST_NAME'
DEVICE_ID = 'ENTER_YOUR_DEVICE_ID'
SHARED_ACCESS_KEY = 'ENTER_YOUR_SHARED_ACCESS_KEY'

# Programmatically generate a SAS token for using the IoT Hub REST APIs
# https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token
def generate_sas_token():
    expiry=3600
    ttl = time.time() + expiry
    sign_key = "%s\n%d" % ((urllib.parse.quote_plus(HOST_NAME)), int(ttl))
    signed_hmac_sha256 = hmac.HMAC(base64.b64decode(SHARED_ACCESS_KEY), sign_key.encode('utf-8'), hashlib.sha256)
    signature = base64.b64encode(signed_hmac_sha256.digest())
    rawtoken = {
        'sr' :  HOST_NAME,
        'sig': signature,
        'se' : str(int(ttl))
    }
    return 'SharedAccessSignature ' + urllib.parse.urlencode(rawtoken)

# Send data to IoT Hub
def send_message(token, message):
    url = 'https://{0}/devices/{1}/messages/events?api-version=2018-04-01'.format(HOST_NAME, DEVICE_ID)
    headers = {
        "Content-Type": "application/json",
        "Authorization": token
    }
    data = json.dumps(message)
    requests.post(url, data=data, headers=headers)

if __name__ == '__main__':
    # 1. Generate SAS Token
    token = generate_sas_token()

    # 2. Simulate IoT Device
    while True:
        datapoint = psutil.cpu_percent()
        print(datapoint)
        message = {"cpu": datapoint}
        send_message(token, message)
        time.sleep(1)

Finally, navigate to the Analytics section via the side menu to confirm the data is indeed being received by Azure IoT Central and automatically visualized for further analysis.

azure_iot_central_analytics.png

And of course, you can add additional devices by going into Device Explorer and then copy the connection details to the scripts running on the other devices (e.g. other laptops). In the final example, I have the Python script running on my MacBook Pro, Surface Laptop and Raspberry Pi. Note the ability to split the measure (CPU Usage) by a property (Manufacturer).

azure_iot_central_multiple_devices.png