Pairing with MatterSupport framework

In my RequestHandler.swift, this is extension of MatterAddDeviceExtensionRequestHandler After commission device is completion. I call getBaseDevice method in the MTRDeviceController.

func controller(_ controller: MTRDeviceController, commissioningComplete error: Error?, nodeID: NSNumber?) {
        if error != nil {
            os_log(.default, "TrinhVM: commissioningComplete error -> \(error!.localizedDescription)")
        } else {
            os_log(.default, "TrinhVM: commissioningComplete ->\(nodeID)")
            chipController.getBaseDevice(1, queue: DispatchQueue.main, completionHandler: { chipDevice, error in
                if chipDevice == nil {
                    os_log(.debug, "Status: Failed to establish a connection with the device")
                } else {
                    os_log(.error, "Status: Success to establish a connection with the device: \(chipDevice?.description ?? "")")
                    let onOff = MTRBaseClusterOnOff(device: chipDevice, endpointID: 1, queue: DispatchQueue.main)
                    // Send the "on" command to the device
                    onOff?.on { error in
                        let resultString: String
                        if let error = error {
                            resultString = String(format: "An error occurred: 0x%02lx", error._code)
                        } else {
                            resultString = "On command success"
                        }
                        debugPrint(resultString)
                    }
                }
            })
        }
}

It's working well, the status is always "Status: Success to establish a connection with the device". And I can control the lightbulb here with chipDevice (chipDevice is MTRBaseDevice).

But, after the commission device has finished in the extension, get back the application scheme. I call method:

chipController.getBaseDevice(1, queue: DispatchQueue.main, completionHandler: { chipDevice, error in
      if chipDevice == nil {
            os_log(.debug, "Status: Failed to establish a connection with the device")
      } else {
            os_log(.error, "Status: Success to establish a connection with the device: \(chipDevice?.description ?? "")")
            let onOff = MTRBaseClusterOnOff(device: chipDevice, endpointID: 1, queue: DispatchQueue.main)
            // Send the "on" command to the device
            onOff?.on { error in
                 let resultString: String
                 if let error = error {
                       resultString = String(format: "An error occurred: 0x%02lx", error._code)
                 } else {
                       resultString = "On command success"
                 }
                 debugPrint(resultString)
            }
     }
})

It's always show timeout error .

Mdns: Resolve failure (src/platform/Darwin/DnssdImpl.cpp:476: CHIP Error 0x00000074: The operation has been cancelled)
OperationalSessionSetup[1:0000000000000015]: operational discovery failed: src/lib/address_resolve/AddressResolve_DefaultImpl.cpp:119: CHIP Error 0x00000032: Timeout
Creating NSError from src/lib/address_resolve/AddressResolve_DefaultImpl.cpp:119: CHIP Error 0x00000032: Timeout (context: (null))
"Failed to establish a connection with the device Optional(Error Domain=MTRErrorDomain Code=9 \"Transaction timed out.\" UserInfo={NSLocalizedDescription=Transaction timed out.})"

I don't know why the same method, works in RequestHandler.swift but not in AppScheme.

Any support for this issue. Thank and best regards.

Answered by DTS Engineer in 791434022

How long did it take for you to get that error? Was it "immediate/fast" or did it take significant time (10+ seconds)?

This is a guess, but did you include the key NSLocalNetworkUsageDescription and NSBonjourServices in your main app? The error you're getting is coming from the bonjour resolver and those keys are required for apps that are accessing bonjour. NSLocalNetworkUsageDescription is the string the system will show the user to approve giving your app bonjour access, while NSBonjourServices is an array object that lists the bonjour services you'll be browsing for.

For matter, you'd need to list these three services:

_matter._tcp
_matterc._udp
_matterd._udp

This isn't necessary in the MatterService extension because the system implicitly grants them through the extension point.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

How long did it take for you to get that error? Was it "immediate/fast" or did it take significant time (10+ seconds)?

This is a guess, but did you include the key NSLocalNetworkUsageDescription and NSBonjourServices in your main app? The error you're getting is coming from the bonjour resolver and those keys are required for apps that are accessing bonjour. NSLocalNetworkUsageDescription is the string the system will show the user to approve giving your app bonjour access, while NSBonjourServices is an array object that lists the bonjour services you'll be browsing for.

For matter, you'd need to list these three services:

_matter._tcp
_matterc._udp
_matterd._udp

This isn't necessary in the MatterService extension because the system implicitly grants them through the extension point.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Pairing with MatterSupport framework
 
 
Q