pyazureutils package

IoT central enrollment module

Functions and classes for device registration with Azure IoT Central

class pyazureutils.iotcentral.AzureIotCentral(session, app_name)

Bases: object

Wrapper for interaction with Azure IoT Central

create_device(device_id, template, display_name=None)

Create device via REST API call

Parameters:
  • device_id (str) – IoT central device ID

  • template (str) – template to use for creation

  • display_name (optional, str) – friendly name to use

create_device_attestation(device_id, certificate)

Create device attestation via REST API call

Parameters:
  • device_id (str) – IoT central device ID

  • certificate (str) – certificate for enrollment

get_default_subscription()

Retrieves the default subscription using AZ CLI (az account show)

get_device(device_id)

Retrieve device info via REST API call

Parameters:

device_id (str) – IoT central device ID

get_device_attestation(device_id)

Retrieve device attestation via REST API call

Parameters:

device_id (str) – IoT central device ID

get_device_template(template_id)

Get a device template by ID via REST API call.

Parameters:

template_id (str) – Template ID as defined by the DTDL e.g. dtmi:com:Microchip:PIC_IoT_WM;1 for the PIC-IoT Wx. More info here

Returns:

result of the REST request

Return type:

str

get_device_templates()

Retrieve device templates via REST API call

get_subscriptions()

Retrieve subscriptions via REST API call

list_applications()

List applications using AZ CLI

set_app_name(app_name)

Set the app name

set_default_subscription(name_or_id)

Sets the default subscription using AZ CLI (az account set –subscription <name>)

Parameters:

name_or_id (str) – subscription name or ID to set as default (no spaces allowed)

class pyazureutils.iotcentral.AzureIotCentralSession(subscription=None)

Bases: object

Session handling for Azure IoT Central

az_cli_command(command)

Execute an Azure CLI command

az_rest_get(url)

Make a rest-api GET call to Azure IoTCentral

az_rest_put(url, json_content=None)

Make a rest-api PUT call to Azure IoTCentral

connect()

Connect to Azure services by creating access tokens.

Raises:

Exception – If no access tokens could be created.

pyazureutils.iotcentral.iotcentral_register_device(app_name=None, certificate_file=None, display_name=None, subscription=None, device_template=None)

Register an IoT device in Azure’s IoTCentral

Registration requires that the user logs into Azure using the Azure CLI “az” Tokens will be collected from the user’s Azure local token storage

Registration uses an application name which is either:

  • collected from IoTCentral account (first one found is used)

  • passed in as an argument

Registration uses a certificate which is either:

  • collected from local certificate storage for a kit, if a kit has been provisioned using this machine

  • passed in as a filename argument

Registration uses a device name which is derived from the subject common name of the certificate used

Registration uses a display name which is either:

  • derived from the kit serial number (if a kit is connected)

  • passed in as an argument

Parameters:
  • app_name – Application Name to register device with

  • certificate_file – Device certificate PEM file

  • display_name – Display name to register device with

  • device_template – Device template to use for registration

pyazureutils

Python Utilities for Microsoft Azure

pyazureutils is a collection of utilities for interacting with Microsoft Azure.

pyazureutils can be used as a library by instantiating any of the contained classes.

Overview

pyazureutils is available:

Logging

This package uses the Python logging module for publishing log messages to library users. A basic configuration can be used (see example), but for best results a more thorough configuration is recommended in order to control the verbosity of output from dependencies in the stack which also use logging.