0

We tried to read data for bluetooth devices to iphone. We flowed this
https://github.com/paulw11/BTBackground .We got devices name and devices uuid number and connection also Fine.But we failed to get data.Please guide to us

    -(void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
        self.connectedPeripheral=peripheral;
        NSLog(@"Connected to %@(%@)",peripheral.name,peripheral.identifier.UUIDString);
        peripheral.delegate=self;
        NSLog(@"DeviceInfoUUID %@",_deviceInfoUUID);

        [peripheral discoverServices:@[self.deviceInfoUUID]];
//we tried this also 
       // [peripheral discoverServices:nil];

    }
    #pragma mark - CBPeripheralManager delegate methods


    -(void) peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {

         NSLog(@"peripheral.services    %@",peripheral.services);
        for (CBService *service in peripheral.services) {
            NSLog(@"Discovered service %@",service.description);
            if ([service.UUID isEqual:self.deviceInfoUUID]) {

                [peripheral discoverCharacteristics:nil forService:service];
            }
        }

    }

Please guide to us What wrong in code.We are new this

konda
  • 51
  • 1
  • 6
  • Does peripheral has the service with UUID `self.deviceInfoUUID`? Does it advertise it? – Larme Oct 08 '15 at 13:02
  • @Larme when we print deviceinforUUID "Device Information" only – konda Oct 08 '15 at 13:05
  • @Larme we tried [peripheral discoverServices:nil]; also but no luck – konda Oct 08 '15 at 13:05
  • As @Larme says, what services is your device advertising? Have you tried the LightBlue Explorer app from the app store? – Paulw11 Oct 08 '15 at 21:22
  • @Paulw11 thanks for reply .really we don't know about what services is devices advertisings.Please tell me how to know about devices services devices advertising. we install LighBlue Explrer app we got devices name .When we click on devices We got error Message Connection alert DISMISS – konda Oct 09 '15 at 09:42
  • 1
    LightBlue Explorer is a good way of seeing what your device is advertising. If it can't connect then your device may have a problem – Paulw11 Oct 09 '15 at 09:45
  • @Paulw11 any other chances to solved my problem . We are work last 6 day but still we are not able to get data for Bluetooth device .Please guide to us – konda Oct 09 '15 at 10:08
  • As Paulw11 said, does LightBlue success to scan your peripheral? – Larme Oct 09 '15 at 10:16
  • @Larme LightBlue is show my bluetooth devices name but When we click on name it's showing one alert Connection Alert "periperal disconnected while being interrogated". – konda Oct 09 '15 at 10:18
  • On your code, is the delegate method didDisconnect called? – Larme Oct 09 '15 at 10:18
  • @Larme yes my code is called didDisconnectPeripheral – konda Oct 09 '15 at 10:31
  • What show the "error" parameter in that case? – Larme Oct 09 '15 at 10:33
  • @Larme Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo={NSLocalizedDescription=The specified device has disconnected from us.} – konda Oct 09 '15 at 10:41

1 Answers1

0

Have you scanned for peripheral with the services, code below:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
    [self.bluetoothManager scanForPeripheralsWithServices:nil options:options];
Lei Zhang
  • 634
  • 4
  • 6