From 45e65686a08b689151278cbfbcd36daa233ac59d Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 12 Jun 2024 11:17:27 +0200 Subject: [PATCH] Avoid errors when using on-network commissioning When on network commissioning is used from Python we currently don't stop discovery even though we already found a device. Future devices found won't be processed, so it is fine to stop discovery of commissionable nodes at this point. Also avoid "Unknown filter type; all matches will fail" errors in the log: If the filter type is set to None, it wasn't the SetUpCodePairer which set up the discovery. Avoid printing errors in this case. A potential alternative to this would be to skip notifying the SetUpCodePairer in DeviceCommissioner::OnNodeDiscovered in this case. --- src/controller/SetUpCodePairer.cpp | 3 +++ ...ipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 8ebf78a3fc545e..17f2e5945eb1bf 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -377,6 +377,9 @@ bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & case Dnssd::DiscoveryFilterType::kLongDiscriminator: discriminatorMatches = (nodeData.longDiscriminator == mCurrentFilter.code); break; + case Dnssd::DiscoveryFilterType::kNone: + ChipLogDetail(Controller, "Filter type none; all matches will fail"); + return false; default: ChipLogError(Controller, "Unknown filter type; all matches will fail"); return false; diff --git a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp index 56b4932e9a8988..add4428c36a183 100644 --- a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp @@ -32,6 +32,9 @@ void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::Commi nodeData.ipAddress[0].ToString(buf); ChipLogProgress(chipTool, "Discovered Device: %s:%u", buf, port); + // Stop active discovery. + mActiveDeviceCommissioner->StopCommissionableDiscovery(); + // Cancel discovery timer. chip::DeviceLayer::SystemLayer().CancelTimer(OnDiscoveredTimeout, this);