Exemplo n.º 1
0
 public async Task SendToHubV1(DeviceTelemetry deviceTelemetry, string clinetDeviceConnectionString)
 {
     try
     {
         using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(clinetDeviceConnectionString, transportType))
         {
             //await deviceClient.OpenAsync();//ToDo.Do we need this?
             //await UpdateTwin(deviceClient);//ToDo-Fix this
             await SendTelemetry(deviceClient, deviceTelemetry);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception occured while creating device client " + ex.ToString());
     }
 }
Exemplo n.º 2
0
 //TODo-Should we really use Message? It has restiction of 250kb and JSON serialization much increases the byte array size. Explore all other options of sending
 //ToDo-Handle MessageTooLarge exception
 private static async Task SendTelemetry(DeviceClient deviceClient, DeviceTelemetry deviceTelemetry)
 {
     var payload = JsonConvert.SerializeObject(deviceTelemetry);
     var message = new Message(Encoding.ASCII.GetBytes(payload));
     await deviceClient.SendEventAsync(message);
 }