polybar / polybar

A fast and easy-to-use status bar
https://polybar.github.io
MIT License
14.2k stars 710 forks source link

Network module WiFi signal strength issues #2179

Open RouNNdeL opened 4 years ago

RouNNdeL commented 4 years ago

Describe the issue

I'm using the internal/network module. The signal value changes unpredictably and does not follow the set interval.

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

[colors]
background = #70000000
foreground = #dfdfdf

[bar/bar]
width = 100%
height = 34
offset-x = 1%
offset-y = 1%

background = ${colors.background}
foreground = ${colors.foreground}

font-0 = "Roboto:style=Medium:pixelsize=11;2"
font-1 = "Roboto:style=Medium:pixelsize=8;2"
font-2 = "Symbols Nerd Font:fontformat=truetype:pixelsize=13;4"
font-3 = "Roboto:style=Bold:pixelsize=15;2"
font-4 = "Roboto:style=Medium:pixelsize=10;2"
font-5 = "Roboto:style=Bold:pixelsize=11;2"
font-6 = "Roboto:style=Regular:pixelsize=11;2"
font-7 = "Roboto:style=Thin:pixelsize=30;2"
font-8 = "Material Design Icons Desktop:fontformat=truetype:pixelsize=13;4"

modules-left = 
modules-center = 
modules-right = wlan

[module/wlan]
type = internal/network
interface = wlp0s20f3
interval = 2 

format-connected = <label-connected>
label-connected = %{T6}%essid% %{T7}%local_ip% %signal%
label-connected-foreground = #ff87c095

The value reported by iwconfig look good. Signal strength -20dBm - -75dBm.

Polybar Log

* Loading config: /home/kris/config_wifi_only
- config: Current bar section: [bar/bar]
* Loaded monitor eDP1 (1920x1080+0+0)
* Bar geometry: 1920x34+19+11; Borders: 0,0,0,0
- bar: Attach X event sink
- bar: Attach signal receiver
- controller: Install signal handler
- controller: Setup user-defined modules
* Starting application
- controller: Main thread id = 1
* Starting module/wlan
- module/wlan: Thread id = 2
* Entering event loop (thread-id=1)
- controller: Attach config watch
* Eventqueue worker (thread-id=3)
- bar: Create renderer
- renderer: Get TrueColor visual
- renderer: Allocate colormap
- renderer: Allocate output window
- renderer: Allocate window pixmaps
- renderer: Allocate graphic contexts
- renderer: Allocate alignment blocks
- renderer: Allocate cairo components
- renderer: Load fonts
* Configured DPI = 96x96
* Loaded font "Roboto:style=Medium:pixelsize=11" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Medium.ttf)
* Loaded font "Roboto:style=Medium:pixelsize=8" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Medium.ttf)
* Loaded font "Symbols Nerd Font:fontformat=truetype:pixelsize=13" (name=Symbols Nerd Font, offset=4, file=/usr/share/fonts/TTF/Symbols-2048-em Nerd Font Complete.ttf)
* Loaded font "Roboto:style=Bold:pixelsize=15" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Bold.ttf)
* Loaded font "Roboto:style=Medium:pixelsize=10" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Medium.ttf)
* Loaded font "Roboto:style=Bold:pixelsize=11" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Bold.ttf)
* Loaded font "Roboto:style=Regular:pixelsize=11" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Regular.ttf)
* Loaded font "Roboto:style=Thin:pixelsize=30" (name=Roboto, offset=2, file=/usr/share/fonts/TTF/Roboto-Thin.ttf)
* Loaded font "Material Design Icons Desktop:fontformat=truetype:pixelsize=13" (name=Material Design Icons Desktop, offset=4, file=/usr/share/fonts/MaterialDesignIconsDesktop.ttf)
* Bar window: 0x0e00001
- bar: Reconfigure window
- bar: Set window WM_NAME
- bar: Set window _NET_WM_WINDOW_TYPE
- bar: Set window _NET_WM_STATE
- bar: Set window _NET_WM_DESKTOP
- bar: Set window _NET_WM_PID
- bar: Map window
- bar: Draw empty bar
- bar: Setup tray manager
* Disabling tray manager (reason: missing `tray-position`)
* module/wlan: Rebuilding cache
- bar: Force update
* Redrawing bar window
- renderer: flush(3 geom=161x34+1759+0, falloff=0)
- bar: Received expose event
* module/wlan: Rebuilding cache
- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache
- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache
- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache
- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache
- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache

When the value finally updates:

- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache
* Redrawing bar window
- renderer: flush(3 geom=161x34+1759+0, falloff=0)
* module/wlan: Rebuilding cache
- bar: Ignoring update (unchanged)
* module/wlan: Rebuilding cache

Environment:

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

## Additional context
Example output of `iwconfig`:

wlp0s20f3 IEEE 802.11 ESSID:""
Mode:Managed Frequency:5.2 GHz Access Point: Bit Rate=780 Mb/s Tx-Power=22 dBm
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

cynicated commented 3 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.

patrick96 commented 2 years ago

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.

mike0618 commented 11 months ago

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.