Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.48 KB

readme.md

File metadata and controls

59 lines (43 loc) · 1.48 KB

Using MQTT to connect an IoT Hub with Python

Prerequisites

  1. Follow the general prerequisites
  2. Install Python
  3. Install Pip

Variable substitution

The following variables will need to be expanded in the sample:

Variable Description Example
iothub_name The name of the created IoT Hub (NOT FQDN/HostName) iothub
device_id The name of the device created in the IoT Hub mosquitto_pub
sas_token The SAS token generated for the device SharedAccessSignature sr=*.azure-devices.net%2Fdevices%2F*&sig=*

Setup

  1. Open main.py and edit the following fields with the correct IoT Hub and device information

    • IOT_HUB_NAME
    • IOT_HUB_DEVICE_ID
    • IOT_HUB_SAS_TOKEN
  2. Install Paho MQTT

    pip install paho-mqtt
  3. Change into the python directory in the cloned repository:

    cd python
  4. Run the script

    python main.py
  5. Observe the telemetry being sent

    sending message[0]: Accio
    connect: 0
    publish: 1
    sending message[1]: Aguamenti
    publish: 2
    sending message[2]: Alarte Ascendare
    publish: 3
    sending message[3]: Expecto Patronum
    publish: 4
    sending message[4]: Homenum Revelio
    publish: 5