0
votes

How do I receive device messages in Event Hub using Python? I am seeing summary messages from Event Hub, but detailed device messages are missing.

Using the Azure IOT Remote Monitoring Example (https://github.com/Azure/azure-iot-remote-monitoring, https://www.azureiotsolutions.com/Accelerators) and IOT Hub Explorer https://github.com/Azure/iothub-explorer provides messages like these:

==== 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" }

To get those messages in python, I am using the azure-event-hubs-python library and examples at https://github.com/Azure/azure-event-hubs-python to read IOT messages from an Event Hub using the Event Hub connection string specified for the IOT Hub on the Operations tab. The IOT Hub Explorer written in Node JS uses the IOT Hub Connection String, but writing the corresponding code using python fails and EventHubClient.from_connection_string fails because 'EndPoint' is not in the connection string. Changing 'HostName' to 'EndPoint' in the connection string gives an error in connection.pyx:

File "./src/connection.pyx", line 20, in uamqp.c_uamqp.create_connection TypeError: expected bytes, NoneType found

Pre-pending the protocol sb:// to the endpoint complains that the EventHub is not specified:

ValueError: No EventHub specified

Adding ;EntityPath= gets further, but fails with a CBS Token authentication error:

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.'

Using the Event Hub Connection string for the IOT Hub connects and receives messages fixes these errors, but receives summary data only without any device telemetry, for example:

{
  "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"
}

Since the device data is missing, I am not sure if I am passing the correct parameters to the Python EventHubClient, or if the client is just not returning them. This stack exchange from a year ago How can I receive from Azure IoT Hub messages sent by devices? indicated that reading the telemetry using Python was not available, but since the Python EventHub SDK is out there I'm hoping this has been fixed.

1

1 Answers

0
votes

Yes, reading the telemetry using python was available with the latest EventHubs SDK. I don't know if you have referred to the issue(#28) posted on GitHub. I think the response commented by annatisch on Apr 28 is helpful for this issue.