0% found this document useful (0 votes)
3 views

Iot Tutorial Azure Microsoft

The document describes how to set up an Azure functions app triggered by an IoT hub to process device events. It includes steps to log in, set subscriptions, create resources, register a device, and deploy and test the functions locally and in Azure.

Uploaded by

Joao Miranda
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Iot Tutorial Azure Microsoft

The document describes how to set up an Azure functions app triggered by an IoT hub to process device events. It includes steps to log in, set subscriptions, create resources, register a device, and deploy and test the functions locally and in Azure.

Uploaded by

Joao Miranda
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

AZURE LOGIN

az login
___________________________________________________________________________________
___

SHOW ACCOUNT LIST OUTPUT TABLE

az account list --output table


___________________________________________________________________________________
___

SET ACCOUNT SUBSCRIPTION

az account set --subscription <SubscriptionId>


___________________________________________________________________________________
___

SHOW LIST-LOCATIONS

az account list-locations --output table


___________________________________________________________________________________
___

CREATE RESOURCE GROUP

az group create --name <resource_group_name> \


--location uksouth
___________________________________________________________________________________
__

CREATE HUB

az iot hub create --resource-group gps-sensor \


--sku F1 \
--partition-count 2 \
--name <hub_name>

___________________________________________________________________________________
__

SHOW HUB DEVICE-IDENTITY

az iot hub device-identity create --device-id gps-sensor \


--hub-name <hub_name>

___________________________________________________________________________________
__

SHOW CONNECTION STRING

az iot hub device-identity connection-string show --device-id gps-sensor \


--output table \
--hub-name <hub_name>
___________________________________________________________________________________
__
INSTALL AZURITE

npm install -g azurite


___________________________________________________________________________________
__

RUN AZURITE PASSING IT THIS NEW FOLDER

azurite --location azurite


___________________________________________________________________________________
__

CREATE FUNCTIONS APP


mkdir <trigger_name>
cd <trigger_name>
func init --worker-runtime python <trigger_name>
___________________________________________________________________________________
__

CHANGE FILE local.settings.json

"AzureWebJobsStorage": "UseDevelopmentStorage=true",
___________________________________________________________________________________
__

PIP PACKAGES INSTALL USING REQUIREMENTS

pip install -r requirements.txt


___________________________________________________________________________________
__

FUNC START TEST (dentro da pasta do trigger)

func start
___________________________________________________________________________________
__

SHOW CONNECTION STRING IOT HUBS EVENT HUB

az iot hub connection-string show --default-eventhub \


--output table \
--hub-name <hub_name>
___________________________________________________________________________________
__

local.settings.json

"IOT_HUB_CONNECTION_STRING": "<connection string>",


___________________________________________________________________________________
__

FUNC START (dentro da pasta do trigger)

func new --name iot-hub-trigger --template "Azure Event Hub trigger"


___________________________________________________________________________________
__

DENTRO DA PASTA <SENSOR_TRIGGER_NAME> FOI CRIADA UMA PASTA IOT-HUB-TRIGGER


NO FICHEIRO function.json

"cardinality": "one",
"connection": "IOT_HUB_CONNECTION_STRING",
"eventHubName": "",
___________________________________________________________________________________
__

FUNC START DENOVO

func start

SE APARECER : [2021-05-05T02:44:09.395Z] Executed 'Functions.iot-hub-trigger'


(Succeeded, Id=802803a5-eae9-4401-a1f4-176631456ce4, Duration=245ms)
QUER DIZER QUE ESTA A FUNCIONAR
___________________________________________________________________________________
__

SHOW REGISTRY MANAGER CONNECTION STRING

az iot hub connection-string show --policy-name service \


--output table \
--hub-name <hub_name>
___________________________________________________________________________________
__

ACRESCENTAR EM LOCAL.SETTINGS.JSON COM A CONNECTION STRING DO REGISTRY MANAGER

"REGISTRY_MANAGER_CONNECTION_STRING": "<connection string>"


___________________________________________________________________________________
__
ACRESCENTAR EM requirements.txt

azure-iot-hub
___________________________________________________________________________________
__

CREATE STORAGE

az storage account create --resource-group gps-sensor \


--sku Standard_LRS \
--name <storage_name>
___________________________________________________________________________________
__

SHOW CONNECTION STRING STORAGE

az storage account show-connection-string --output table \


--name <storage_name>
___________________________________________________________________________________
__

CREATE FUNCTION APP

az functionapp create --resource-group soil-moisture-sensor \


--runtime python \
--functions-version 3 \
--os-type Linux \
--consumption-plan-location <location> \
--storage-account <storage_name> \
--name <functions_app_name>
___________________________________________________________________________________
__

UPLOAD APPLICATION SETTINGS

az functionapp config appsettings set --resource-group gps-sensor \


--name gpssensorjrp \
--settings
"IOT_HUB_CONNECTION_STRING=Endpoint=sb://ihsuprodlnres008dednamespace.servicebus.wi
ndows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=vI/
JTMvG7BUsKfQhtYDu43uxxCK76V3F0W8SdHrwdZw=;EntityPath=iothub-ehub-gps-sensor-
23939462-96893c83dd"
___________________________________________________________________________________
__

DEPLOY YOUR FUNCTIONS APP TO THE CLOUD

func azure functionapp publish <functions_app_name>

___________________________________________________________________________________
__

You might also like