![](/img/trans.png)
[英]Cannot send message to Azure IoT Hub to units with ":" in their device id
[英]Not able to send Cloud to Device Message to Azure IoT hub
因此,我正在尝试使用 Python 将消息发送到 Azure IoT Hub。 我正在关注此文档,但是当我运行脚本时:
from azure.iot.hub import IoTHubRegistryManager
RECEIVED_MESSAGES = 0
CONNECTION_STRING = "<IoT Hub Connection String>"
DEVICE_ID = "<IoT Edge Device ID>"
def iothub_messaging_sample_run():
# Create IoTHubRegistryManager
registry_manager = IoTHubRegistryManager(CONNECTION_STRING)
i = 0
while True:
i += 1
print(f'Sending message: {i}')
data = f'NodeId : Node{i}, Message : Message{i}'
registry_manager.send_c2d_message(DEVICE_ID, data)
if __name__ == '__main__':
print('Starting the Python IoT Hub C2D Messaging service sample...')
iothub_messaging_sample_run()
它首先打印: Sending message: 1
然后抛出这个错误: Exception: C2D message send failure
错误日志的 rest 不包含任何其他信息,仅包含对 Azure IoT 中心 Package 文件的引用。
我已经在防火墙上启用了Inbound Port 8883
,但我仍然无法将数据发送到 Azure IoT Hub。
配置:
通过链接的教程工作,我注意到您的实现完全不同。 尽管如此,当我复制您的代码时,它确实可以在我的机器上运行,但我知道有两个原因可能导致此错误:
我还注意到你写道:
DEVICE_ID = "<IoT Edge Device ID>"
Azure IoT Edge 设备不支持 C2D 消息,但不会导致错误,但您将无法在设备上接收消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.