4
votes

I have a IoT Hub with 2 IoT devices both sending environmental data (Temperature and Humidity) I created a custom endpoint and route to my Azure Storage Account, it gets saved there so I can look back. The problem is it sends raw telemetry data including weird characters and stuff like that. I figured out it was in a CSV format but I still can't parse it.

My question is, I want to take the raw telemetry data directly from the blob and parse it into a SensorResult class using C#. I figured out how to read the blob data I just need to parse the telemetry data. But I can't figure that part out.

Snippet of raw telemetry data:

Objavro.codecnullavro.schemaÐ{"type":"record","name":"Message","namespace":"Microsoft.Azure.Devices","fields":[{"name":"EnqueuedTimeUtc","type":"string"},{"name":"Properties","type":{"type":"map","values":"string"}},{"name":"SystemProperties","type":{"type":"map","values":"string"}},{"name":"Body","type":["null","bytes"]}]}°ÈF¬êYâS:á…ð82018-06-29T18:34:10.4320000Z temperatureAlert
falsemessageIdmessage_0correlationIdcorrelation_0$connectionDeviceIdraspi(connectionAuthMethodœ{"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}8connectionDeviceGenerationId$0enqueuedTime82018-06-29T18:34:10.4320000Z¨{"deviceId": "Raspberry Pi - Python","temperature": 28.801060,"humidity": 40.097196}82018-06-29T18:34:12.3400000Z temperatureAlert

First line being the header of the telemetry, all lines below that are just messages from the IoT devices.

Thanks.

1
I have the same issue, but file is having format like this Objavro.codecnullavro.schema�{"type":"record","name":"Message","namespace":"Microsoft.Azure.Devices","fields"kudlatiger

1 Answers

2
votes

the following is a code snippet for avro reader:

 using Microsoft.Hadoop.Avro.Container;

 // ...
 using (var reader = AvroContainer.CreateGenericReader(myBlob))
 {
    while (reader.MoveNext())
    {
       foreach (dynamic record in reader.Current.Objects)
       {
          var bodyText = Encoding.UTF8.GetString(record.Body);
          log.Info($"AvroRecord = {bodyText}");
       }
    }
 }