1

My device registered on the Cumulocity IoT Platform has a signal for the current battery level: DLValues => battery_level

I want to compute the total energy consumption from this signal. The energy consumption between two battery level measurements can be computed with the following expression:

create expression double calcConsumedEnergy(prevBatteryLevel, newBatteryLevel) [
  var batteryCapacity = 100;
  var energyConsumption = 0;
  if(newBatteryLevel < prevBatteryLevel){
      energyConsumption = batteryCapacity * (prevBatteryLevel - newBatteryLevel) / 100;
  }
  energyConsumption;
];

My question is: How can I add up the delta between the battery level measurements?

If I create a new signal DLValuesCalc => energy_consumption, then initialy it will have no measurement at all, so I cannot use this signal conceptually in the following way:

DLValuesCalc.energy_consumption.value = DLValuesCalc.energy_consumption.value + delta
eanbmu
  • 11
  • 2

1 Answers1

0

Probably the built-in aggregation functions in esper will already solve this for you (http://esper.espertech.com/release-7.0.0/esper-reference/html/functionreference.html#epl-function-aggregation). There is a function sum() that will do the job for you (it handles also the initial null value). It just needs the return value of your expression as input.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23