Python 和 Azure 物联网中心

Python and Azure Iot Hub

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

我无法使用库连接到 Iot Hub。我正在寻找一种在 Python 和普通 MQTT 中执行此操作的方法。

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

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

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

你试过了吗?

我没有使用过 Azure Iot Hub,但我假设可以获得 MQTT 主机名、端口、用户名和密码,然后用于连接它?

尼克。

另一个帖子Python MQTT connection to Azure Iot Hub可以参考我的post。

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

另一种选择是使用适用于 NodeJS 的 Azure IoT SDK 创建一个服务器作为监听 Python 推送消息并转发到 Azure IoTHub 的代理,请参阅 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/ 或使用 sudo apt-get install nodejs 在 Raspbian OS.

  1. 树莓派:ARMv6
  2. 树莓派 2:ARMv7

否则,将消息从设备发送到 Respberry PI 上的 Azure IoTHub 的简单方法是使用 Python 中的 Device Messaging REST APIs

希望对您有所帮助。最好的问候。

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

看这里:

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

Azure IoT 中心的 Python SDK 现已推出:https://github.com/azure/azure-iot-sdk-python 并原生支持 MQTT