Skip to content

Latest commit

 

History

History
81 lines (57 loc) · 2.89 KB

python-run-sample.md

File metadata and controls

81 lines (57 loc) · 2.89 KB
platform device language
debian, Linux, raspbian, Ubuntu, windows
any
Python

Run a simple Python sample on device


Table of Contents

Introduction

About this document

This document describes how to run the iothub_client_sample.py Python sample application. This multi-step process includes:

  • Configuring Azure IoT Hub
  • Registering your IoT device
  • Build and deploy Azure IoT SDK on device

Step 1: Prerequisites

You should have the following items ready before beginning the process:

Step 2: Prepare your Device

Step 3: Run the sample

  • Navigate to the folder python/device/samples in your local copy of the repository.

  • Open the file iothub_client_sample.py in a text editor.

  • Locate the following code in the file:

    connectionString = "[device connection string]"	
    
  • Replace [device connection string] with the connection string for your device. Save the changes.

  • Run the sample application using the following command:

    python iothub_client_sample.py
    
  • The sample application will send messages to your IoT hub. The iothub-explorer utility will display the messages as your IoT hub receives them.

If you receive the error "ImportError: dynamic module does not define module export function (PyInit_iothub_client)" you may be running the samples with a different version of python than the iothub_client was build with. Following the Prepare your development environment to ensure the library is built with the desired python version

Experimenting with various transport protocols

There is a command line switch to test each of the AMQP, HTTP and MQTT protocols. It is also possible to simply change the transport in the sample.

```
python iothub_client_sample.py -p <mqtt|http|amqp>
```

Debugging the samples (and/or your code)

Visual Studio Code provides an excellent environment to write and debug Python code: