Hi,
we have option to calculate measurement average in Epl, as
using com.apama.aggregates.avg;
using com.apama.aggregates.last;
using com.apama.cumulocity.Measurement;
action onload() {
// Subscribe to Measurement.CHANNEL to receive all measurements
monitor.subscribe(Measurement.CHANNEL);
from m in all Measurement(type="c8y_TemperatureMeasurement") within (3600.0)
group by m.source select
AverageByDevice(m.source,
avg(m.measurements["c8y_TemperatureMeasurement"]["T"].value),
last(m.measurements["c8y_TemperatureMeasurement"]["T"].unit)) as avgdata {
send Measurement("", "c8y_AverageTemperatureMeasurement", avgdata.source, currentTime,
{"c8y_AverageTemperatureMeasurement":
{
"T": MeasurementValue(avgdata.avgValue, avgdata.unit, new dictionary<string,any>)
}
}, new dictionary<string,any>) to Measurement.CREATE_CHANNEL;
}
}
},
i want to achieve the same thing in java microservice using the cumulocity sdk , i just want
the implementation of avg() and last() in java, please help with the code snippet
If you add a dateRange with dateFrom & dateTo you will retrieve multiple measurements not only the recent one.
No API supports the retrieval of an average value unfortunately.
I don’t think this API is implemented in the SDK but you can give it a try: Cumulocity IoT - OpenAPI Specification
It allows to you define the aggregation but it returns only min max values, not the average.
So I guess you have to implement/calculate that on your own as mentioned above.