如何使用Python在事件中心接收设备消息?我看到来自事件中心的摘要消息,但缺少详细的设备消息。在
使用Azure IOT远程监控示例(https://github.com/Azure/azure-iot-remote-monitoring,https://www.azureiotsolutions.com/Accelerators)和IOT集线器资源管理器https://github.com/Azure/iothub-explorer提供如下消息:
==== From: 'chiller-01.0' at '2018-06-27T17:35:13.835Z' ==== { "temperature": 74.8813305672404, "temperature_unit": "F", "humidity": 67.345695720448, "humidity_unit": "%", "pressure": 155.648674178239, "pressure_unit": "psig" } ---- application properties ---- { "iothub-message-schema": "chiller-sensors;v1", "iothub-creation-time-utc": "2018-06-27T17:35:13.5066336Z", "$$CreationTimeUtc": "2018-06-27T17:35:13+00:00", "$$MessageSchema": "chiller-sensors;v1", "$$ContentType": "JSON" }
为了在python中获取这些消息,我使用了azure event hubs python库和https://github.com/Azure/azure-event-hubs-python上的示例,使用在“操作”选项卡上为IOT中心指定的事件中心连接字符串从事件中心读取IOT消息。在Node JS中编写的IOT Hub Explorer使用IOT Hub连接字符串,但是使用python编写相应的代码失败,并且EventHubClient.from连接字符串失败,因为“EndPoint”不在连接字符串中。将连接字符串中的“HostName”更改为“EndPoint”会在中出错连接.pyx公司名称:
File "./src/connection.pyx", line 20, in uamqp.c_uamqp.create_connection TypeError: expected bytes, NoneType found
预先挂起协议sb://到终结点时,会抱怨未指定EventHub:
ValueError: No EventHub specified
添加;EntityPath=会更进一步,但失败时出现CBS令牌身份验证错误:
azure.eventhub.EventHubError: Receive failed: CBS Token authentication failed. Status code: 401 Description: b'The specified SAS token has an invalid signature. It does not match either the primary or secondary key.'
将事件集线器连接字符串用于IOT集线器连接和接收消息可修复这些错误,但仅接收摘要数据而不进行任何设备遥测,例如:
{
"count": 0,
"total": 0,
"minimum": 0,
"maximum": 0,
"average": 0,
"resourceId": "/SUBSCRIPTIONS/{SUBSCRIPTION}/RESOURCEGROUPS/{RESOURCEGROUP}/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/{IOTHUB}",
"time": "2018-06-27T16:59:00.0000000Z",
"metricName": "jobs.failed",
"timeGrain": "PT1M"
}
由于设备数据丢失,我不确定是否向pythoneventhubclient传递了正确的参数,还是客户机没有返回这些参数。一年前的堆栈交换How can I receive from Azure IoT Hub messages sent by devices?表明无法使用Python读取遥测数据,但由于Python EventHub SDK已经存在,我希望这个问题已经得到解决。在
是的,最新的EventHubs SDK可以使用python读取遥测数据。 我不知道你是否提到过GitHub上发布的issue(#28)。我认为annatisch在4月28日的评论对这个问题很有帮助。在
相关问题 更多 >
编程相关推荐