diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m index baaafe1c157e14..57977c63e2a622 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m @@ -788,11 +788,22 @@ - (NSString *)getNetworkName:(NSNumber *)discriminator return peripheralFullName; } +- (void)_restartMatterStack +{ + NSLog(@"Shutting down the stack"); + [self.chipController shutdown]; + NSLog(@"Starting up the stack"); + [self.chipController startup:nil vendorId:0 nocSigner:nil]; +} + - (void)handleRendezVousDefault:(NSString *)payload { NSError * error; uint64_t deviceID = CHIPGetNextAvailableDeviceID(); + // restart the Matter Stack before pairing (for reliability + testing restarts) + [self _restartMatterStack]; + if ([self.chipController pairDevice:deviceID onboardingPayload:payload error:&error]) { deviceID++; CHIPSetNextAvailableDeviceID(deviceID);