For this year’s Global Azure Bootcamp event I decided to take one of the Microsoft tutorials available on the Microsoft Docs site and bring it to life. For a while I’ve been interested in the advancements of IoT – although certainly not a new thing IoT has started to explode in use with more and more useful, time-saving and money saving ides being brought to life.
The tutorial I used was the ‘Predict the Weather using RaspberryPi’ which makes use of a good number of Azure services – IoT hub, Stream Analytics, Azure Blob Storage and Azure Machine Learning. Finally although not exactly an Azure service I used PowerBI to display the temperature and humidity live in a line graph. The tutorials can be found here –
Although obviously being the Azure Global Bootcamp my aim was to demonstrate as many Azure services as possible there were two other things I wanted to get out of the session first I wanted to introduce the various different ways you can interstate with Azure PowerShell, CLI, JSON templates and the Azure portal are the methods I used in the demo. And secondly, I wanted to show that you truly can use the toolsets you’re most comfortable with. As you’ll know if you read this blog I’m a HUGE Apple fanboy (to most people’s disgust) but I wanted in the presentation to show that even though you’re using Microsoft services I can happily use MacOS, CLI (Open Source) and Visual Studio Code (again, the source code is Open Source) without any restrictions or constraints on what I can do – this would be completely unimaginable from a Microsoft of 5+ years ago.
Finally, I wanted to introduce the Azure CloudShell – an often forgotten but invaluable tool.
The code I used for the presentation can be found here (the JSON templets are attached). Hopefully, you find them useful.
#Connect to Azure
#Select the right Subscription
az account set --subscription "Azure Pass - Sponsorship"
#Create your Resource Group
az group create --name "Demo01" --location "North Europe"
#Create the IoT Hub
az iot hub create --name "Joes-Test-IoT-Hub-2" --resource-group "Demo01" --sku F1
#Show the new IoT Hub
az iot hub list
#Get the Primary Key
az iot hub policy show --hub-name Joes-Test-IoT-Hub-2 --name iothubowner
#Get the connection string
az iot hub show-connection-string --name Joes-Test-IoT-Hub-2
#To work with the hub we will need to install the IoT CLI extension.
az extension add --name azure-cli-iot-ext
#Register a new device
az iot hub device-identity create --device-id "JoesDevice" --hub-name "Joes-Test-IoT-Hub-2"
#We need to create a 'consumer group' for application to connect to
az iot hub consumer-group create --hub-name "Joes-Test-IoT-Hub-2" --name "TestConsumerGroup"
# We need to create the AI model. You can get to the AI gallery here. https://gallery.cortanaintelligence.com/Experiment/Weather-prediction-model-1
# Create Analytics Streaming Job
$resourceGroup = "Demo01"
$jobname = "Joes-Test-IoT-Hub"
# Create the job
$jobDefinitionFile = "./jobdefinition.json"
New-AzStreamAnalyticsJob -ResourceGroupName $resourceGroup -Name $jobname -File $jobDefinitionFile
$jobInputName = "IoTHubInput"
$jobInputDefinitionFile = "./JobInputDefinition.json"
New-AzStreamAnalyticsInput -ResourceGroupName $resourceGroup -JobName $jobName -File $jobInputDefinitionFile -Name $jobInputName
$jobOutputName = "BlobOutput"
$jobOutputDefinitionFile = "./JobOutputDefinition.json"
New-AzStreamAnalyticsOutput -ResourceGroupName $resourceGroup -JobName $jobName -File $jobOutputDefinitionFile -Name $jobOutputName -Force
$jobOutputName = "MyJobFunction"
$jobFunctionDefinitionFile = "./JobFunctionDefinition.json"
New-AzStreamAnalyticsFunction -ResourceGroupName $resourceGroup -JobName $jobName -File $jobFunctionDefinitionFile
$jobTransformationName = "MyJobTransformation"
$jobTransformationDefinitionFile = "./JobTransformationDefinition.json"
New-AzStreamAnalyticsTransformation -ResourceGroupName $resourceGroup -JobName $jobName -File $jobTransformationDefinitionFile -Name $jobTransformationName -Force