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