Python和Azure Iot Hub

时间:2016-02-18 11:10:44

标签: python azure mqtt azure-iot-hub

我在Raspberry Pi上运行Python代码。我需要使用普通的MQTT协议从我的Python代码连接到Azure Iot Hub。

我无法使用这些库连接到Iot Hub。我正在寻找一种在Python和普通MQTT中实现此目的的方法。

有谁知道如何做到这一点?

4 个答案:

答案 0 :(得分:2)

您可以参考我的帖子中的其他帖子Python MQTT connection to Azure Iot Hub

作为RaspberryPi粉丝,我建议您尝试使用Azure IoT SDK for C扩展Python,请参阅https://azure.microsoft.com/en-us/documentation/articles/iot-hub-device-sdk-c-intro/https://docs.python.org/2/extending/extending.html

另一个选择是使用Azure IoT SDK for NodeJS创建服务器作为侦听Python推送消息和转发到Azure IoTHub的代理,请参阅https://github.com/Azure/azure-iot-sdks/tree/master/node/device。根据您的Respberry Pi的版本,您需要从nodejs官方网站https://nodejs.org/en/download/或在Raspbian OS上使用sudo apt-get install nodejs下载适当的nodejs运行时,如下所示。

  1. Respberry Pi:ARMv6
  2. Respberry Pi 2:ARMv7
  3. 否则,在Respberry PI上从设备向Azure IoTHub发送消息的简单方法是使用Python中的Device Messaging REST APIs

    希望它有所帮助。最诚挚的问候。

答案 1 :(得分:0)

我不确定你的普通MQTT协议是什么意思。

MQTT的主要实现是Python是Paho的: https://eclipse.org/paho/clients/python/

你试过吗?

我没有使用Azure Iot Hub,但我认为可以获得MQTT主机名,端口,用户名和密码,然后用它们连接到它?

缺口。

答案 2 :(得分:0)

适用于Azure IoT Hub的Python SDK现在位于:https://github.com/azure/azure-iot-sdk-python并且本机支持MQTT

答案 3 :(得分:-1)

用于Azure IoT Hub的Python SDK已经发布,应该可以将Raspberry Pi连接到Azure IoT Hub。

见这里:

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