[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 ,

    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?

  • Hi  

    Application first need to establish session with "CASESessionManager::FindOrEstablishSession" where you provide ScopedNodeId as a destination. Once device is connected, application can save session object.

    In above code snippet: 

    aDevice->GetSecureSession().Value(),

    it has information about destination node.

  • Hi  

    are you successful with your project?

    Can you read attributes from device A with a device B?

    Best regards,

    Benny

  •   

    I'm in this same situation wherein i need to get a stateValue of a subscribe event.

    Currently, i use chip-tool as below.

    ./chip-tool interactive start

    >> booleanstate subscribe state-value 1 1 120 1

    Also as standalone, 

    ./chip-tool booleanstate subscribe state-value 1 1 120 1

    My requirement is to capture the stateValue in my Linux machine(ubuntu) whenever the state changes its value.

    If i use the chip-tool in the interactive start mode, then I cannot get the value outside the chip tool.

    If I use the chp-tool in single command mode, once the tool exits, i can get the stateValue.

    So, looking forward for a solution that notifies me on this value change.

    The  use case is as below.

    I have a contact sensor. I need to capture the stateValue whenever it changes.

    I looked at the piece of code you posted above, but not sure how/where to implement that.

    Can you please help?

Related