You are not logged in.

#1 2016-11-21 04:51:45

The_Keeper
Member
Registered: 2016-11-21
Posts: 3

AwesomeWM network widget interfaces autodetection

Hello. I'm new to Awesome and Lua, but I already like the WM.
My concern is network statistics. I connect the Internet via USB-Tethering and each time I get somewhat different interface name: it can be enp0s20u4, another time (or with different device) it might be enp0s20u2 but generally it is enp0sXXuY. I want my network widget to show net stats without specifying the interface names in advance. (I'm trying to setup vicious.net widget for that purpose).

I guess I should set up WM to catch signal every time connections change to re-register the widget, but I have no idea how.

Anyway, if the widget could just list stats on all connected interfaces, I think that would work as well.

Curiously, the state of those interfaces is never UP but UNKNOWN:

~ » ip link
...
 enp0s20u4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 1000

Of course if manually put the interface name, it works just fine

vicious.register(netwidget, vicious.widgets.net, "D:${enp0s20u4 down_kb}", 1)

so the problem is to detect the name when it's connected.

Last edited by The_Keeper (2016-11-21 05:15:48)

Offline

#2 2016-11-21 05:40:29

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: AwesomeWM network widget interfaces autodetection

The state is in the bracketed array:

<BROADCAST,MULTICAST,**UP**,LOWER_UP>

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2016-11-21 13:42:55

The_Keeper
Member
Registered: 2016-11-21
Posts: 3

Re: AwesomeWM network widget interfaces autodetection

So, I've tried to catch dbus-singals of NetworkManager, but I can't get all the relevant data. According to NetworkManager docs DeviceAdded and DeviceRemoved signals should return path to the device.  Here is my rc.lua with comments:

local dbus=dbus
...
dbus.add_match("system", "type=signal,interface='org.freedesktop.NetworkManager',member='DeviceRemoved'")
dbus.add_match("system", "type=signal,interface='org.freedesktop.NetworkManager',member='DeviceAdded'")
  dbus.connect_signal(
    "org.freedesktop.NetworkManager",
    function(...)
		local data = {...}
		local sender=data[1] -- here is signal info (type, interface, etc)
		local state=data[2]  -- here should be path to device, but there's none: data is one-element table
		-- I've tried to get interface name from /sys/class/net, but it seems like NetworkManager
		-- needs some time to update those (new device name is usb0, if any):
		local p = assert(io.popen("ls /sys/class/net","r"))
		local s = p:read('*all')
		naughty.notify({ text=tostring(s),timeout = 10}) 
	end)

Any suggestions?

Offline

#4 2016-11-24 07:48:13

The_Keeper
Member
Registered: 2016-11-21
Posts: 3

Re: AwesomeWM network widget interfaces autodetection

Of course, I can just read /sys/class/net on each refresh, but I suppose it would be an overhead on system resources. Would that really be significantly worse that dbus way?

Offline

Board footer

Powered by FluxBB