0

I have a BLE device (obd2 dongle) that I want to connect to. I can pair with it through "settings" but I can't discover it via didDiscoverPeripheral delegate method , any help ?

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    _centralManager =[[CBCentralManager alloc]initWithDelegate:self queue:nil]; 
    [self scan]; 
}

-(void)scan { 

    NSDictionary *options1 =@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }; 
    [_centralManager scanForPeripheralsWithServices:nil options:options1]; 
}

-(void)centralManagerDidUpdateState:(CBCentralManager *)central{ 
    if (central.state == CBCentralManagerStatePoweredOn) { 
        [self scan]; 
    } 
}

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI {

    [peripheral readRSSI];

    [central connectPeripheral:peripheral options:nil];

}

-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { 
    CBPeripheral *peripheral1 =peripheral; 
    NSLog(@"peripheral1 name = %@",peripheral1.name); peripheral.delegate=self; 
    [peripheral discoverServices:nil]; 
}
Paulw11
  • 108,386
  • 14
  • 159
  • 186
Skander Fathallah
  • 503
  • 1
  • 5
  • 10
  • 1
    Is it a Bluetooth Low Energy Device? Can you discover it with the Light Blue App? Can you show more code? Specifically, how you initiate discovery – Paulw11 Aug 17 '16 at 20:32
  • Yes , my peripheral is BLE. The weird thing that i could pair my app through "settings" but i can't find it with Blue Light. This is the rest of the code - (void)viewDidLoad { [super viewDidLoad]; _centralManager =[[CBCentralManager alloc]initWithDelegate:self queue:nil]; [self scan]; } -(void)scan{ CBCentralManagerScanOptionAllowDuplicatesKey, nil]; NSDictionary *options1 =@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }; [_centralManager scanForPeripheralsWithServices:nil options:options1]; NSLog(@"started scanning"); } – Skander Fathallah Aug 18 '16 at 08:35
  • -(void)centralManagerDidUpdateState:(CBCentralManager *)central{ if (central.state == CBCentralManagerStatePoweredOn) { [self scan]; } } – Skander Fathallah Aug 18 '16 at 08:38
  • -(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{ CBPeripheral *peripheral1 =peripheral; NSLog(@"peripheral1 name = %@",peripheral1.name); peripheral.delegate=self; [peripheral discoverServices:nil]; } – Skander Fathallah Aug 18 '16 at 08:39
  • Please edit your question to include the code so that it can be formatted properly. If LightBlue can't find your peripheral then there is a very good chance that it is not advertising a BLE service – Paulw11 Aug 18 '16 at 08:43
  • `- (void)viewDidLoad { [super viewDidLoad]; _centralManager =[[CBCentralManager alloc]initWithDelegate:self queue:nil]; [self scan]; } -(void)scan{ CBCentralManagerScanOptionAllowDuplicatesKey, nil]; NSDictionary *options1 =@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }; [_centralManager scanForPeripheralsWithServices:nil options:options1]; } ` – Skander Fathallah Aug 18 '16 at 08:55
  • `-(void)centralManagerDidUpdateState:(CBCentralManager *)central{ if (central.state == CBCentralManagerStatePoweredOn) { [self scan]; } }` – Skander Fathallah Aug 18 '16 at 08:56
  • `-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{ CBPeripheral *peripheral1 =peripheral; NSLog(@"peripheral1 name = %@",peripheral1.name); peripheral.delegate=self; [peripheral discoverServices:nil]; } ` – Skander Fathallah Aug 18 '16 at 08:58
  • @Paulw11, code formatted, thanks in advance – Skander Fathallah Aug 18 '16 at 09:49
  • No, you can edit your question and add the code; there is an "edit" link below the question – Paulw11 Aug 18 '16 at 10:17
  • So you don't get a call to `didDiscoverPeripheral` at all? Your code look OK. The only issue I can see is that you don't store the peripheral you have discovered/connected to in a property, so a strong reference won't be held and the connection won't go ahead, but if you aren't getting a call to `didDiscoverPeripheral` then you aren't getting that far. As I said, if LightBlue can't see the peripheral then it is quite possible that it is legacy Bluetooth and not BLE. Do you have a link to the OBD dongle you are using? – Paulw11 Aug 18 '16 at 10:23
  • I have already tried storing my peripheral into a strong property, but still nothing. Here 's the link to mu Bluetooth dongle (last device) http://www.continental-automotive.com/www/automotive_de_en/themes/commercial_vehicles/tolling_telematic_solutions/telematics_en.html – Skander Fathallah Aug 18 '16 at 10:43
  • 2
    Hmm. Not much information there. Based on what you are seeing; LightBlue can't find it and you can pair it from settings, it sounds like a legacy Bluetooth device to me – Paulw11 Aug 18 '16 at 11:36
  • @Paulw11, much obliged. – Skander Fathallah Aug 18 '16 at 14:06
  • Just one more question @Paulw11, i have an android device that supports BLE but i can't detect it with Light Blue, could this app discover android peripherals ? – Skander Fathallah Aug 18 '16 at 15:27
  • You need to be running an app that advertises a service on the Android phone for there to be a thing to discover. – Paulw11 Aug 18 '16 at 20:33

0 Answers0