зеркало из
1
0
Форкнуть 0
azure-iot-sdk-python/samples/sync-samples
ks6088ts def32f339c
fix: sample disconnect when all the messages are sent (#1176)
Co-authored-by: Carter Tinney <carter.tinney@microsoft.com>
2024-07-17 10:40:49 -07:00
..
README.md chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
get_twin.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
provision_symmetric_key.py fix: sample disconnect when all the messages are sent (#1176) 2024-07-17 10:40:49 -07:00
provision_symmetric_key_group.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
provision_symmetric_key_with_payload.py chore: Remove remaining references (#1041) 2022-08-23 19:19:07 -04:00
provision_x509.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
receive_direct_method.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
receive_message.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
receive_message_on_input.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
receive_message_x509.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
receive_twin_desired_properties_patch.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
recurring_telemetry.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
send_message.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
send_message_to_output.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
send_message_via_module_x509.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
send_message_via_proxy.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
send_message_x509.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
update_twin_reported_properties.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00
use_custom_sastoken.py chore: Restructure repository for single project (#1030) 2022-08-04 12:58:57 -07:00

README.md

Synchronous API Scenario Samples for the Azure IoT Hub Device SDK

This directory contains samples showing how to use the various features of Azure IoT Hub Device SDK with the Azure IoT Hub and Azure IoT Edge.

IoTHub Device Samples

In order to use these samples, you must set your Device Connection String in the environment variable IOTHUB_DEVICE_CONNECTION_STRING.

  • send_message.py - Send multiple telemetry messages in parallel from a device to the Azure IoT Hub.

    • You can monitor the Azure IoT Hub for messages received by using the following Azure CLI command:

      bash az iot hub monitor-events --hub-name <your IoT Hub name> --output table```
      
      
  • recurring_telemetry.py - Send telemetry message every two seconds from a device to the Azure IoT Hub.

    • You can monitor the Azure IoT Hub for messages received by using the following Azure CLI command:

      bash az iot hub monitor-events --hub-name <your IoT Hub name> --output table```
      
      
  • receive_message.py - Receive Cloud-to-Device (C2D) messages sent from the Azure IoT Hub to a device.

    • In order to send a C2D message, use the following Azure CLI command:
    az iot device c2d-message send --device-id <your device id> --hub-name <your IoT Hub name> --data <your message here>
    
  • receive_direct_method.py - Receive direct method requests on a device from the Azure IoT Hub and send responses back

    • In order to invoke a direct method, use the following Azure CLI command:

      az iot hub invoke-device-method --device-id <your device id> --hub-name <your IoT Hub name> --method-name <desired method>
      
  • receive_twin_desired_properties_patch - Receive an update patch of changes made to the device twin's desired properties

    • In order to send a update patch to a device twin's desired properties, use the following Azure CLI command:

      az iot hub device-twin update --device-id <your device id> --hub-name <your IoT Hub name> --set properties.desired.<property name>=<value>
      
  • update_twin_reported_properties - Send an update patch of changes to the device twin's reported properties

    • You can see the changes reflected in your device twin by using the following Azure CLI command:

      az iot hub device-twin show --device-id <your device id> --hub-name <your IoT Hub name>
      

IoT Edge Module Samples

In order to use these samples, they must be run from inside an Edge container.

DPS Samples

Individual

In order to use these samples, you must have the following environment variables :-

  • PROVISIONING_HOST
  • PROVISIONING_IDSCOPE
  • PROVISIONING_REGISTRATION_ID

There are 2 ways that your device can get registered to the provisioning service differing in authentication mechanisms. Depending on the mechanism used additional environment variables are needed for the samples:-

  • provision_symmetric_key.py - Provision a device to IoTHub by registering to the Device Provisioning Service using a symmetric key, then send telemetry messages to IoTHub. For this you must have the environment variable PROVISIONING_SYMMETRIC_KEY.
  • provision_symmetric_key_with_payload.py - Provision a device to IoTHub by registering to the Device Provisioning Service using a symmetric key while supplying a custom payload, then send telemetry messages to IoTHub. For this you must have the environment variable PROVISIONING_SYMMETRIC_KEY.
  • provision_x509.py - Provision a device to IoTHub by registering to the Device Provisioning Service using a symmetric key, then send a telemetry message to IoTHub. For this you must have the environment variable X509_CERT_FILE, X509_KEY_FILE, PASS_PHRASE.

Group Enrollment

In order to use these samples, you must have the following environment variables :-

  • PROVISIONING_HOST

  • PROVISIONING_IDSCOPE

  • provision_symmetric_key_group.py - Provision multiple devices to IoTHub by registering them to the Device Provisioning Service using derived symmetric keys, then send telemetry to IoTHub from these devices. For this you must have knowledge of the group symmetric key and must have the environment variables PROVISIONING_DEVICE_ID_1, PROVISIONING_DEVICE_ID_2, PROVISIONING_DEVICE_ID_3.

    • NOTE : Group symmetric key must NEVER be stored and all the device keys must be computationally derived prior to using this sample.