v0id9 Posted September 14 Share Posted September 14 So I've been working on some things, and one of the things I want to implement in my script is the ability to turn all 3 leds to always_off, red, blue and green, and then remain off til a certain event happens at which point it will turn the led on to a certain color, as visual feedback, and then return the leds back to their original setting. I figured out how to do all those things, except for 1 thing, turning the led settings to "always_off". I can manipulate the led colors and brightness via the brightness file in /sys/class/leds/<specific:led>, but if the ui for example is set to be "heartbeat", then I can't really control it via that file since there is a process elsewhere that will keep setting the file content to 0 and 255 and back continuously. I've had a look in the "police" binary to see how that handles it, but that only seems to manipulate the brightness file directly and nothing else.. Anybody got any ideas on how I could do this? Quote Link to comment Share on other sites More sharing options...
v0id9 Posted September 14 Author Share Posted September 14 (edited) Edit: NVM, seems I found it, you can manipulate the led with the LED command, now I just need to figure out if it's possible to get the current state using that command, I can at least turn it off Edit2: I seem to be able to use that to set the LED to whatever I want it to do, color and patternwise, but I still cannot figure out how I'm supposed to be able to retrieve what the current applied setting is for LEDs so that I can set them back to default afterwards Edited September 14 by v0id9 Quote Link to comment Share on other sites More sharing options...
dark_pyrro Posted September 14 Share Posted September 14 2 minutes ago, v0id9 said: get the current state Not sure if I understand your use case, but can't you just check the LED related file(s) to get the current state (the ones you've already mentioned)? Quote Link to comment Share on other sites More sharing options...
v0id9 Posted September 14 Author Share Posted September 14 (edited) The usecase is to provide an option for the led to be turned off so that it's less noticeable, unless there is a hit in the portal let's say, and then provide the user with feedback on wether that attempt was incorrect: slow red blinking, or wether it was correct: solid green, then revert back to what the state it was beforehand. I am having a scroll through the LED binary right now in /sbin, but I don't see a way to get the current state from there, nor in any of the files in /sys/class/leds/red:system for example Edited September 14 by v0id9 Quote Link to comment Share on other sites More sharing options...
dark_pyrro Posted September 14 Share Posted September 14 What LED binary? There's just a script file that controls the LED. Just cat the files below and if it returns a 1, that LED state is activated /sys/class/leds/red:system/brightness /sys/class/leds/green:system/brightness /sys/class/leds/blue:system/brightness To turn off the LED, just execute LED OFF Quote Link to comment Share on other sites More sharing options...
v0id9 Posted September 14 Author Share Posted September 14 (edited) yea that LED script is the one I mean, that's /sbin/LED, I can control it with that, but I can't seem to get the current setting that's in the UI from it, for example it would be possible to grab it from /sys/class/leds/red:system/brightness if the setting in the UI was set to "Always On" or "Always Off", then it would be pretty straightforward, but if it was set to say "Heartbeat" or "Network", then it constantly manipulates /sys/class/leds/red:system/brightness to be 0 or 255, but it would constantly change, so then it gets pretty difficult for me to discern what the original setting was.. But the setting that's set in the UI gets saved somewhere because it retains the setting on a reboot, so it should be stored somewhere right? Edit: Found it I think, it's in the trigger file Edit2: Never mind, I need to learn to read.... I don't have to find the current state anywhere, I can simply do LED RESET for it to go back to the previous setting Edited September 14 by v0id9 Quote Link to comment Share on other sites More sharing options...
dark_pyrro Posted September 14 Share Posted September 14 OK, well... if you want to edit the settings that the web UI saves using CLI, then you can try to manipulate /etc/config/system Quote Link to comment Share on other sites More sharing options...
v0id9 Posted September 14 Author Share Posted September 14 (edited) Hmm, maybe, I don't really know if it's necessary yet but I'll try to implement this first, but that does look like what I was initially looking for and looks worthwhile, thanks Edit: That file actually looks a lot easier to grep instead of needing to grep 3 files Edited September 14 by v0id9 Quote Link to comment Share on other sites More sharing options...
dark_pyrro Posted September 14 Share Posted September 14 you can use uci as well to "interact" with it (instead of just using grep) Quote Link to comment Share on other sites More sharing options...
v0id9 Posted September 14 Author Share Posted September 14 Would that be simpler? That's like an openwrt thing right? This is already my first time messing around with php and I'm kinda learning as I go along, maybe I should just stick to what I'm familiar with, or would using uci be more effective? Quote Link to comment Share on other sites More sharing options...
Solution dark_pyrro Posted September 14 Solution Share Posted September 14 It depends on what you want to do, and how I think using uci is far easier if the settings are a part of what's within the "uci scope" To show not just the value, but the whole "uci path" as well, for a LED setting (using red LED as an example here): uci show system.led_red.trigger To show just the value itself: uci get system.led_red.trigger Set a value for a LED color: uci set system.led_red.trigger='default-on' uci commit system /etc/init.d/system restart Addressing green and blue is done in the same way: uci set system.led_green.trigger='off' uci set system.led_blue.trigger='off' Possible trigger settings should be: default-on off heartbeat netdev with extended options for netdev specifically: option mode 'tx rx' option dev 'eth0' option dev 'wlan0' option dev 'wlan0-1' option dev 'wlan0-2' option dev 'wlan0-3' option dev 'wlan1mon' option dev 'wlan2' option dev 'wlan3mon' Quote Link to comment Share on other sites More sharing options...
v0id9 Posted September 15 Author Share Posted September 15 That's perfect, I can just do uci get system.led_red.trigger to get the value I need then, and uci set system.led_blue.trigger='<value>' to set it and do LED RESET to apply it, that's by far the simplest and cleanest method, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.