unable to connect to some devices but not others
- (IBAction)connectToDevices:(id)sender {
NSArray *indexPathArray = [_selectDevicesTable indexPathsForSelectedRows];
NSMutableArray *selectedDeviceIdentifiers = [[NSMutableArray alloc] init];
[connectedDevices removeAllObjects];
// Get the devices that have been selected for connection.
NSLog(@Devices selected for connection are at following rows:);
for (NSIndexPath *i in indexPathArray) {
NSLog(@%d,(int)i.row);
[selectedDeviceIdentifiers addObject: [deviceIdentifiers objectAtIndex:i.row]];
}
// Only connected to selected devices.
[manager retrieveSavedMetaWearsWithHandler:^(NSArray *array) {
for (MBLMetaWear *currdevice in array) {
// Connect to the device first.
// connectWithTimeout:handler: is a simple way to limit the amount of
// time spent searching for the device
if ([selectedDeviceIdentifiers containsObject:currdevice.name]) {
[currdevice connectWithTimeout:20 handler:^(NSError *error) {
if ([error.domain isEqualToString:kMBLErrorDomain] &&
error.code == kMBLErrorConnectionTimeout) {
[currdevice forgetDevice];
NSLog(@Connection Timeout);
}
else {
NSLog(@Connection succeeded with %@.",currdevice.name);
[currdevice.led flashLEDColorAsync:[UIColor greenColor] withIntensity:1.0 numberOfFlashes:2];
[connectedDevices addObject:currdevice.name];
}
}];
}//endif
}
}];
}
Comments
- (IBAction)startSearch:(id)sender {
[self disable_button:_connectDevicesButton];
[self disable_button:_refreshListButton];
//Search for devices excluding duplicates.
//NOTE: Might be a good idea to exclude ones with weak signals.
[manager startScanForMetaWearsAllowDuplicates:NO handler:^(NSArray *listOfDevices) {
int i=0;
for (MBLMetaWear *foundDevice in listOfDevices) {
if ([deviceIdentifiers indexOfObject:foundDevice.name]==NSNotFound) {
[foundDevice rememberDevice];
[deviceIdentifiers addObject: foundDevice.name];
i++;
}
[self enable_button:_connectDevicesButton];
[self enable_button:_refreshListButton];
}
// List found metaWears.
NSLog(@MetaWears found:);
NSLog(@%@",[deviceIdentifiers componentsJoinedByString:@\n]);
[_selectDevicesTable reloadData];
}];
}
The devices that "don't respond" actually are discoverable but I get a connection timeout when I try to connect to them. This doesn't happen with all the other devices I'm trying to connect to.