[Matter] Is there an example/tutorial how to deal with subscriptions / readings of an Cluster - Attribute with a device (not with CHIP Tool)

Hi Nordic's,

is there a description or example available for my mentioned issue?

I want to subscribe one device/node to another one. For example:

I have extend the template-example with the thermostat-Cluster. I put it on a device wich measure the temperature and which are able to set a new set point to control the temperature. On a second device I want to read out (or get informed if LocalTemperature changed) the attribute LocalTemperature from the thermostat-Cluster of the first device.

How I have to implement the subscription or the read-out command?

Is that also a binding?

Best regards,

Benny

Parents Reply Children
  • Hi  ,

    okay thanks for your support, I will wait for your answer :-)

  • Hi,

    I asked the development team about this. Unfortunately, there is no API documentation other than very limited doxygen comments for Matter, so you need to read the code of existing examples and tools in order to write a new Matter application. This means that there is no straightforward API to use for figuring out how to subscribe. However, a starting point would be examples/chip-tool/commands/clusters/ReportCommand.h. If you dig deeper from this point you can find that the way to use read/subscribe interactions is to use ReadClient class:

    auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
      mBufferedReadAdapter, interactionType);
      if (interactionType == ReadClient::InteractionType::Read)
      { 
        ReturnErrorOnFailure(client->SendRequest(params));
      }

    Hope this helps!

    Best regards,

    Marte

  • Hi ,

    I've tried to implement class for handling reading temperature value from another node. There are static methods functions called: "Controler::ReadAttribute", "Controller::SubscribeAttribute". Maybe this code could be useful as example:

    void SensorsManager::SensorsWorkerHandler(intptr_t aContext)
    {
          VerifyOrReturn(aContext != 0);
          SensorsData * data = reinterpret_cast<SensorsData *>(aContext);
    
          const chip::OperationalDeviceProxy * aDevice =  SensorsManager::GetInstance().GetOperationalDeviceProxy();
          VerifyOrDie(aDevice);
    
          using Type = app::Clusters::TemperatureMeasurement::Attributes::MeasuredValue::TypeInfo::Type;
          
          auto onSuccess = [](const app::ConcreteDataAttributePath & aPath, const Type & aData) {
              ChipLogProgress(AppServer, "ReadAttribute .... applied successfully!");
          };
    
          auto onFailure = [](const app::ConcreteDataAttributePath * aPath, CHIP_ERROR aError) {
              ChipLOgError(AppServer, "ReadAttribute .... error!");
          };
    
          CHIP_ERROR ret = Controller::ReadAttribute<Type>(
                  aDevice->GetExchangeManager(),
                  aDevice->GetSecureSession().Value(),
                  data->EndpointId,
                  data->ClusterId,
                  data->AttributeId,
                  onSuccess,
                  onFailure);
    
          if (CHIP_NO_ERROR != ret) {
              ChipLogProgress(AppServer, "Invoke OnOff Command Request ERROR, %s ", ErrorStr(ret));
          }
    }

    Best

    Sigitas

    P.S. Still working on Linux Matter application which will receive sensors values from another node (device).

  • Hi  ,

    I'm very interested in your code snippet, if it works in your linux application.

    I read your previous code snippet and your methode SensorsWorkerHandler(). I wonder that there is no "destinationID" for requesting the attribute you want. How does this function know about the node from which the attribute should read from?

Related