From bf6c45fb3a96baf8a39cabdf460f200b82a9de89 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Mon, 3 Aug 2020 21:25:07 -0400 Subject: [net] get speed from all interfaces by default --- net-speed-widget/net-speed.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/net-speed-widget/net-speed.lua b/net-speed-widget/net-speed.lua index d0eaaff..7c12ad8 100644 --- a/net-speed-widget/net-speed.lua +++ b/net-speed-widget/net-speed.lua @@ -95,25 +95,28 @@ local function worker(args) local args = args or {} - if args.interface == nil then - show_warning("Interface name is not specified") - return - end - - local interface = args.interface + local interface = args.interface or '*' local update_widget = function(widget, stdout, stderr) local cur_vals = split(stdout, '\r\n') - local cur_rx = cur_vals[1] - local cur_tx = cur_vals[2] + local cur_rx = 0 + local cur_tx = 0 + + for i, v in ipairs(cur_vals) do + if i%2 == 1 then cur_rx = cur_rx + cur_vals[i] end + if i%2 == 0 then cur_tx = cur_tx + cur_vals[i] end + end + + print('cur_rx = ' .. cur_rx) + print('cur_tx = ' .. cur_tx) local speed_rx = cur_rx - prev_rx local speed_tx = cur_tx - prev_tx - net_speed_widget:set_rx_text(convert_to_h(speed_rx)) - net_speed_widget:set_tx_text(convert_to_h(speed_tx)) + widget:set_rx_text(convert_to_h(speed_rx)) + widget:set_tx_text(convert_to_h(speed_tx)) prev_rx = cur_rx prev_tx = cur_tx -- cgit v1.2.3