Azure 功能 - 从 IoT 中心保存到表存储

标签 azure azure-functions azure-table-storage azure-iot-hub

我有 5 台设备连接到 IoT 中心。此设备发送消息,我已将此消息保存到 Azure 存储表而不是 blob。

我所做的一切都是基于本指南https://blog.maximerouiller.com/post/persisting-iot-device-messages-into-cosmosdb-with-azure-functions-and-iot-hub/不幸的是,我可以毫无问题地添加输入和输出,不幸的是,我无法编写一个函数代码来将该数据保存到表中:(

我可以将数据从 IoT 中心保存到 Blob 存储,从带流分析的 IoT 中心保存到表存储,但无法从没有 SA 的 IoT 中心保存到表存储:(

最佳答案

我建议您针对您的情况使用azure table storage REST API。

您也可以使用 SDK。请往下看。

类别

public class Item : TableEntity
    {
        public Item()
        {
            PartitionKey = "YourPartionKey";
            RowKey = "YourRowKey";
        }
        public string Message{ get; set; }
        public string Description { get; set; }

    }

使用 SDK 的内部函数

 Item entity = new Item("YourPartionKey", "YourRowKey")
            {
                Message= "I am From IOT Device",
                Description = "I am from IOT and Want to go to Storage"
            };
            // My Storage operation 
            var client = new CloudTableClient(new Uri("https://YourTableStorageAccountName.table.core.windows.net/"),
                      new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("YourTableStorageAccountName", "YourStorageKey"));
            var table = client.GetTableReference("YourTableName");

            TableOperation insertOperation = TableOperation.Insert(entity);
            var insertOnstorage = await table.ExecuteAsync(insertOperation);

            Console.WriteLine("Entity inserted!");

REST API 引用

URL: https://YourAccount.table.core.windows.net/YourTableThatYouWantedToInsertMessase

方法: POST

请求正文:

{  

   "Message":"IOT Message",  
   "Description":"I am from IOT and Want to go to Storage",  
   "PartitionKey":"Yourpartitionkey",  
   "RowKey":"YourRowkey"  
}

Note: For more details you could refer here

如果您还有任何疑问,请随时分享。谢谢您,祝您编码愉快!

关于Azure 功能 - 从 IoT 中心保存到表存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56119524/

相关文章:

Azure 混合连接管理器卡在 "Saving please wait"

azure - Azure Functions 中可以使用属性路由吗

azure - 无法在 Visual Studio 2017 中加载迁移的 Azure 函数项目

azure-table-storage - 表存储: Retrieve all partition keys

azure - ServiceInsight Azure 连接到 VM

azure - 使用 Ambassador API 网关在 Azure Kubernetes 上自定义域

azure - 有没有办法将文件从 azure 应用程序服务复制到另一个 azure 应用程序服务?

c# - 在添加 Azure 逻辑应用程序中使用 (HttpTrigger – C#) 的 Azure 函数

azure - 如何在 Azure 表存储中创建唯一属性