Skip to content

[Net widget] devices not passed to net_now #454

@zvolin

Description

@zvolin

Hi,
I was trying to hack net widget a bit, to refetch network ssid every time new connection is acquired and I've noticed that net_now variable doesn't contain devices array. I've added simple logging to check what's going on, but I couldn't find why does it happen.
I've added some simple logging which shows that indeed net_now is not updated in the end. Here is a diff of my changes:

diff --git a/util/separators.lua b/util/separators.lua
index 465132d..ccf85fd 100644
--- a/util/separators.lua
+++ b/util/separators.lua
@@ -11,7 +11,7 @@ local gears = require("gears")
 
 -- Lain Cairo separators util submodule
 -- lain.util.separators
-local separators = { height = 0, width = 9 }
+local separators = { height = 0, width = 15 }
 
 -- [[ Arrow
 
diff --git a/widget/net.lua b/widget/net.lua
index 805b577..720992a 100644
--- a/widget/net.lua
+++ b/widget/net.lua
@@ -37,7 +37,25 @@ local function factory(args)
 
     if #net.iface == 0 then net.get_device() end
 
+    file = io.open('lain.log', 'a')
+    io.output(file)
+    io.write('Initializing lain.widget.net:\n'..
+            '\ttimeout: '..timeout..'\n'..
+            '\tunits: '..units..'\n'..
+            '\tnotify: '..notify..'\n'..
+            '\twifi_state: '..wifi_state..'\n'..
+            '\teth_state: '..eth_state..'\n'..
+            '\tscreen: '..screen..'\n'..
+            '\tiface: { ')
+    for i, s in ipairs(net.iface) do
+        io.write(i..', '..s..'; ')
+    end
+    io.write('}\n')
+    io.close(file)
+
     function net.update()
+        file = io.open('lain.log', 'a')
+        io.output(file)
         -- These are the totals over all specified interfaces
         net_now = {
             devices  = {},
@@ -46,6 +64,16 @@ local function factory(args)
             received = 0
         }
 
+        function net_now:dump()
+            ret = 'Net_now:\n\tdevices: '
+            for n, dev in ipairs(self.devices) do
+                ret = ret..'{'..self.n..', '..self.dev..'}, '
+            end
+            ret = ret..'\n\tsent: '..self.sent
+            ret = ret..'\n\treceived: '..self.sent..'\n'
+            return ret
+        end
+
         for _, dev in ipairs(net.iface) do
             local dev_now    = {}
             local dev_before = net.devices[dev] or { last_t = 0, last_r = 0 }
@@ -66,14 +94,27 @@ local function factory(args)
 
             dev_now.last_t   = now_t
             dev_now.last_r   = now_r
+            io.write('Update:\n'..
+                    '\tdev: '..dev..'\n'..
+                    '\tdev_now.carrier: '..dev_now.carrier..'\n'..
+                    '\tdev_now.state: '..dev_now.state..'\n'..
+                    '\tdev_now.sent: '..dev_now.sent..'\n'..
+                    '\tdev_now.received: '..dev_now.received..'\n'..
+                    '\tdev_now.last_t: '..dev_now.last_t..'\n'..
+                    '\tdev_now.last_r: '..dev_now.last_r..'\n')
 
             if wifi_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) == "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then
                 dev_now.wifi   = true
                 dev_now.signal = tonumber(string.match(helpers.lines_from("/proc/net/wireless")[3], "(%-%d+%.)")) or nil
+                io.write(
+                    '\tdev_now.wifi: '..tostring(dev_now.wifi)..'\n'..
+                    '\tdev_now.signal: '..dev_now.signal..'\n')
             end
 
             if eth_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) ~= "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then
                 dev_now.ethernet = true
+                io.write(
+                    '\tdev_now.ethernet: '..dev_now.ethernet..'\n')
             end
 
             net.devices[dev] = dev_now
@@ -102,6 +143,8 @@ local function factory(args)
         net_now.received = string.format("%.1f", net_now.received)
 
         widget = net.widget
+        io.write(net_now:dump())
+        io.close(file)
         settings()
     end

And here is a sample of output:

Initializing lain.widget.net:
	timeout: 20
	units: 1024
	notify: on
	wifi_state: on
	eth_state: off
	screen: 1
	iface: { 1, wlan0; }
Update:
	dev: wlan0
	dev_now.carrier: 1
	dev_now.state: up
	dev_now.sent: 578.2
	dev_now.received: 799.8
	dev_now.last_t: 11842390
	dev_now.last_r: 16379913
	dev_now.wifi: true
	dev_now.signal: -54.0
Net_now:
	devices: 
	sent: 578.2
	received: 578.2
Update:
	dev: wlan0
	dev_now.carrier: 1
	dev_now.state: up
	dev_now.sent: 0.5
	dev_now.received: 0.4
	dev_now.last_t: 11853508
	dev_now.last_r: 16389063
	dev_now.wifi: true
	dev_now.signal: -56.0
Net_now:
	devices: 
	sent: 0.5
	received: 0.5
Update:
	dev: wlan0
	dev_now.carrier: 1
	dev_now.state: up
	dev_now.sent: 1.8
	dev_now.received: 2.9
	dev_now.last_t: 11890441
	dev_now.last_r: 16448641
	dev_now.wifi: true
	dev_now.signal: -54.0
Net_now:
	devices: 
	sent: 1.8
	received: 1.8
❯ awesome -v
awesome v4.3 (Too long)
 • Compiled against Lua 5.3.5 (running with Lua 5.3)
 • D-Bus support: ✔
 • execinfo support: ✔
 • xcb-randr version: 1.6
 • LGI version: 0.9.2
❯ lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions