Post

Replies

Boosts

Views

Activity

Using MatterSupport framework to add Matter device to our system
1, I add an Matter extension named TRMatterExtension, using the Template in Xcode. 2, check the InfoPlist with the TRMatterExtension module, I see the NSExtension key with two key which are like this: 3,The RequestHandler.swift file is like this: import os import MatterSupport let logger = Logger(subsystem: "com.airdroitech.commissionMtr2", category: "MatterExtension") // The extension is launched in response to MatterAddDeviceRequest.perform() and this class is the entry point // for the extension operations. class RequestHandler: MatterAddDeviceExtensionRequestHandler { override init() { logger.log("QAWI3 - init") super.init() } override func validateDeviceCredential(_ deviceCredential: MatterAddDeviceExtensionRequestHandler.DeviceCredential) async throws { // Use this function to perform additional attestation checks if that is useful for your ecosystem. logger.log("QAWI3 - validateDeviceCredential") } override func selectWiFiNetwork(from wifiScanResults: [MatterAddDeviceExtensionRequestHandler.WiFiScanResult]) async throws -> MatterAddDeviceExtensionRequestHandler.WiFiNetworkAssociation { // Use this function to select a Wi-Fi network for the device if your ecosystem has special requirements. // Or, return `.defaultSystemNetwork` to use the iOS device's current network. logger.log("QAWI3 - Returning default system network") return .defaultSystemNetwork } override func selectThreadNetwork(from threadScanResults: [MatterAddDeviceExtensionRequestHandler.ThreadScanResult]) async throws -> MatterAddDeviceExtensionRequestHandler.ThreadNetworkAssociation { // Use this function to select a Thread network for the device if your ecosystem has special requirements. // Or, return `.defaultSystemNetwork` to use the default Thread network. return .defaultSystemNetwork } override func commissionDevice(in home: MatterAddDeviceRequest.Home?, onboardingPayload: String, commissioningID: UUID) async throws { // Use this function to commission the device with your Matter stack. logger.log("QAWI3 - Starting commissioning flow") } override func rooms(in home: MatterAddDeviceRequest.Home?) async -> [MatterAddDeviceRequest.Room] { // Use this function to return the rooms your ecosystem manages. // If your ecosystem manages multiple homes, ensure you are returning rooms that belong to the provided home. return [.init(displayName: "Living Room")] } override func configureDevice(named name: String, in room: MatterAddDeviceRequest.Room?) async { // Use this function to configure the (now) commissioned device with the given name and room. } } 4, I add Privacy - Local Network Usage Description and Bonjour services [ _matter._tcp _matterc._udp _matterd._udp ] to the main target's InfoPlist. 5, click a button to call MatterAddDeviceRequest.perform(), the code is as the following: let homes = [MatterAddDeviceRequest.Home(displayName: "TRHome")] let topology = MatterAddDeviceRequest.Topology(ecosystemName: "TR", homes: homes) let request = MatterAddDeviceRequest(topology: topology) do { try await request.perform() print("Successfully set up device!") } catch { print("Failed to set up device with error: (error)") } 6, Result: Most times, Matter devices can be added to the KeyChain and the commission window of the Matter device could be opened. But sometimes the MatterSupport window will show "Pairing Failed". The total error is: [1E1D8753] Failed to perform Matter device setup setup: Error Domain=HMErrorDomain Code=18 "Pairing Failed" UserInfo={HFErrorUserInfoOptionsKey={ HFErrorUserInfoOptionDescriptionKey = "Pairing Failed"; HFErrorUserInfoOptionTitleKey = "\U65e0\U6cd5\U6dfb\U52a0\U914d\U4ef6"; }, NSLocalizedDescription=Pairing Failed, NSUnderlyingError=0x3009e8240 {Error Domain=HAPErrorDomain Code=15 "Failed to pair Matter Accessory in time" UserInfo={NSLocalizedDescription=Failed to pair Matter Accessory in time, NSUnderlyingError=0x3009e86c0 {Error Domain=HAPErrorDomain Code=24 "(null)"}}}}. From the log I can see, the Function selectWiFiNetwork(from wifiScanResults: [MatterAddDeviceExtensionRequestHandler.WiFiScanResult]) async throws -> MatterAddDeviceExtensionRequestHandler.WiFiNetworkAssociation of the RequestHandler.swift file will be called and commissionDevice(in home: MatterAddDeviceRequest.Home?, onboardingPayload: String, commissioningID: UUID) will NOT called. Sometimes the RequestHandler class will not be called at all, this means the first function validateDeviceCredential will not be called. But ,when this happens, the iPhone will Continuously can NOT add device for a long time, sometimes it gets better inexplicably. Even under normal circumstances, the probability of successfully adding a device is less than 50% and very slowly. When using Apple Home app, the success rate is very high, almost 100%, and very fast. So, can you help me identify where the problem is and what areas need attention? Thank you very much! Finally, I often encounter logs like this: nw_browser_dns_service_browse_callback [B3] not in ready or waiting state Do you know what it means and whether it will affect the equipment distribution network? My testing machine is iPhone 12, operating on iOS 18 and above 17.0. Thank you very much!
3
0
323
Sep ’24