ios - Refreshing RSSI value of many bluetooth peripherals -
i'm trying mesure rssi indicator on ios (6 ble) several bluetooth peripheral. can rssi scanforperipheral :
nsdictionary *options = [nsdictionary dictionarywithobjectsandkeys:[nsnumber numberwithbool:yes], cbcentralmanagerscanoptionallowduplicateskey, nil]; [_manager scanforperipheralswithservices:nil options:options];
coupled with:
- (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral:(cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi {
this works have no control on rate of packets receive , result seems uncertain.
i've read : https://stackoverflow.com/a/12486927/270209 rate not close 100ms @ (more 1~2 seconds)
if i'm connected device result readrssi seems more reliable.
i'm looking way "stimulate" peripherals more frequents updates in scan mode or way connect more 1 peripheral @ time.
thanks
edit : i've tried start / stop scan quickly, seems @ start scan detects more devices , updates more frequent
i'm sure you've figured out in case comes across (like did) looking other info, if you're not using other ios devices corelocation need call peripheraldidupdaterssi:
delegate using [self.myperipheral readrssi];
.
you can call rssi data updates in didupdatevalueforcharacteristic:
once in updatevalue delegate.
you don't need in viewdidload: nsdictionary *options = etc...
nsdictionary created in diddiscoverperipheral:
delegate.
so overall flow be:
check receiving rssi in nslog obtained rssi data...
- (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral:(cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi{ nsstring *localname = [advertisementdata objectforkey:cbadvertisementdatalocalnamekey]; if ([localname length] > 0){ nslog(@"discovered: %@ rssi: %@", peripheral.name, rssi); // other needs ... }
call peripheraldidupdaterssi:
here since updates occur continuously if you've set notify value yes [peripheral setnotifyvalue:yes forcharacteristic:characteristic];
- (void) peripheral:(cbperipheral *)peripheral didupdatevalueforcharacteristic:(cbcharacteristic *)characteristic error:(nserror *)error{ //call peripheraldidupdaterssi delegate .. [self.myperipheral readrssi]; // of other characteristic value updates here }
readrssi
call delegate perform rssi updates on uilabel (or whatever you're using) every time update previous characteristics values:
- (void)peripheraldidupdaterssi:(cbperipheral *)peripheral error:(nserror *)error; { _rssilabel.text = [self.myperipheral.rssi stringvalue]; nslog(@"rssi method”); }
if don't need characteristic values app run loop in there whatever timing need rssi value refresh.
Comments
Post a Comment