ReadRSSI does not call a delegate method

I had a problem since the iOS 8 update, right now my application is connected to the BLE device and periodically reads RSSI thanks to the timer and ReadRSSI method.

The ReadRSSI method is ReadRSSI (checked with a breakpoint), so up to this point everything is in order.

According to the documentation calling ReadRSSI , you need to call a callback

 - (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error 

However, this delegate method is not called every time. But when I turn off the bluetooth phone and again, I return RSSI updates. Has anyone already encountered this problem? How can i fix this?

+8
ios ios8 bluetooth bluetooth-lowenergy core-bluetooth
source share
3 answers

I had the same problem, at first I thought that it could be my mistake, but later it will turn out to be really strange.

I wrote a similar program using the iPhone to connect to the BLE beacon and using [CBPeripheral readRSSI] to get the signal strength. Everything goes smoothly when the BLE beacon is connected to my iPhone for the first time. But if it disconnects and reconnects, the readRSSI method will no longer be called. Only after restarting Bluetooth on my iPhone will the problem be resolved.

I run the program in debug mode, step by step, to my surprise, I did not find a problem at all. Even I disconnect so many times and reconnect, the readRSSI method can still be called correctly.

Hope this helps. I am also waiting for an answer to this strange thing.

+4
source share

I recently ran into this problem, and I had several problems that caused it. Here are the solutions on the checklist, from the simplest to the most complex:

  • CBCentralManager will not contain links to peripheral , you need to save it yourself.
  • Make sure that you are truly peripheral.delegate .
  • Make sure you use the new peripheral(peripheral:didReadRSSI:error:) method peripheral(peripheral:didReadRSSI:error:) , and not the old one.
  • In iOS 8.0.2, there were problems with the above method, any version after that 8.1, 8.2, 8.3 works without problems (as @Gamma Point spoke about).
  • You can only use readRSSI for devices connected to your central, so:
    • For devices that are removed by discovery, you can pass [CBCentralManagerScanOptionAllowDuplicatesKey : true] when you run scanForPeripheralsWithServices(_:options:) . As seen in this answer .
    • In addition, there is a getcha with the central.retrieveConnectedPeripheralsWithServices method. this method returns “connected” devices, but readRSSI or service discovery works until you actually call connectPeripheral(_:options:) on them, so even if they are connected to the iPhone / iPad / AppleWatch, they don’t connected to your central annoying.

This last one was big for me, I was hoping to “select the closest” connected or detected device, but could not save the updated RSSI. The documentation says nothing.

What I ended up with was creating a large dictionary with all the devices indexed by [UUID : Device] (the device is a wrapper for CBPeripheral ). Devices added through discovery receive their RSSIs that are updated using the discovery method and connected via a GCD timer in the Bluetooth queue, which calls readRSSI and updates its own RSSI read.

+2
source share

I have 8.0, it works fine.

 -(void) startScanForRSSI{ timerRSSI = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(detectRSSI) userInfo:nil repeats:YES]; } - (void)detectRSSI { if (state == ...) { peripheral.delegate = self; [peripheral readRSSI]; } else { if (timerRSSI && [timerRSSI isValid]) { [timerRSSI invalidate]; } } } - (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error { NSLog(@"Got RSSI update: %4.1f", [peripheral.RSSI doubleValue]); NSNumber *rssiNum = peripheral.RSSI; } 

Since the above is deprecated in iOS 8, having tried another delegate, it will report.

 -(void) peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error { NSLog(@"Got RSSI update in didReadRSSI : %4.1f", [RSSI doubleValue]); } 

This seems to be the OSX delegate method. Apple is likely to add something in iOS for RSSI soon.

On iOS 8.0, didReadRSSI works. In the documentation 8.0.2 it is not listed in iOS.

If I put both methods, then didReadRSSI will be called in iOS 8, and the peripheral DidUpdateRSSI will be called in iOS 7.

Therefore, do not update iOS 8.0.2 until Apple places something in the RSSI.

Has anyone tried the beta version of iOS 8.1?

It seems that when scanning devices, RSSI cannot be read. If a call to [CBCentralManager scanForPeripheralsWithServices ...] has been initiated, the ReadRSSI effect does not occur (delegates are not called). But if [CBCentralManager stopScan] is issued, ReadRSSI starts to respond.

Also note: the device must be in a connected state for issuing commands, otherwise you will receive: CoreBluetooth [API MISUSE] CBPeripheral can receive commands only in a connected state.

+1
source share

All Articles