Transmit Sensor Data using Gateway Device

In this article

In this quickstart, you send telemetry from a physical Raspberry Pi device through Azure IoT Hub to a back-end application for processing. IoT Hub is an Azure service that enables you to ingest high volumes of telemetry from your IoT devices into the cloud for storage or processing. This quickstart uses a pre-written Python application to send the telemetry. Before you run this application, you create an IoT hub and register a device with the hub.

Prerequisites

Install Python Library for Azure IoT Device

Install azure.iot.device using the following command in the terminal. Click Terminal > New Terminal in VS Code and run the following command.

python3 -m pip install azure.iot.device

Use of python3 -m option with pip command ensures that the correct version of pip is used for package installation. In the above command pip version corresponding to the default python3 will be used.

Download and organise sample code

  • Download the sample Python project in Raspberry Pi.

  • Right click the downloaded archive (.zip) and select Extract here

  • Rename the extracted folder azure-iot-samples-python-master to azure-iot-samples-python and move it to the Documents folder in Raspberry Pi.

  • Open azure-iot-samples-python folder in VS Code and navigate to azure-iot-samples-python/iot-hub/Quickstarts/simulated-device/SimulatedDeviceSync.py.

  • Replace the value of variable, CONNECTION_STRING, with the primary connection string copied from IoT Hub Setup process in SimulatedDeviceSync.py.

  • Run

  • You will see the following output in the terminal.

You can monitor Monitor D2C (device-to-cloud) messages in VS code. A sample output is shown below.

Last updated