Skip to content

Instantly share code, notes, and snippets.

@tomconte
Created May 12, 2016 09:32
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomconte/eef8c9bfb4434787672c303153eee500 to your computer and use it in GitHub Desktop.
Save tomconte/eef8c9bfb4434787672c303153eee500 to your computer and use it in GitHub Desktop.
This is a simple example showing how to use the [Paho MQTT Python client](https://eclipse.org/paho/clients/python/) to send data to Azure IoT Hub. You need to assemble the rights credentials and configure TLS and the MQTT protocol version appropriately.
#!/usr/bin/python
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt
import ssl
auth = {
'username':"ciscohackhub.azure-devices.net/lora1",
'password':"SharedAccessSignature sr=ciscohackhub.azure-devices.net%2Fdevices%2Flora1&sig=xxxx&se=1463048772"
}
tls = {
'ca_certs':"/etc/ssl/certs/ca-certificates.crt",
'tls_version':ssl.PROTOCOL_TLSv1
}
publish.single("devices/lora1/messages/events/",
payload="hello world",
hostname="ciscohackhub.azure-devices.net",
client_id="lora1",
auth=auth,
tls=tls,
port=8883,
protocol=mqtt.MQTTv311)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment