我有在 Raspberry Pi 上运行的 Python 代码。我需要使用普通 MQTT 协议(protocol)从我的 Python 代码连接到 Azure Iot Hub。
我无法使用库来连接到 IoT Hub。我正在寻找一种在 Python 和普通 MQTT 中执行此操作的方法。
有人知道如何做到这一点吗?
最佳答案
你可以引用我的另一个帖子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/下载合适的nodejs运行时,如下所示或通过在 Raspbian 操作系统上使用 sudo apt-get install nodejs
。
否则,将消息从设备发送到 Respberry PI 上的 Azure IoTHub 的简单方法是使用 Device Messaging REST APIs在Python中。
希望有帮助。谨致问候。
关于Python 和 Azure 物联网中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479783/