简体   繁体   English

Python和Azure Iot Hub

[英]Python and Azure Iot Hub

I have Python code running on a Raspberry Pi. 我在Raspberry Pi上运行了Python代码。 I need to connect to Azure Iot Hub from my Python code by using plain MQTT protocol. 我需要使用简单的MQTT协议从我的Python代码连接到Azure Iot Hub。

I cannot use the libraries for connecting to Iot Hub. 我无法使用这些库来连接到Iot Hub。 I am looking for a way to do this in Python and plain MQTT. 我正在寻找在Python和纯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 . 您可以参考我的文章,了解与Azure Iot Hub的其他线程Python MQTT连接

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 . 作为RaspberryPi爱好者,我建议您可以尝试使用适用于C的Azure IoT SDK扩展Python,请参阅https://azure.microsoft.com/zh-cn/documentation/articles/iot-hub-device-sdk-c -intro /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 . 另一个选择是使用用于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/ or via using sudo apt-get install nodejs on the Raspbian OS. 并且根据您的Respberry Pi的版本,您需要从以下nodejs官方网站https://nodejs.org/en/download/下载合适的nodejs运行时,或者在Raspbian OS上使用sudo apt-get install nodejs下载。

  1. Respberry Pi: ARMv6 Respberry Pi: ARMv6
  2. Respberry Pi 2: ARMv7 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. 否则,将消息从设备发送到Respberry PI上的Azure IoTHub的简单方法是在Python中使用设备消息传递REST API

Hope it helps. 希望能帮助到你。 Best Regards. 最好的祝福。

I am not sure what you mean by plain MQTT protocol. 我不确定您所说的纯MQTT协议是什么意思。

The main implementation of MQTT is Python is the Paho one: https://eclipse.org/paho/clients/python/ MQTT的主要实现是Python,是Paho之一: 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? 我没有使用过Azure Iot Hub,但我想可以获取MQTT主机名,端口,用户名和密码,然后将其用于连接该主机名吗?

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. 适用于Azure IoT中心的Python SDK已发布,应该可以将Raspberry Pi连接到Azure IoT中心。

See here: 看这里:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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