我想通过Function App编写代码来处理来自IoT传感器的数据。 我为此使用功能代码:
#r "Microsoft.WindowsAzure.Storage"
using System;
using Microsoft.WindowsAzure.Storage.Table;
public static void Run(DataPoint myIoTHubMessage, out DataPoint outputTable)
{
myIoTHubMessage.PartitionKey = DateTime.Now.ToString("yyMMddHH");
myIoTHubMessage.RowKey = DateTime.Now.ToString("yyyy-MM-ddTH:mm:ss");
outputTable = myIoTHubMessage;
}
public class DataPoint : TableEntity
{
public string deviceId { get; set; }
public double rpm { get; set; }
}
对于此代码,我将从具有以下消息格式的传感器数据中获取:
{"deviceId":"os-test1","rpm":29.306095180868812,"devicetime":"2019-08-12T11:33:46.978Z","edgeCnt":72,"var_A":"A"}
在此示例中,一切正常,输出(存储表)中写入了deviceId和rpm值...
但是现在我正在尝试从新传感器处理数据,其中消息看起来有点不同:
{"nodes":{"00:13:A2:00:41:94:1A:9D":{"transmission_count":191,"battery_level":3.16204,"type":27,"node_id":0,"rssi":100,"temperature":25,"pressure":985,"humidity":51,"gas_resistance":61427,"iaq":24}}}
...而我的代码不起作用...:-/
我已经更新了DataPoint类:
public class DataPoint : TableEntity
{
public double battery_level { get; set; }
public double temperature { get; set; }
public double pressure { get; set; }
public double humidity { get; set; }
public double gas_resistance { get; set; }
public double iaq { get; set; }
}
所有请求的变量都写入到输出中,但是值为零...
显然,消息的结构不同(上面的“节点”段有问题),但是我在C#中是乞be,我不知道该如何解决...
你能帮助我吗?