简体   繁体   中英

Python and Azure Iot Hub

I have Python code running on a Raspberry Pi. I need to connect to Azure Iot Hub from my Python code by using plain MQTT protocol.

I cannot use the libraries for connecting to Iot Hub. I am looking for a way to do this in Python and plain MQTT.

Does anyone know how this can be done?

You can refer to my post for the other thread Python MQTT connection to Azure Iot Hub .

As a RaspberryPi fan, I suggest that you can try to extend Python with Azure IoT SDK for C, please see https://azure.microsoft.com/en-us/documentation/articles/iot-hub-device-sdk-c-intro/ and https://docs.python.org/2/extending/extending.html .

The other choice is that using the Azure IoT SDK for NodeJS to create a server as proxy for listening Python push messages and forwarding to Azure IoTHub, please see https://github.com/Azure/azure-iot-sdks/tree/master/node/device . And according to the version of your Respberry Pi, you need to download the suitable nodejs runtime as below from the nodejs offical website https://nodejs.org/en/download/ or via using sudo apt-get install nodejs on the Raspbian OS.

  1. Respberry Pi: ARMv6
  2. Respberry Pi 2: ARMv7

Otherwise, the simple way for sending messages from device to Azure IoTHub on Respberry PI is that using the Device Messaging REST APIs in Python.

Hope it helps. Best Regards.

I am not sure what you mean by plain MQTT protocol.

The main implementation of MQTT is Python is the Paho one: https://eclipse.org/paho/clients/python/

Have you tried that?

I have not used the Azure Iot Hub, but I would presume that it is possible to get a MQTT hostname, port, username and password, which would then be used to connect to it?

nick.

适用于Azure IoT中心的Python SDK现在位于此处: https//github.com/azure/azure-iot-sdk-python并原生支持MQTT

The Python SDK for Azure IoT Hub has been released and should work to connect a Raspberry Pi to Azure IoT Hub.

See here:

https://github.com/Azure/azure-iot-sdks/tree/master/python/device

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM