Skip to content

bluetooth: add rssi property #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bbedward
Copy link

Add rssi to bluetooth property bindings. It's useful to see signal strength of devices during discovery (IE, for sorting by signal strength, ignoring very low signal strength devices)

Because rssi is not available when the adapter is no longer discovering I also added a condition to lower the log level on the property update callback for optional properties, it's not really necessary and can be removed - but prevents some log spam when turning off discovery (because the rssi properties become unavailable)

Comment on lines 58 to 76
qint32 BluetoothDevice::signalStrength() const {
// Convert RSSI (dBm) to a normalized 0-100 scale
// Based on practical Bluetooth RSSI ranges:
// -30 to -40 dBm = 85-100
// -40 to -55 dBm = 65-85
// -55 to -65 dBm = 45-65
// -65 to -75 dBm = 25-45
// -75 to -85 dBm = 10-25
// <= -85 dBm = 0-10

auto rssiValue = this->bRssi.value();
if (rssiValue == 0) {
return 0;
}

auto rssi = std::max(static_cast<qint16>(-100), std::min(static_cast<qint16>(-30), rssiValue));
auto normalized = static_cast<qint32>(((rssi + 100) / 70.0) * 100.0);

return std::max(0, std::min(100, normalized));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dBm is not linear

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh I'm not sure if this should be linear or not. It requires actual testing at various distances to make sure the number is useful

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted it, there's no good singular mathematical function I could find to get it as a good representation for display purposes - but I think the numbers are pretty good now.

dBm normalized
-30 100
-35 96
-40 92
-45 88
-50 83
-55 79
-60 75
-65 59
-70 42
-75 26
-80 9
-85 5
-90 0

Pretty much anything > -67 is a good signal, anything -80 or below is usually un-usable. 0 is driver reporting no signal data is available for the device (so treating it as effectively 0 normalized)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants