Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;
- using Microsoft.Azure.WebJobs;
- using Microsoft.Azure.WebJobs.Host;
- using Microsoft.Azure.EventHubs;
- using System.Text;
- using System.Net.Http;
- using Microsoft.Extensions.Logging;
- using System;
- using Newtonsoft.Json;
- namespace Iot19
- {
- public static class SaveToTableStorage
- {
- private static HttpClient client = new HttpClient();
- [FunctionName("SaveToTableStorage")]
- [return: Table("messages")]
- public static TableStorageModel Run([IoTHubTrigger("messages/events", Connection = "IotHubconnection",ConsumerGroup ="tablestorage")]EventData message, ILogger log)
- {
- log.LogInformation($"Saving messages to TableStorage");
- var obj = JsonConvert.DeserializeObject<TableStorageModel>(Encoding.UTF8.GetString(message.Body));
- var tsm = new TableStorageModel();
- DateTimeOffset date = DateTimeOffset.FromUnixTimeSeconds(obj.timeStamp);
- obj.UtcTime = date.UtcDateTime;
- tsm.PartitionKey = "IOT";
- tsm.RowKey = Guid.NewGuid().ToString();
- tsm.MyName = message.Properties["MyName"].ToString();
- tsm.SchoolName = message.Properties["SchoolName"].ToString();
- tsm.ClassName = message.Properties["ClassName"].ToString();
- tsm.TemperatureAlert = message.Properties["temperatureAlert"].ToString();;
- tsm.deviceId = obj.deviceId;
- tsm.messageId = obj.messageId;
- tsm.temperature = obj.temperature;
- tsm.humidity = obj.humidity;
- tsm.lightSenorValue = obj.lightSenorValue;
- tsm.UtcTime = obj.UtcTime;
- tsm.Latitud = obj.Latitud;
- tsm.Longitud = obj.Longitud;
- return tsm;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement