How to convert Wifi signal strength from Quality (percent) to RSSI (dBm)?

后端 未结 11 943
故里飘歌
故里飘歌 2020-12-04 12:42

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)?

11条回答
  •  情深已故
    2020-12-04 13:25

    Im glad I found this post cause I was looking for a way to convert the dbm to percentage. Using David's post, I wrote up a quick script in python to calculate the quality percentage.

    #!/usr/bin/env python3
    import os
    import platform
    
    system = platform.system()
    if system == 'Linux':
        cmd = "iwconfig wlan0 | grep Signal | /usr/bin/awk '{print $4}' | /usr/bin/cut -d'=' -f2"
    elif system == 'Darwin':
        cmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI | awk '{ print $NF; }"
    else:
        print("Unsupported os: {}".format(system))
    
    dbm = os.popen(cmd).read()
    if dbm:
        dbm_num = int(dbm)
        quality = 2 * (dbm_num + 100)
        print("{0} dbm_num = {1}%".format(dbm_num, quality))
    else:
        print("Wifi router connection signal strength not found")
    

    In order to get the highest wifi quality from where my computer is located, I moved/rotated my antenna until I received the highest quality. To see real time quality, I ran the above script using:

    watch -n0.1 "python getwifiquality.py"
    

提交回复
热议问题