Skip to content

Build multiple containers (simulate devices) with X.509 DPS or Azure IoT Edge and connecting to Azure IoT Hub

License

Notifications You must be signed in to change notification settings

nnmer/azure-iot-device-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The purpose of this repository is to have an easy running sample of simulated devices packaged into docker containers.

2 cases:

  • with authorization via X.509 certificate and group enrollment into Azure IoT Hub
  • a device connected to IoTHub via IoT Edge

Note: this is only for a demo and tests purposes, not for production.

Example is based on some azure-iot-samples-node code.

Next files are taken from the Azure/azure-iot-sdk-c repository:

  • ./scripts/certGen.sh
  • ./scripts/openssl_device_intermediate_ca.cnf
  • ./scripts/openssl_root_ca.cnf

Preparation

You need to have installed on your system:

  • docker-ce
  • nodejs runtime

Notes

for Ubuntu users:

  • When you will run docker-compose up and it will fail with error "Version in ./docker-compose.yml is unsupported" the reason and solution may be here
  • you may need to execute commands with bash XXXXX.sh not sh XXXXX.sh, as in ubuntu sh is a dash interpretator

Leaf device -> IoT Hub register with DPS and X.509

Note If you are using not a global azure then change the file run-leaf-device-dps.sh at string

- PROVISIONING_HOST=global.azure-devices-provisioning.net

to correct global.azure-devices-provisioning.XXX

Step 1.

Create Azure IoT Hub and DPS services, link them together. Azure Docs for reference

Step 2.

In root folder of the repo run:

bash run-init.sh

This will generate X.509 root certificate and verification certificate. When you will be prompted to provide verification code do next:

  • go to Azure DPS > Certificates and add generated certificate, which is saved at ./scripts/build/certs/azure-iot-test-only.root.ca.cert.pem .
  • generate verification code for the certificate and provide it to the script
  • add a verification certificate to your certificate settings at Azure DPS. The verification certificate is saved at ./scripts/build/certs/verification-code.cert.pem

Step 3a.

Go to "Azure DPS > Manage enrollments" and create your group enrollment, select your certificate from the list

Step 3b.

Add a proper "IoTHub at Azure DPS > Linked IoT hubs"

Step 4.

run:

bash run-leaf-device-dps.sh {Number_Of_Desired_Devices} {ID_Scope_Of_Your_Azure_DPS_Service}
docker-composer up

at this point you should have desired number of containers (devices) running and sending telemetry to your Azure IoT Hub

Leaf device -> IoT Edge -> IoT Hub

Precondition:

  • have azure-cli installed
  • azure iot extension: az extension add --name azure-cli-iot-ext
  • have IoT Hub created
  • run az login if didn't run it yet

Step 1

In root folder of the repo run:

bash run-init.sh

This will generate X.509 root certificate and verification certificate. When you will be prompted to provide verification code write any info (verification certificate will not be used in this case)

Step 2

create CA cert for Edge device

sh run-edge-dev.sh <IoTHub-Name> <Number-Of-Leaf-Devices> <IoTEdge-Name>

Step 3

docker-compose up

Be patiant, it may take a while while edge device finish startup communication with IoT Hub

About

Build multiple containers (simulate devices) with X.509 DPS or Azure IoT Edge and connecting to Azure IoT Hub

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published