Hi,
I have a couple of I/O i am reading both temperature and humidity data from, and i would like to trigger an alarm within Cumulocity once a certain threshold has been exceeded. I know i can use Smart Rules for this but when i have 20+ data points, this can be a bit tedious. i was wondering if can i be able to use Apama EPL for Cumulocity to filter out the measurements based on the fragment alone and ignore the series?! For example i have the fragments “gmj_Temperature” and “gmj_Humidity” which i would like to implement the alarms fro if a certain threshold is exceeded.
Can you help understand your use case by answering below queries?
- Would both fragments be part of a single measurement or are they sent individually ? would there be multiple series for each fragment ?
- How should these measurement fragments be correlated ? Are you expecting to raise alarm only when both these are above a threshold or do you want to raise alarms even if one of the values is beyond a threshold ?
- If measurements are sent individually, What basis should be used to correlate individual measurements ? will measurement creation ‘time’ be the same for both sensors ?
- Do you expect the measurements to arrive out of order ?
Hi Ravish,
I will be responding to your questions in their order:
-
The fragments are not from a single measurement but they are separate and there are multiple series within each fragment.
-
For each fragment there is a constant threshold level, so at any point where any one of the thresholds is exceeded by any of the values in a series i would like to trigger an alarm.
-
Yes, the time for the measurements will be the same as both sensors are connected to the same client.
-
I expect the measurements to be ordered according to their series, if am understanding your question correctly.
Thanks Vuyo,
You can subscribe to receive MeasurementFragment to listen to each fragments and series in a measurement. Depending on your data and use case you can use either one of the solution:
Scenario 1:
If you are expecting only few measurements to cross the threshold value and the fragments for which you want to check threshold is a static:
using com.apama.cumulocity.MeasurementFragment;
monitor MySampleMonitor {
/** Initialize the application */
dictionary<string, float> fragmentThreshold := {"gmj_Temperature":10.0, "gmj_Humidity":20.0};
action onload() {
// Application starts here
monitor.subscribe(MeasurementFragment.SUBSCRIBE_CHANNEL);
string fragment;
for fragment in fragmentThreshold.keys() {
on all MeasurementFragment(valueFragment=fragment, value > fragmentThreshold[fragment]) {
// Create and send alarm
}
}
}
}
Scenario 2 :
If you are expecting many measurements to cross the threshold value or the fragments for which you want to check threshold is a dynamic:
using com.apama.cumulocity.MeasurementFragment;
monitor MySampleMonitor {
/** Initialize the application */
dictionary<string, float> fragmentThreshold := {"gmj_Temperature":10.0, "gmj_Humidity":20.0};
action onload() {
// Application starts here
monitor.subscribe(MeasurementFragment.SUBSCRIBE_CHANNEL);
from mf in all MeasurementFragment() where fragmentThreshold.hasKey(mf.valueFragment) and mf.value > fragmentThreshold[mf.valueFragment] select mf as mf {
// Create and send alarm
}
}
}
Scenario 3:
If you need to perform some aggregation as well before generating an alarm
using com.apama.cumulocity.MeasurementFragment;
monitor MySampleMonitor {
/** Initialize the application */
dictionary<string, float> fragmentThreshold := {"gmj_Temperature":10.0, "gmj_Humidity":20.0};
action onload() {
// Application starts here
monitor.subscribe(MeasurementFragment.SUBSCRIBE_CHANNEL);
on all MeasurementFragment() as mf{
if(fragmentThreshold.hasKey(mf.valueFragment) and mf.value > fragmentThreshold[mf.valueFragment]) {
// Create and send alarm
}
}
}
}
Kindly make below update in the files mentioned to enable receiving MeasurementFragment :
CumulocityIoT.yaml:
startChains:
CumulocityIoT:
… …
- ApamaConnectivityForCumulocityIoT:
… …
measurementFormat: ${CUMULOCITY_MEASUREMENT_FORMAT}
CumulocityIoT.properties:
#set cumulocity measurement format
CUMULOCITY_MEASUREMENT_FORMAT=BOTH