Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;
  2.  
  3. using Microsoft.Azure.WebJobs;
  4. using Microsoft.Azure.WebJobs.Host;
  5. using Microsoft.Azure.EventHubs;
  6. using System.Text;
  7. using System.Net.Http;
  8. using Microsoft.Extensions.Logging;
  9. using System;
  10. using Newtonsoft.Json;
  11.  
  12. namespace Iot19
  13. {
  14. public static class SaveToTableStorage
  15. {
  16. private static HttpClient client = new HttpClient();
  17.  
  18. [FunctionName("SaveToTableStorage")]
  19. [return: Table("messages")]
  20. public static TableStorageModel Run([IoTHubTrigger("messages/events", Connection = "IotHubconnection",ConsumerGroup ="tablestorage")]EventData message, ILogger log)
  21. {
  22. log.LogInformation($"Saving messages to TableStorage");
  23.  
  24.  
  25. var obj = JsonConvert.DeserializeObject<TableStorageModel>(Encoding.UTF8.GetString(message.Body));
  26. var tsm = new TableStorageModel();
  27.  
  28. DateTimeOffset date = DateTimeOffset.FromUnixTimeSeconds(obj.timeStamp);
  29. obj.UtcTime = date.UtcDateTime;
  30.  
  31. tsm.PartitionKey = "IOT";
  32. tsm.RowKey = Guid.NewGuid().ToString();
  33. tsm.MyName = message.Properties["MyName"].ToString();
  34. tsm.SchoolName = message.Properties["SchoolName"].ToString();
  35. tsm.ClassName = message.Properties["ClassName"].ToString();
  36. tsm.TemperatureAlert = message.Properties["temperatureAlert"].ToString();;
  37. tsm.deviceId = obj.deviceId;
  38. tsm.messageId = obj.messageId;
  39. tsm.temperature = obj.temperature;
  40. tsm.humidity = obj.humidity;
  41. tsm.lightSenorValue = obj.lightSenorValue;
  42. tsm.UtcTime = obj.UtcTime;
  43. tsm.Latitud = obj.Latitud;
  44. tsm.Longitud = obj.Longitud;
  45.  
  46.  
  47. return tsm;
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement