如何使用 Cumulocity REST 创建测量?

How can I create a Measurement with Cumulocity REST?

我是 Cumulocity 的新手,正在尝试用 C# 为 Cumulocity 平台编写微服务。

我从这里克隆了 Cumulocity.SDK.Client REST 示例: https://bitbucket.org/m2m/cumulocity-sdk-cs/src/master/

我通过InventoryApi创建了一些设备,并在创建时添加了一些属性(c8y_Hardware, c8y_RequiredAvailability, c8y_Position)。 当我尝试向设备添加测量值时,我迷路了。

我尝试将度量添加为属性。

我的代码如下所示:

 MeasurementRepresentation measurement = new MeasurementRepresentation();

 measurement.DateTime = DateTime.Now.ToUniversalTime();
 measurement.Source = InventoryAPI.Get(new GId(deviceId));
 measurement.Type = "Temperature";

 JObject T = new JObject();
 T.Add("value", 90);
 T.Add("unit","C");
 measurement.Attrs.Add("Temperature", T);

 MeasurementApi.Create(measurement);

有了这个,我想要设备的温度类型测量。它不会引发错误,但也不会创建任何测量结果。

首先我以为我的Json嵌套是错误的,所以在"T"之前的属性下又加了一层。

像这样:

 JObject T = new JObject();
 T.Add("value", 90);
 T.Add("unit","C");

 JObject temperatureMeasurement = new JObject();
 temperatureMeasurement.Add("T",T);

 measurement.Attrs.Add("Temperature", temperatureMeasurement);

这个也没用。

当我查看测试文件时,我看到正在使用一些 Set() 方法。我应该创建一个测量对象,然后用 Set() 方法传递它吗?

由于测试文件中的片段 类 是空的,我不知道对象应该是什么样子。

我是完全不在了还是只是错过了一些小事?

为设备创建测量的正确方法是什么?

显然正确的方法是使用 Set() 方法,并将测量 class 作为对象参数。