Azure IoT features demo.
You'll need to following software to run this demo:
- Azure CLI
- Azure CLI IoT Extension (
az extension add --name azure-cli-iot-ext
)
# 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
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
These steps are taken from this Microsoft article.
git clone https://github.com/Azure-Samples/azure-iot-samples-csharp.git
cd .\azure-iot-samples-csharp\provisioning\Samples\device\X509Sample
- Create the certificates:
powershell .\GenerateTestCertificate.ps1
- Configure individual enrollment:
az iot dps enrollment create -g iotdemo --dps-name $iotdemodps999 `
--enrollment-id iothubx509device1 --attestation-type x509 --certificate-path certificate.cer
- Get the DPS ID Scope:
az iot dps show -n iotdemodps999 --query "properties.idScope" -o tsv
- Send a message:
dotnet run <idScope>
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.
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.
- Create a Stream Analytics Job using the Portal
- Add IoT Hub as an input to the job
- Checkout the generator sample:
git clone https://github.com/MattHoneycutt/ps-create-iot-solutions.git
- Create a device:
az iot hub device-identity create --device-id generator-01 --hub-name iotdemohub999
- Get the device connection string:
az iot hub device-identity show-connection-string `
--hub-name iotdemohub999 `
--device-id generator-01 `
-o tsv
- Run the generator-sample program:
dotnet run "<connection_string>"
- Open the Query in the Stream Analytics, go to Input and select the IoT Hub
sample data from input
- 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)
- Create a storage account:
az storage account create -n iotdemosa999 -g iotdemo -l eastus
- Add an Output of type Blob Storage for the Stream Analytics.
- Change the INTO parameter in the query to
blobstorage
- Start the job.
Do it when you want to have more than one processing strategy for the data, such as raw archive.
- Add a Custom Endpoint named
rawdata
to the "Messge routing" option in the IoT Hub of type Blob Storage - Add a Route to the IoT Hub referencing the custom endpoint
Security concerns for IoT provisioning:
https://docs.microsoft.com/en-us/azure/iot-dps/concepts-security#hardware-security-module
Pluralsight Creating IoT Solutions