Why there's a requirement of reconnecting to a BLE device every time?

48 views Asked by At

I have a CBPeripheral which accepting different commands for communications.

For example:

  1. If I need to fetch current rate from the device, the command is "get-rate".

  2. If I need to fetch current battery level of the device, the command is "battery".

So If I execute individual command, it works fine. Giving me proper response. But after each commands execution, I need to reconnect (disconnect & then connect again) before executing another command. If I will not do that then, it will always returning the value of lastly executed command.

I am NOT sure if this is the right way to do?

Let me know if you need more information from me.

This doesn't help:

@property (nonatomic, strong) CBPeripheral *currentPeripheral;

        NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:k_UUID];
        NSArray *peripherals = [self.btManager retrievePeripheralsWithIdentifiers:@[uuid]];
        if(peripherals.count) {
            self.currentPeripheral = [peripherals firstObject];
            [self.btManager connectPeripheral:self.currentPeripheral options:nil];
        }
0

There are 0 answers