Skip to content

Azure IoT Hub Device example, written in Python. It supports both D2C and C2D communication

License

Notifications You must be signed in to change notification settings

sandervandevelde/Azure-IoT-Hub-Device-Python-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure-IoT-Hub-Device-Python-Example

Both Azure IoT Hub Device example and Azure IoT Device Provisioning Service enrollment example, written in Python. It supports both D2C and C2D communication.

Blog post

Check out the blog post behind this sample code for more background information.

Two examples

Both examples are exposing the same logic.

IoT Hub - Device connection string

This code expects an Environment variable named 'IOTHUB_DEVICE_CONNECTION_STRING' to be present. Otherwise the app will fail to authenticate. See the blog post for instructions.

DPS - individual enrollment, symmetric key

This code expects Environment variables named "PROVISIONING_HOST", "PROVISIONING_IDSCOPE", "PROVISIONING_REGISTRATION_ID", and "PROVISIONING_SYMMETRIC_KEY".

Usage

Device Twin call

On startup, the device will ask for any Device twin information. It will receive both the desired and reported properties.

Direct Method event handler

You can send an interval (in seconds) to 'SetTelemetryInterval'. No JSON format neede, junst ths integer.

Cloud message event handler

Just send some string to the device. It will show the received text in the console output.

Device Twin desired properties change event handler

Send a Device twin desired property change. It will be shown in the console output.

The device will respond with a reported property update.

Resources

This code is based on thiese resources:

Check out the details there for more indept information.

Missing packages

if packages are missing, like Azure, try:

pip install azure.iot.device

Check the 'from' lines in the code for package names.

About

Azure IoT Hub Device example, written in Python. It supports both D2C and C2D communication

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages