Giter Club home page Giter Club logo

azure-iot-hub-demo's Introduction

Azure IoT Hub Demo

Azure IoT features demo.

Tools

You'll need to following software to run this demo:

  • Azure CLI
  • Azure CLI IoT Extension (az extension add --name azure-cli-iot-ext)

Provisioning the Infrastructure

# Login and setup your location variable
az login -u <username>
az configure --defaults location=eastus

# Group creation
$group="iotdemo"
az group create -n $group

# Create IoT Hub with free SKU (It cannot to be upgraded to Basic or Standard)
az iot hub create -n "iotdemohub999" -g $group --sku F1

# Create the Device Provisioning Service (DPS)
az iot dps create -n iotdemodps999 -g $group

#Link the hub to the provisioning service
$hubConnectionString=az iot hub show-connection-string -n iotdemohub999 -o tsv
az iot dps linked-hub create -g $group --dps-name iotdemodps999 --connection-string $hubConnectionString

# Create a device:
az iot hub device-identity create --device-id test-device-01 --hub-name iotdemohub999

Sending Messages

Send messages between Cloud and Device for testing.

# D2C
az iot hub monitor-events -n iotdemohub999
az iot device send-d2c-message -n iotdemohub999 -d test-device-01 --data 'Hello from Azure CLI'

# C2D
az iot device c2d-message send -n iotdemohub999 -d test-device-01 --data 'Hello, device, from Azure CLI'
az iot device c2d-message receive -n iotdemohub999 -d test-device-01

# simulate device
az iot hub monitor-events -n iotdemohub999

az iot device simulate -n iotdemohub999 -d test-device-01 `
--data "Message from simulated device!" `
--msg-count 5

Manual Enrollment

These steps are taken from this Microsoft article.

  1. git clone https://github.com/Azure-Samples/azure-iot-samples-csharp.git
  2. cd .\azure-iot-samples-csharp\provisioning\Samples\device\X509Sample
  3. Create the certificates: powershell .\GenerateTestCertificate.ps1
  4. Configure individual enrollment:
az iot dps enrollment create -g iotdemo --dps-name $iotdemodps999 `
--enrollment-id iothubx509device1 --attestation-type x509 --certificate-path certificate.cer
  1. Get the DPS ID Scope: az iot dps show -n iotdemodps999 --query "properties.idScope" -o tsv
  2. Send a message: dotnet run <idScope>

OpenSSL Certificate

You may choose to generate the certificate with OpenSSL.

openssl genrsa -out private.key 2048
openssl req -new -x509 -key private.key -out publickey.cer -days 90

You may optionally add -subj '/CN=<full domain name>/emailAddress=<email>/C=<country code>/ST=<state name>/L=<city>/O=<organization>/OU=<department>' but it might require an upgrade of OpenSSL to the latest version due to -subj not working properly on all scenarios. Another alternative is to use openssl.conf file with -config parameter.

Stream Analytics

This is where the data received from the devices are selected to be processed in a service of your choice, such as functions, queues and events.

  1. Create a Stream Analytics Job using the Portal
  2. Add IoT Hub as an input to the job
  3. Checkout the generator sample: git clone https://github.com/MattHoneycutt/ps-create-iot-solutions.git
  4. Create a device: az iot hub device-identity create --device-id generator-01 --hub-name iotdemohub999
  5. Get the device connection string:
az iot hub device-identity show-connection-string `
--hub-name iotdemohub999 `
--device-id generator-01 `
-o tsv
  1. Run the generator-sample program: dotnet run "<connection_string>"
  2. Open the Query in the Stream Analytics, go to Input and select the IoT Hub sample data from input
  3. Insert this query and click Save:
SELECT
	DeviceId=datapoints.iothub.connectionDeviceId,
	SensorName,
	WindowEndTime=(System.Timestamp),
	AVG(Value),
	MIN(Value),
	MAX(Value)
INTO
	[YourOuputAlias] --later change it to blobstorage
FROM
	datapoints
	TIMESTAMP BY
		datapoints.iothub.enqueuedTime
GROUP BY
	datapoints.iothub.connectionDeviceId,
	SensorName,
	TumblingWindow(second, 15)
  1. Create a storage account: az storage account create -n iotdemosa999 -g iotdemo -l eastus
  2. Add an Output of type Blob Storage for the Stream Analytics.
  3. Change the INTO parameter in the query to blobstorage
  4. Start the job.

Configure IoT Hub Message Routing

Do it when you want to have more than one processing strategy for the data, such as raw archive.

  1. Add a Custom Endpoint named rawdata to the "Messge routing" option in the IoT Hub of type Blob Storage
  2. Add a Route to the IoT Hub referencing the custom endpoint

Security

Security concerns for IoT provisioning:

https://docs.microsoft.com/en-us/azure/iot-dps/concepts-security#hardware-security-module

References

Pluralsight Creating IoT Solutions

Managing DPS with CLI

Simulated device with CE

X.509 Enrollment

Send Telemetry

IoT client provisioning sample

IoT C# Samples

azure-iot-hub-demo's People

Contributors

epomatti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.