{"id":23729829,"url":"https://github.com/azure/iot_central_python_sample","last_synced_at":"2025-09-04T05:32:33.149Z","repository":{"id":66003895,"uuid":"274268384","full_name":"Azure/iot_central_python_sample","owner":"Azure","description":"Interacting with Azure IoT Central using a device written in Python","archived":false,"fork":false,"pushed_at":"2022-09-13T21:24:06.000Z","size":27,"stargazers_count":5,"open_issues_count":0,"forks_count":6,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-22T18:05:13.545Z","etag":null,"topics":["device","iot","iot-central"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-23T00:06:52.000Z","updated_at":"2023-08-23T06:18:42.000Z","dependencies_parsed_at":"2023-06-07T20:30:49.430Z","dependency_job_id":null,"html_url":"https://github.com/Azure/iot_central_python_sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fiot_central_python_sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fiot_central_python_sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fiot_central_python_sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fiot_central_python_sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure","download_url":"https://codeload.github.com/Azure/iot_central_python_sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231933611,"owners_count":18448126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["device","iot","iot-central"],"created_at":"2024-12-31T02:18:40.487Z","updated_at":"2024-12-31T02:18:41.860Z","avatar_url":"https://github.com/Azure.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iot_central_python_sample\nInteracting with Azure IoT Central using a device written in Python\n\nuses the Azure IoT Native Python Device SDK details found here: https://github.com/Azure/azure-iot-sdk-python/tree/master/azure-iot-device\n\nThe code requires the use of Python version 3.7+ for optimal use\n\nThe code uses six library for detecting Q+[enter] key press to perform clean shutdown\n \ninstall the libraries with: \n\n```\npip install azure-iot-device six\n```\n\nThe capability model for IoT Central is in the file device-capability-model.json and should be loaded into the IoT Central application\nViews will need to be created to see the telemetry, properties and commands\n\nIn the code add the necessary values for id_scope, device_symmetric_key or group_symmetric_key, device_id, model_identity \nand set use_websockets to true or false depending on if MQTT ports are blocked or not\n\nFeatures enabled in this sample:\n  * Supports DPS with cached DPS credentials (to file system) so a DPS call is not needed every connection\n  * Supports symmetric key and X509 certificate DPS and hub connection\n  * Supports using group symmetric key to generate a device symmetric key\n  * if connection fails with cached credentials falls back to re-call DPS\n  * Supports device side registration of the device in IoT Central with auto-association to a device model\n  * Illustrates sending telemetry to IoT Central\n  * Illustrates sending reported properties\n  * Illustrates receiving desired properties and acknowledging them correctly back to IoT Central\n  * Illustrates receiving direct methods and acknowledging them and returning a return value\n  * Illustrates receiving Cloud to device (C2D) messages\n  * Auto reconnects are handled by the Python device SDK\n\nThis sample application uses the device template model in the device-capability-model.json file.  This template should be imported into the IoT Central application, and appropriate views generated or created from the device template.\n\nTo use first open the iot_central_config.py file and enter in the necessary configuration information based on you IoT Central application.  If X509 device authentication is desired please see these articles on generating the necessary certificates for IoT Central https://docs.microsoft.com/en-us/azure/iot-central/core/concepts-get-connected#connect-devices-using-x509-certificates, https://github.com/Azure/azure-iot-sdk-c/tree/master/tools/CACertificates\n\n```python\n# IoT Central connection settings\nid_scope = \"\u003cID Scope found in IoT application - Administration -\u003e Device connection page\u003e\"\ndevice_id = \"\u003cDevice ID can be either an application unique name or a pre-created device in IoT Central\u003e\"\nmodel_identity = \"\u003cModel Identity found in Device templates -\u003e Edit Identity -\u003e Identity\u003e\"\n\n# device symmetric key support - default\ndevice_symmetric_key = \"\u003cDevice Primary Key found in the device details Connect popup window\u003e\"\n\n# group symmetric key support\nuse_group_symmetric_key = False  # set True to use group_symmetric_key and False to use device_symmetric_key\ngroup_symmetric_key = \"\u003cShared Access Signature token found in IoT application - Administration -\u003e Device connection page\u003e\"\n\n# X509 support\nuse_x509 = False  # set True to use X509 certificate authentication (use_group_symmetric_key must be set False)\nx509_public_cert_file = \"\u003clocation (relative to this file) of the public cert file in PEM format\u003e\"\nx509_private_cert_file = \"\u003clocation (relative to this file) of the private cert file in PEM format\u003e\"\nx509_pass_phrase = \"\u003cpass phrase for the private cert file\u003e\"\n\n# General config settings\nuse_websockets = True  # set True to use web sockets for MQTT connection to get through firewall proxies\nuse_cached_credentials = False # True to use cached credentials to connect to IoT Hub\n```\n\nAfter filling in the configuration information run the iot_central_sample.py file using:\n\n```\npython iot_central_sample.py\n```\n\nYou should see similar output to the following from the application (pressing the Q key and enter will exit the application):\n\n```\nRegistrationStage(RequestAndResponseOperation): Op will transition into polling after interval 2.  Setting timer.\nThe complete registration result is abc123\niotc-6f3e7a04-1498-46cb-8af8-299e1cc4315c.azure-devices.net\ninitialAssignment\nnull\nPress Q to quit\nsending message: {\"temp\": 89.000000, \"humidity\": 32.000000}\nSending reported property: {'text': {'value': '6UiewI1SxpSzxI5lQjjqDyhUU0Ekmzrb'}}\nSending reported property: {'boolean': {'value': True}}\nSending reported property: {'number': {'value': 64}}\ncompleted sending message\nsending message: {\"temp\": 78.000000, \"humidity\": 42.000000}\ncompleted sending message\nsending message: {\"temp\": 70.000000, \"humidity\": 12.000000}\ncompleted sending message\nsending message: {\"temp\": 74.000000, \"humidity\": 42.000000}\ncompleted sending message\nSending reported property: {'text': {'value': 'oGafYZ2c2601DRjONuD5G6y4FjCPuFGH'}}\nsending message: {\"temp\": 94.000000, \"humidity\": 32.000000}\ncompleted sending message\nq\nQuitting...\nDisconnecting from IoT Hub\n```\n\nNote: Currently the Cloud to Device (C2D) feature is in preview and behind a feature flag.  To use C2D please add the following to the url ?flights=c2d\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Fiot_central_python_sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure%2Fiot_central_python_sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Fiot_central_python_sample/lists"}