Go Down

Topic: is it possible to control the wifi led? Any command? (Read 9543 times) previous topic - next topic

bjarne

#15
Dec 10, 2013, 07:51 am Last Edit: Dec 10, 2013, 09:56 pm by bjarne Reason: 1
Well, that sounded like a fun exercise as I had not heard of Lua before.  So I gave it a shot by creating a new wlanled.lua by stripping out all the stuff in pretty-wifi-info.lua not needed for checking the signal strength, and I added in the commands to blink the wlan led.  It seems to work correctly  :)

Incidentally, is the wlan LED not used for anything while the sketch is running, IOW is it free to use as we please?

wlanled.lua
Code: [Select]
#!/usr/bin/lua

local function get_wifi_info(network, iface, accumulator)
 local net = network:get_wifinet(iface)

 if net then
   local dev = net:get_device()
   if dev then
     accumulator["quality"] = net:signal_percent()
   end
 end
end

local function collect_wifi_info()
 local network = require"luci.model.network".init()
 local accumulator = {}
 get_wifi_info(network, "wlan0", accumulator)
 return accumulator
end

local info = collect_wifi_info()

if info.quality == 0 then
 print("Signal: " .. info.quality .. "%")
 os.execute("echo 'none' > /sys/class/leds/ds:green:wlan/trigger")
end
if info.quality > 0 and info.quality < 25 then
 print("Signal: " .. info.quality .. "%")
 os.execute("echo 'timer' > /sys/class/leds/ds:green:wlan/trigger")
 os.execute("echo 200 > /sys/class/leds/ds:green:wlan/delay_on")
 os.execute("echo 200 > /sys/class/leds/ds:green:wlan/delay_off")
end
if info.quality >= 25 and info.quality < 50 then
 print("Signal: " .. info.quality .. "%")
 os.execute("echo 'timer' > /sys/class/leds/ds:green:wlan/trigger")
 os.execute("echo 1000 > /sys/class/leds/ds:green:wlan/delay_on")
 os.execute("echo 1000 > /sys/class/leds/ds:green:wlan/delay_off")
end
if info.quality >= 50 then
 print("Signal: " .. info.quality .. "%")
 os.execute("echo 'timer' > /sys/class/leds/ds:green:wlan/trigger")
 os.execute("echo 2000 > /sys/class/leds/ds:green:wlan/delay_on")
 os.execute("echo 2000 > /sys/class/leds/ds:green:wlan/delay_off")
end



PCWorxLA


Well, that sounded like a fun exercise as I had not heard of Lua before.
Well, I knew about Lua (for me it was just a YASL-Yet Another Scripting Language) but not that it was by default available on a Yun, as everyone and their next door neighbor seems to be eager to use Python (which I don't like very much do to some design flawsfeatures)...
Quote
So I gave it a shot by creating a new wlanled.lua by stripping out all the stuff in pretty-wifi-info.lua not needed for checking the signal strength, and I added in the commands to blink the wlan led.  It seems to work correctly  :)
That was (and still is) my basic plan of action after looking at the Lua script last night. But I think this could still be improved on by moving the LED access directly in the Lua script instead of making those os.execute calls for that.
As mentioned, I don't have access to my Yun during the work week (at least not with a workable WLAN connection), but I try to get that worked out by the coming weekend...

Ralf

federicofissore

Nice to see starting some lua hacking :)

Lua was used because of its very low memory footprint and start up time. But since it lacks many features* so commonly used, we installed and used and promote python as the language of choice for the yun

* It's not the language lacking features of course, it's the libraries bundled with it that don't suffice

PCWorxLA


Nice to see starting some lua hacking :)

Lua was used because of its very low memory footprint and start up time. But since it lacks many features* so commonly used, we installed and used and promote python as the language of choice for the yun

* It's not the language lacking features of course, it's the libraries bundled with it that don't suffice
Well, working on the libraries to expand them is easier than dealing with a language that has brain-dead (IMHO) structural features...
You move a piece of code around and accidentally don't pay attention to proper white-space in place and your whole program changes... yikes...

Ralf

federicofissore


You move a piece of code around and accidentally don't pay attention to proper white-space in place and your whole program changes... yikes...

Are you talking about lua or python?

PCWorxLA



You move a piece of code around and accidentally don't pay attention to proper white-space in place and your whole program changes... yikes...

Are you talking about lua or python?
Python of course...  :smiley-mr-green:

Lua doesn't depend on whitespace for program logic, all constructs are properly "end"ed. Too bad they decided to make the language case-sensitive... :~

Ralf

Go Up