Open RouNNdeL opened 4 years ago
@RouNNdeL - I'm not denying that there may be an issue here, but digging through the wireless-tools library, I'm not certain that this should be going from 0 - 100.
This is actually somewhat problematic to code as the idea of a maximum quality is a bit odd when talking about dB. I think the best option would be to display the actual dB instead of trying to create some form of percentage here.
The values for %signal%
do go from 0 to 100, but the edges (especially 100% is rarely reached). A signal strength of -20dBm coresponds to 100% and -90dBm is 0% with linear interpolation in between.
Many other tools use a quadratic formula that one of the drivers in the linux kernel uses and which reaches a higher percentage value earlier. One example for this is i3status-rust
There is probably a case to be made for polybar to adapt the same model because it would match what many other tools are already doing and values around -50dBm are already quite good and don't necessarily warant only a 57% signal strength.
PRs are welcome, but this really isn't critical.
Here is my workaround: Add this custom script to your polybar config:
[module/wlanwithsignal]
type = custom/script
exec = python3 /path/to/script/wlanwithsignal.py wlan0
interval = 2
Set the path to the script (given below). Add it to modules-right or left. Replace wlan0 with your interface name if necessary.
wlanwithsignal.py
from subprocess import run
from sys import argv
if len(argv) != 2:
raise Exception('Expected argument: interface name')
ifc = argv[1]
output1 = run(['iwconfig', ifc], capture_output=True).stdout.decode('utf-8')
output2 = run(['ip', '-4', 'a', 'show', ifc], capture_output=True).stdout.decode('utf-8')
if output1 and output2:
lines1 = output1.splitlines()
lines2 = output2.splitlines()
name = lines1[0].split(':')[-1].replace('"', '').strip()
dbm = lines1[5].split('=')[-1].replace(' ', '').strip()
ipaddr = lines2[1].split()[1].strip()
state = lines2[0].split()[8].strip()
match state:
case 'UP':
logo = '%{F#F0C674} ' + ifc + '%{F-}'
print(f'{logo} {dbm} {name} {ipaddr}')
case _:
logo = '%{F#707880}'
print(f'{logo} {ifc} {state}')
Put the script into the directory you set in the module.
Make it executable chmod +x wlanwithsignal.py
If your output of ip
and iwconfig
utilities is the same as mine - you are happy
If not - tune the script's parsing (name, dbm, ipaddr, state) for you.
Describe the issue
I'm using the
internal/network
module. Thesignal
value changes unpredictably and does not follow the setinterval
.Expected behavior: The value should update every
2s
-interval = 2
. The value should scale roughly between 0-100.Actual behavior: I was not able to consistently measure how often the value updates (walking around the house, to keep change the signal strength). Sometimes It'd update every 15-30s , and sometimes it would get stuck for a few minutes. The value would never go above 42 even right next to the router, and never below 22 even on the edge of losing the signal.
EDIT: The value just updated to 47 (the highest ever seen) at
-56 dBm
.Was it working before? No, it's the first time I'm using polybar.
To Reproduce
The value reported by
iwconfig
look good. Signal strength-20dBm - -75dBm
.Polybar Log
When the value finally updates:
Environment:
polybar -vvv
:Features: +alsa +curl +i3 +mpd +network(libnl) +pulseaudio +xkeyboard
X extensions: +randr (+monitors) +composite +xkb +xrm +xcursor
Build type: Release Compiler: /usr/bin/c++ Compiler flags: -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wall -Wextra -Wpedantic -O3 -DNDEBUG Linker flags: -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
wlp0s20f3 IEEE 802.11 ESSID:""
Bit Rate=780 Mb/s Tx-Power=22 dBm
Mode:Managed Frequency:5.2 GHz Access Point:
Retry short limit:7 RTS thr:off Fragment thr:off Power Management:on Link Quality=57/70 Signal level=-53 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:2 Invalid misc:2013 Missed beacon:0