How to convert Wifi signal strength from Quality (

2019-01-16 10:09发布

How should I convert Wifi signal strength from a Quality in percentage, usually 0% to 100% into an RSSI value, usually a negative dBm number (i.e. -96db)?

标签: wifi
10条回答
forever°为你锁心
2楼-- · 2019-01-16 10:50

Mentioned pseudocode will not work all the ranges, the ranges example (-80dBm to 0, and -40dBm to 100).

Generic simple logic to map any range to 0 to 100. Usage example, for below code ConvertRangeToPercentage(-80,-40,-50)

int ConvertRangeToPercentage (int a_value_map_to_zero, int a_value_map_to_100, int a_value_to_convert)
{

   int percentage = 0;

   if (a_value_map_to_zero < a_value_map_to_100)
   {
      if (a_value_to_convert <= a_value_map_to_zero)
      {
         percentage = 0;
      }
      else if (a_value_to_convert >= a_value_map_to_100)
      {
         percentage = 100;
      }
      else
      {
         percentage = (a_value_to_convert - a_value_map_to_zero) * 100 / (a_value_map_to_100 - a_value_map_to_zero);
      }
   }
   else if (a_value_map_to_zero > a_value_map_to_100)
   {
      if (a_value_to_convert >= a_value_map_to_zero)
      {
         percentage = 0;
      }
      else if (a_value_to_convert <= a_value_map_to_100)
      {
         percentage = 100;
      }
      else
      {
         percentage = (a_value_to_convert - a_value_map_to_zero) * 100 / (a_value_map_to_100 - a_value_map_to_zero);
      }
   }
   else
   {
      percentage = 0;
   }

   return percentage;
}
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-16 10:52

In JS I prefer doing something like:

Math.min(Math.max(2 * (x + 100), 0), 100)

My personal opinion is that it's more elegant way to write it, instead of using if's.

查看更多
来,给爷笑一个
4楼-- · 2019-01-16 10:55

From experience:

  1. Less than -50dB (-40, -30 and -20) = 100% of signal strength
  2. From -51 to -55dB= 90%
  3. From -56 to -62dB=80%
  4. From -63 to -65dB=75%

    The below is not good enough for Apple devices

  5. From -66 to 68dB=70%
  6. From -69 to 74dB= 60%
  7. From -75 to 79dB= 50%
  8. From -80 to -83dB=30%
    Windows laptops can work fine on -80dB however with slower speeds

查看更多
再贱就再见
5楼-- · 2019-01-16 10:56

Wifi Signal Strength Percentage to RSSI dBm

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.

RSSI (or "Radio (Received) Signal Strength Indicator") are in units of 'dB' (decibel) or the similar 'dBm' (dB per milliwatt) (See dB vs. dBm) in which the smaller magnitude negative numbers have the highest signal strength, or quality.


Therefore, the conversion between quality (percentage) and dBm is as follows:

    quality = 2 * (dBm + 100)  where dBm: [-100 to -50]

    dBm = (quality / 2) - 100  where quality: [0 to 100]

Pseudo Code (with example clamping):

    // dBm to Quality:
    if(dBm <= -100)
        quality = 0;
    else if(dBm >= -50)
        quality = 100;
    else
        quality = 2 * (dBm + 100);

    // Quality to dBm:
    if(quality <= 0)
        dBm = -100;
    else if(quality >= 100)
        dBm = -50;
    else
        dBm = (quality / 2) - 100;

Note:

Check the definition of Quality that you are using for your calculations carefully. Also check the range of dB (or dBm). The limits may vary.

Examples:

Medium quality:   50%      ->   -75dBm   = (50 / 2) - 100
Low quality:      -96dBm   ->   8%       = 2 * (-96 + 100)
查看更多
Juvenile、少年°
6楼-- · 2019-01-16 10:58

Ok.. I agree...but why is then:

 Quality=29/100  Signal level=-78 dBm
 Quality=89/100  Signal level=-55 dBm
 Quality=100/100 Signal level=-21 dBm

this does not agree with the formula percentage=quality/2 - 100.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-16 11:00

Also, you can try inverse this Bash function which converts dBm to percentage:

#!/bin/bash

function dbmtoperc { # Convert dBm to percentage (based on https://www.adriangranados.com/blog/dbm-to-percent-conversion)
  dbmtoperc_d=$(echo "$1" | tr -d -)
  dbmtoperc_r=0
  if [[ "$dbmtoperc_d" =~ [0-9]+$ ]]; then
    if ((1<=$dbmtoperc_d && $dbmtoperc_d<=20)); then dbmtoperc_r=100
    elif ((21<=$dbmtoperc_d && $dbmtoperc_d<=23)); then dbmtoperc_r=99
    elif ((24<=$dbmtoperc_d && $dbmtoperc_d<=26)); then dbmtoperc_r=98
    elif ((27<=$dbmtoperc_d && $dbmtoperc_d<=28)); then dbmtoperc_r=97
    elif ((29<=$dbmtoperc_d && $dbmtoperc_d<=30)); then dbmtoperc_r=96
    elif ((31<=$dbmtoperc_d && $dbmtoperc_d<=32)); then dbmtoperc_r=95
    elif ((33==$dbmtoperc_d)); then dbmtoperc_r=94
    elif ((34<=$dbmtoperc_d && $dbmtoperc_d<=35)); then dbmtoperc_r=93
    elif ((36<=$dbmtoperc_d && $dbmtoperc_d<=38)); then dbmtoperc_r=$((92-($dbmtoperc_d-36)))
    elif ((39<=$dbmtoperc_d && $dbmtoperc_d<=51)); then dbmtoperc_r=$((90-($dbmtoperc_d-39)))
    elif ((52<=$dbmtoperc_d && $dbmtoperc_d<=55)); then dbmtoperc_r=$((76-($dbmtoperc_d-52)))
    elif ((56<=$dbmtoperc_d && $dbmtoperc_d<=58)); then dbmtoperc_r=$((71-($dbmtoperc_d-56)))
    elif ((59<=$dbmtoperc_d && $dbmtoperc_d<=60)); then dbmtoperc_r=$((67-($dbmtoperc_d-59)))
    elif ((61<=$dbmtoperc_d && $dbmtoperc_d<=62)); then dbmtoperc_r=$((64-($dbmtoperc_d-61)))
    elif ((63<=$dbmtoperc_d && $dbmtoperc_d<=64)); then dbmtoperc_r=$((61-($dbmtoperc_d-63)))
    elif ((65==$dbmtoperc_d)); then dbmtoperc_r=58
    elif ((66<=$dbmtoperc_d && $dbmtoperc_d<=67)); then dbmtoperc_r=$((56-($dbmtoperc_d-66)))
    elif ((68==$dbmtoperc_d)); then dbmtoperc_r=53
    elif ((69==$dbmtoperc_d)); then dbmtoperc_r=51
    elif ((70<=$dbmtoperc_d && $dbmtoperc_d<=85)); then dbmtoperc_r=$((50-($dbmtoperc_d-70)*2))
    elif ((86<=$dbmtoperc_d && $dbmtoperc_d<=88)); then dbmtoperc_r=$((17-($dbmtoperc_d-86)*2))
    elif ((89<=$dbmtoperc_d && $dbmtoperc_d<=91)); then dbmtoperc_r=$((10-($dbmtoperc_d-89)*2))
    elif ((92==$dbmtoperc_d)); then dbmtoperc_r=3
    elif ((93<=$dbmtoperc_d)); then dbmtoperc_r=1; fi
  fi
  echo $dbmtoperc_r
}

Usage:

echo $(dbmtoperc -48)% # returns 81%
查看更多
登录 后发表回答