I used to have this code working:
// Get the previous measurement
MeasurementData* previousMeasurement = ElectricalEnergyMeasurement::MeasurementDataForEndpoint(GetEndpointId());
then I used it to get the timestamps for the last measurement:
energyImported.startTimestamp.ClearValue();
energyImported.startSystime.ClearValue();
if (previousMeasurement->cumulativeImported.HasValue())
{
energyImported.startTimestamp = previousMeasurement->cumulativeImported.Value().endTimestamp;
energyImported.startSystime = previousMeasurement->cumulativeImported.Value().endSystime;
}
The problem is that ElectricalEnergyMeasurement::MeasurementDataForEndpoint doesn't seem to exist anymore.
But, I found this function (in app/clusters/electrical-energy-measurement-server/ElectricalEnergyMeasurementCluster.cpp):
CHIP_ERROR ElectricalEnergyMeasurementCluster::GetCumulativeEnergyImported(Optional<EnergyMeasurementStruct> & outValue) const
But, I don't fully understand how to call it from code like the all-device-types-app electrical-measurement.cpp.
How would such code look like?