Apama 10.15.0 | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The Cumulocity IoT Transport Connectivity Plug-in | Using measurements
 
Using measurements
 
Creating a new measurement
Querying for measurements
During application initialization (onApplicationInitialized), if subscribeToAllMeasurements is enabled (true by default), the adapter sends all measurements using the com.apama.cumulocity.Measurement event on the com.apama.cumulocity.Measurement.SUBSCRIBE_CHANNEL (same as cumulocity.measurements) channel.
These events may be sent before all assets are sent. Measurement events contain the identifier of the source of the measurement, the type of measurement, timestamp, and a dictionary of values which contain the numeric value, units and optional type, quantity and state.
Examples of measurement events:
Measurement("1001","c8y_LightMeasurement","12346081",1464359004.89,
{"c8y_LightMeasurement": {"e":com.apama.cumulocity.MeasurementValue(108.1,
"lux", new dictionary<string, any>)}},new dictionary<string, any>)

Measurement("1002","c8y_DistanceMeasurement","12346082",1464359005.396,
{"c8y_DistanceMeasurement": {"distance":com.apama.cumulocity.MeasurementValue
(344,"mm","","","", dictionary<string, any>)}}, dictionary<string, any>)
Example
The following is a simple example of how to receive, create and send measurements:
// Subscribe to receive all the measurements published from Cumulocity IoT
monitor.subscribe(Measurement.SUBSCRIBE_CHANNEL);

// Consume all the measurements from Cumulocity IoT
on all Measurement() as m {
log m.toString() at INFO;
}

// Create a new measurement

Measurement m := new Measurement;
m.source := "<MANAGED_OBJECT_ID>";
m.time := currentTime;
m.type := "TemperatureMeasurement";
MeasurementValue mv := new MeasurementValue;
mv.value := 100.0;
dictionary<string, MeasurementValue> fragment
:= new dictionary<string, MeasurementValue>;
fragment.add("temperature", mv);
m.measurements.add("TemperatureMeasurement", fragment);
send m to Measurement.SEND_CHANNEL;