Samples for the Azure IoT device SDK for Python
This folder contains simple samples showing how to use the various features of the Microsoft Azure IoT Hub service from a device running Python.
List of samples
- Simple Sample: an extremely simple example showing how to send a message
- Full Sample: shows how to connect to IoT Hub and send and receive messages using the AMQP, MQTT or HTTP protocol.
- Class Sample using AMQP: shows how to connect to IoT Hub with a HubManager class to send and receive messages using the AMQP protocol.
- X-509 Sample: shows how to authenticate a device using X-509 certs and send and receive messages.
- HSM Sample: shows how to connect to IoT Hub and send messages with a provisioned device.
And if you are looking for end to end samples that show how to do simple analytics and processing of the data generated by your device using Azure services such as Stream Analytics, Big Data, Machine Learning and others, check out our E2E samples gallery.
How to run the samples
In order to run the device samples you will first need the following prerequisites:
Note: On Windows, it is recommended to install the iothub-client module package using pip (see link above).
- Create an Azure IoT Hub instance
- Create a device identity for your device and retrieve the primary connection string for this device
Once you have a device identity for your sample,
- Get the sample files:
- if you have cloned the repository, Navigate to the folder device/samples
- if you are using the iothub_client module installed with pip, download the samples folder content to your target.
- Run the sample application using the following command to run the simple sample (replacing
<device connection string>with the one generated previously):
python iothub_client_sample.py -c < device connection string > -p < mqtt|http|amqp >
You can get details on the options for the sample command line typing:
python iothub_client_sample.py -h
python iothub_client_prov_hsm_sample_.py -h
- To run the other samples (x-509 and class), replace the name of the .py file in the command line and use the
-hoption to get the details on the available options