esp-matter icon indicating copy to clipboard operation
esp-matter copied to clipboard

How to write value to ElectricalEnergyMeasurement::Attributes::Accuracy::Id (CON-1326)

Open svn-matterize opened this issue 1 year ago • 4 comments

Trying to write a array value to the attribute ElectricalEnergyMeasurement::Attributes::Accuracy::Id using esp_matter_array

ElectricalEnergyMeasurement::Structs::MeasurementAccuracyRangeStruct::Type energyAccuracyRanges[] = {
		{ .rangeMin = 0,
		  .rangeMax = 1'000'000'000'000'000, // 1 million Mwh
		  .percentMax = chip::MakeOptional(static_cast<chip::Percent100ths>(500)),
		  .percentMin = chip::MakeOptional(static_cast<chip::Percent100ths>(50)) }
	};

	ElectricalEnergyMeasurement::Structs::MeasurementAccuracyStruct::Type accuracy = {
		.measurementType = chip::app::Clusters::detail::MeasurementTypeEnum::kElectricalEnergy,
		.measured = true,
		.minMeasuredValue = 0,
		.maxMeasuredValue = 1'000'000'000'000'000, // 1 million Mwh
		.accuracyRanges = chip::app::DataModel::List<
			const ElectricalEnergyMeasurement::Structs::MeasurementAccuracyRangeStruct::Type>(
			energyAccuracyRanges)
	};
	arr_val = esp_matter_array((uint8_t *)&accuracy, sizeof(arr_val), 1);
	// err = attribute::set_val(attribute, &arr_val);
	err = attribute::update(Endpoint.kPlug, ElectricalEnergyMeasurement::Id,
				ElectricalEnergyMeasurement::Attributes::Accuracy::Id, &arr_val);
	if (err != ESP_OK) {
		ESP_LOGE(TAG, "Updated EnergyAccuracy failed");
	}

Device log during attribute update

I (2862) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000091's Attribute 0x00000000 is <invalid type: 4> **********

Chip tool read back

[1725446179.843262][8020:8022] CHIP:DMG: ReportDataMessage =
[1725446179.843366][8020:8022] CHIP:DMG: {
[1725446179.843492][8020:8022] CHIP:DMG: 	AttributeReportIBs =
[1725446179.843806][8020:8022] CHIP:DMG: 	[
[1725446179.843979][8020:8022] CHIP:DMG: 		AttributeReportIB =
[1725446179.844116][8020:8022] CHIP:DMG: 		{
[1725446179.844245][8020:8022] CHIP:DMG: 			AttributeStatusIB =
[1725446179.844411][8020:8022] CHIP:DMG: 			{
[1725446179.844566][8020:8022] CHIP:DMG: 				AttributePathIB =
[1725446179.845094][8020:8022] CHIP:DMG: 				{
[1725446179.845569][8020:8022] CHIP:DMG: 					Endpoint = 0x1,
[1725446179.846278][8020:8022] CHIP:DMG: 					Cluster = 0x91,
[1725446179.846903][8020:8022] CHIP:DMG: 					Attribute = 0x0000_0000,
[1725446179.847421][8020:8022] CHIP:DMG: 				}
[1725446179.847961][8020:8022] CHIP:DMG: 					
[1725446179.848284][8020:8022] CHIP:DMG: 				StatusIB =
[1725446179.848313][8020:8022] CHIP:DMG: 				{
[1725446179.848338][8020:8022] CHIP:DMG: 					status = 0x89 (RESOURCE_EXHAUSTED),
[1725446179.848442][8020:8022] CHIP:DMG: 				},
[1725446179.848470][8020:8022] CHIP:DMG: 				
[1725446179.848557][8020:8022] CHIP:DMG: 			},
[1725446179.848583][8020:8022] CHIP:DMG: 			
[1725446179.848651][8020:8022] CHIP:DMG: 		},
[1725446179.849047][8020:8022] CHIP:DMG: 		
[1725446179.849136][8020:8022] CHIP:DMG: 	],
[1725446179.849159][8020:8022] CHIP:DMG: 	
[1725446179.849173][8020:8022] CHIP:DMG: 	SuppressResponse = true, 
[1725446179.849190][8020:8022] CHIP:DMG: 	InteractionModelRevision = 11
[1725446179.849264][8020:8022] CHIP:DMG: }
[1725446179.849314][8020:8022] CHIP:TOO: Response Failure: IM Error 0x00000589: General error: 0x89 (RESOURCE_EXHAUSTED)

while reading the attribute device log is

I (13352) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000091's Attribute 0x00000000 is <invalid type: 4> **********
E (13362) esp_matter_attribute: Insufficient space for reading Endpoint 0x0001's Cluster 0x00000091's Attribute 0x00000000: required: 4, max: 2

svn-matterize avatar Sep 04 '24 10:09 svn-matterize

Any news about this issue?

lboue avatar Sep 12 '24 07:09 lboue

@svn-matterize Sorry for the delayed response, you cannot use esp_matter_array for storage because esp-matter doesn’t support array attribute storage. There is API to set Accuracy in the connectedhomeip SDK SetMeasurementAccuracy. You have to use this.

jadhavrohit924 avatar Sep 16 '24 05:09 jadhavrohit924

@jadhavrohit924 , attribute storage, are you mentioning (ATTRIBUTE_FLAG_NONVOLATILE) nvs storage? Is it possible to attribute::update/set attribute value using esp_matter_array, if the flag is (ATTRIBUTE_FLAG_NONE)? How to form the struct value to array using esp_matter_array any example.

svn-matterize avatar Sep 16 '24 06:09 svn-matterize

Independent of attribute quality, storage of arrays and structs are not possible using esp-matter because for such attributes there is delegate implementation in the connectedhomeip SDK. But delegate is missing for ElectricalEnergyMeasurement cluster so you have to reach to the SDK to update/set the attribute of this cluster.

jadhavrohit924 avatar Sep 16 '24 06:09 jadhavrohit924

@svn-matterize Sorry for the delayed response, you cannot use esp_matter_array for storage because esp-matter doesn’t support array attribute storage. There is API to set Accuracy in the connectedhomeip SDK SetMeasurementAccuracy. You have to use this.

Hi there,

Calling this API emits an error CHIP_ERROR_INVALID_ARGUMENT, it seems there's a missing link between EndpointID and emberAfGetClusterServerEndpointIndex() function, as it does not find the corresponding endpoint.

What's really missing?

HamzaHajeir avatar Oct 10 '24 15:10 HamzaHajeir

@svn-matterize Sorry for the delayed response, you cannot use esp_matter_array for storage because esp-matter doesn’t support array attribute storage. There is API to set Accuracy in the connectedhomeip SDK SetMeasurementAccuracy. You have to use this.

Hi there,

Calling this API emits an error CHIP_ERROR_INVALID_ARGUMENT, it seems there's a missing link between EndpointID and emberAfGetClusterServerEndpointIndex() function, as it does not find the corresponding endpoint.

What's really missing?

Queued the function call to post initializing time solves the issue.

HamzaHajeir avatar Oct 13 '24 13:10 HamzaHajeir

@svn-matterize Can you please close the issue if it is resolved?

jadhavrohit924 avatar Nov 27 '24 10:11 jadhavrohit924