Azure Services

Links to docs.microsoft.com

IOT Device Setup
IoT Hub Developer Guide

Connecting RaspberryPi to Azure IoT Hub

Send telemetry data (MQTT messages) from RaspberryPi using Python

Create an IoT hub and register a device with the hub.

In a Cloud Shell (CLI) instance add the Azure IoT Extension, to add IoT Hub, IoT Edge, and IoT Device Provisioning Service (DPS) commands to Azure CLI.

  az extension add --name azure-cli-iot-ext 

On Azure services find and click on IoT Hub

On the IoT Hub click the + Add to create a new IoT Resource

Select Subscription
Create New Resource Group and call it RaspberryPiAzureIoT
Select Region
Enter IoT Hub Name RaspberryPiSenseHat

Click Next: Size and scale
Pricing and scale tier : F1: Free Tier *(only one free resource per Hub)
Number of S1 IoT Hub units: 1 (can be increased later)
under Advanced Settings
Device-to-cloud partitions : 2

Click the Create button to create the IoT Hub resource

Wait until deployment completes

Create IoT Device on Azure

———————————–

Register the RaspberryPi to the Azure IoT Hub using the Azure cloud shell CLI. Use RaspberryPiSenseHat as {YourIoTHubName} and SenseHat as {MyPythonDevice}

az iot hub device-identity create --hub-name RaspberryPiSenseHat --device-id SenseHat

Send Sense Hat Data to Azure

For this example a RaspberryPi 3 B+ was used running Rasbian Buster Lite, with Python 3.7.3, Thonny 3.2.0 and Sense Hat installed.

Install Azure-IoT on RaspberryPi

Open a terminal window and install azure iot Python module

 pip3 install azure-iot-device

Download and extract the ZIP archive of the sample Python project from:
 https://github.com/Azure-Samples/azure-iot-samples-python/archive/master.zip .
In this example files were extracted to directory:
/home/pi/Public/Azure/azure-iot-samples-python-master

Use the Azure CLI to get the device connection string.

az iot hub device-identity show-connection-string --hub-name  RaspberryPiSenseHat  --device-id  SenseHat --output table

Navigate to the iot-hub\Quickstarts\simulated-device folder and open the SimulatedDevice.py and replace CONNECTION_STRING value to the value from CLI

Processing data from IoT Hub with Azure Functions