2016-09-23 63 views
0

我想使用事件处理功能来创建派生测量。实时处理 - 读取受管理对象片段

我们的设备报告了一个测量结果,该测量结果具有目标值,我们将其存储在每个设备中的受管理对象片段中。我想创建一个设备测量,它是测量和目标之间的差异,它似乎是RTP/CEL实现的理想候选者。

我已经看过real time processing指南,但无法完全弄清楚如何从管理对象中读取片段。

编辑。我更新了我的代码,并且即将到达那里,我无法弄清楚如何使用来自测量的传入deviceId作为获取我的分段数据的地方。

create variable ManagedObject device = findManagedObjectById(m.measurement.source.value); 
create variable BigDecimal setpoint = getNumber(device, "uty_Setpoint.value"); 

insert into CreateMeasurement 
select 
    m.measurement.time as time, 
    m.measurement.source.value as source, 
    "uty_Pressure_delta" as type, 
    {"uty_Pressure_delta.T.value", getNumber(m, "uty_Pressure.pressure.value") - setpoint, 
    "uty_Pressure_delta.T.unit", "percent" } as fragments 
from MeasurementCreated m 
where getNumber(m, "uty_Pressure.pressure.value") is not null 
+1

你应该直接在声明中做,而不是作为外部变量。所以用getNumber替换设定点(findManagedObjectById(m.measurement.source.value),“uty_Setpoint.value”) 编辑:背景是像声明它们的变量在部署语句时得到解决(这不会工作,因为m .measurement.source.value无法解析) – TyrManuZ

+0

这解释了为什么每次重新部署它时都会起作用!谢谢。 –

回答

1

第一步是查询基于所述测量

findManagedObjectById(measurement.source.value) 

也可以看看地理围栏例如其也读出来自设备对象一些参数的源极上的对象。

http://cumulocity.com/guides/event-language/geofence/

之后,您可以用这些功能的访问片段:

getNumber(deviceObject, "myFragmentInDevice.value") 

getString(deviceObject, "myFragmentInDevice.value") 

我将确保目标值存储为数字而不是字符串,因为你可以使用getNumber功能这将返回一个BigDecimal。

http://cumulocity.com/guides/event-language/functions/#utility-functions