我有 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/