mongoose-os-libs / wifi

Other
13 stars 29 forks source link

add mgos_wifi_sta_get_signal_strength from rssi value #14

Open tripflex opened 6 years ago

tripflex commented 6 years ago

Most end users will have no idea how to convert RSSI (or even just understand the values), so I added a method, mgos_wifi_sta_get_signal_strength which will convert from RSSI value, to a percentage value, out of 100

cpq commented 6 years ago

Could you elaborate on the formula you're using - where does it come from? Is it some sort of a standard? Does the same logic apply to BLE RSSI?

tripflex commented 6 years ago

@cpq I ported it from another library I was using prior to mos, but it's relatively easy to calculate a general value that works for most RSSI values returned ... I actually have numerous wifi certifications (used to work for govt contractor installing wireless networks for cities and other govt agencies)...

general rule of thumb was the range for RSSI would be -50 to -100, with -100 being the worst (no signal) and anything >= -50 being the best possible (very rarely seen anything above -50, but it is possible up to 0 -- i've never personally seen 0), but that's also all dependent on the actual radio chip manufacturer, as they set the "max" RSSI level themselves when calculating the value and returning it as "RSSI" that we are given, which would actually be calculated dBm not the actual RSSI value ... but it's still reported as "RSSI"

RSSI (Received Signal Strength Indicator) is a common measurement, but most WiFi adapter vendors handle it differently, as it isn't standardized.

Now this can vary based on the actual chip manufacturer of course, and there is a lot more that goes into this, but in a general sense, this is the same calc used in a lot of other libs, as you can see here: https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp#L772

https://github.com/marvinroger/homie-esp8266/blob/ad876b2cd0aaddc7bc30f1c76bfc22cd815730d9/src/Homie/Utils/Helpers.cpp#L12

Microsoft defines Wifi signal quality in their WLAN_ASSOCIATION_ATTRIBUTES structure as follows:

wlanSignalQuality:

A percentage value that represents the signal quality of the network. WLAN_SIGNAL_QUALITY is of type ULONG. This member contains a value between 0 and 100. A value of 0 implies an actual RSSI signal strength of -100 dbm. A value of 100 implies an actual RSSI signal strength of -50 dbm. You can calculate the RSSI signal strength value for wlanSignalQuality values between 1 and 99 using linear interpolation.

see: https://stackoverflow.com/questions/15797920/how-to-convert-wifi-signal-strength-from-quality-percent-to-rssi-dbm

https://www.speedguide.net/faq/how-does-rssi-dbm-relate-to-signal-quality-percent-439

https://www.researchgate.net/file.PostFileLoader.html?id=55df0dd85cd9e3ee388b45d7&assetKey=AS:273840230338570@1442300006396