Bluetooth RSSI calculation distance

Source: Internet
Author: User

Using Corelocation.framework is easy to scan to get peripheral Bluetooth devices, Apple open source code airlocate has a specific implementation:

Https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html

The obtained ibeacon is expressed in Clbeacon in Corelocation, which has the RSSI value (Received signal strength), which can be used to calculate the distance between the transmitting end and the receiving end.


Calculation formula:

D = 10^ ((ABS (RSSI)-A)/(Ten * N))

which

D-Calculate the resulting distance

RSSI-received signal strength (negative value)

A-Signal strength at a distance of 1 m from the transmitting and receiving ends

N-Environmental attenuation factor



Code implementation of the calculation formula

-(float) Calcdistbyrssi: (int) rssi{    int irssi = ABS (RSSI);    Float power = (iRssi-59)/(10*2.0);    Return pow (power);}

The Rssi value is passed in, and the distance (in meters) is returned. Where a parameter is assigned a 59,N 2.0.

Due to the different environment, each transmitter source (Bluetooth device) corresponding parameter values are not the same. According to the truth, each parameter in the formula should be tested (calibrated).

When you do not know the exact location of the surrounding Bluetooth devices, you can only give experience values for a and n (as in this example).


Modify Airlocate aplrangingviewcontroller.m Display part of the code, the output calculation distance

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static NSString *identifier = @ "Cell";        UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:identifier];    Display the UUID, major, minor and accuracy for each beacon.    NSNumber *sectionkey = [Self.beacons allkeys][indexpath.section];    Clbeacon *beacon = Self.beacons[sectionkey][indexpath.row]; Cell.textLabel.text = [Beacon.proximityuuid uuidstring];//NSLog (@ "%@", [Beacon.proximityuuid uuidstring]);//Nsstri  ng *formatstring = nslocalizedstring (@ "Major:%@, Minor:%@, Acc:%.2FM, Rssi:%d, Dis:%.2f", @ "Format string for ranging Table cells. "); /Cell.detailTextLabel.text = [NSString stringwithformat:formatstring, Beacon.major, Beacon.minor, beacon.accuracy, be    Acon.rssi, [self calcDistByRSSI:beacon.rssi]]; NSString *formatstring = nslocalizedstring (@ "ACC:%.2fm, Rssi:%d, Dis:%.2fm", @ "Format string for ranging table cells."    ); Cell.detailtExtlabel.text = [NSString stringwithformat:formatstring, Beacon.accuracy, Beacon.rssi, [self CalcDistByRSSI:        Beacon.rssi]]; return cell;}

Scan results


Shows the ACC (precision), Rssi (signal strength), and dis (distance) for each Bluetooth device.

Bluetooth RSSI calculation distance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.