This repository provides code samples that demonstrate how to use pure MQTT in Python (using paho-mqtt) to send message to Azure IoT Edge Hub.
This is a simple Python application that sends a message to an MQTT endpoint every 10 seconds.
cd src/mqtt-simulator
pip install -r requirements.txt
chmod +x main.py
./main.py -c <certPath> -d <deviceId> -n <hubName> -g <gatewayHostname> -t <sasToken>
Where:
certPath
is the path to the Edge device root certificatedeviceId
is the id of the Azure IoT Edge devicehubName
is the name of the Azure IoT HubgatewayHostname
is the hostname of the Azure IoT Edge gatewaysasToken
is the shared access token that will be use to authenticate through Azure IoT Hub. It can be generated usingiothub-explorer sas-token DEVICE_ID
The deployment.json
file located in the src
folder contains a simple deployment definition that can be applied to an Azure IoT Edge device. It only deploy the edgeAgent
, the edgeHub
and a simple route that sends all messages from the Edge Hub to Azure IoT Hub ($upstream):
"routes": {
"route": "FROM /* INTO $upstream"
}
You can check the messages are received by the Azure IoT Edge Hub using the following command on the gateway:
docker logs -f edgeHub
You can monitor messages sent to Azure IoT Hub using the iothub-explorer tool or Visual Studio Code with the Azure IoT Extentions.