Moode Forum
[How to do instruction] LED control on rpi 3B+ and 4B (moOde 6.4.2+) - Printable Version

+- Moode Forum (http://moodeaudio.org/forum)
+-- Forum: moOde audio player (http://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: FAQ and Guides (http://moodeaudio.org/forum/forumdisplay.php?fid=9)
+--- Thread: [How to do instruction] LED control on rpi 3B+ and 4B (moOde 6.4.2+) (/showthread.php?tid=2344)



LED control on rpi 3B+ and 4B (moOde 6.4.2+) - romain - 04-07-2020

Hello,

I've written a shell script which controls the behavior of the rpi LEDs depending on the availability of the configured sources and/or plugged in USB storage(s).

The script is called by a one shot systemd service unit started by a systemd timer unit every 1 minute after the last execution (thanks to philrandal for his advise), you can change this timing to suite your needs. It queries the local SQLITE db to fetch sources settings and tries to remount automatically configured sources if they become unavailable. Works with SMB, NFS, UPnP.

Version 6.5.0 users should turn off LED0 (Activity) and LED1 (Power) directly in the moOde interface (System -> Sytem Modifications) before enabling the systemd service and timer units. I also made some minor modifications to the shell script itself, new version attached here.

Red LED is off by default.
Fixed green LED means all sources configured and/or all plugged in USB storage(s) are available.
Blinking green LED means at least one configured source and/or one plugged in USB storage is unavailable if multiple sources have been configured or if multiple USB storage(s) are plugged in.
Fixed red LED means configured source(s) and/or plugged in USB storage(s) are unavailable.

The only small drawback is when NFS shares are hard mounted (default) ; you may want use soft NFS mounts instead otherwise the script will get stucked waiting for the NFS server to respond (normal behavior).

For NFS soft mounts you should use instead the mount flags:
Code:
soft,timeo=10,retrans=1,ro,nolock

You can also set these mount flags as default if you edit line 208 (version 6.4.2) or 222 (version 6.5.0) in file /var/www/js/scripts-configs.js in order to obtain:
Code:
$('#options').val('soft,timeo=10,retrans=1,ro,nolock');

File checksources.sh should be placed in /usr/local/sbin and made executable:
Code:
sudo chmod +x /usr/local/sbin/checksources.sh

File checksources.service should be placed in /etc/systemd/system and enabled to launch at startup:
Code:
sudo systemctl enable checksources.service

File checksources.timer should be placed in /etc/systemd/system and enabled to execute checksources.service every 1 minute after the last execution of the unit:
Code:
sudo systemctl enable checksources.timer

Start both systemd units:
Code:
sudo systemctl start checksources.service
Code:
sudo systemctl start checksources.timer
or reboot your system:
Code:
sudo shutdown -r now

To check the output of the script, check out syslog:
Code:
tail -f /var/log/syslog
or use:
Code:
journalctl -u checksources.service

I've tested it on pi 3B+ and 4B with moOde versions 6.4.2 and 6.5.0.

Zip file attached, feel free to use and improve if needed.


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2) - the_bertrum - 04-08-2020

Very nice indeed. Good clear instructions. Thanks very much indeed. It is much nicer to see a reassuring green light telling me all is well rather than the baleful red on that used to tell me nothing other than I had power Smile


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2) - romain - 04-08-2020

Thanks for your feedback, enjoy


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2) - the_bertrum - 04-08-2020

One thing I forgot to mention, I found I needed to issue a systemctl start on both the service and the timer after the systemctl enable. Not sure if that is a glitch on my system, or if I just didn't wait long enough.


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2) - romain - 04-08-2020

(04-08-2020, 12:39 PM)the_bertrum Wrote: One thing I forgot to mention, I found I needed to issue a systemctl start on both the service and the timer after the systemctl enable.  Not sure if that is a glitch on my system, or if I just didn't wait long enough.
You're right, you have to start both systemd units or reboot the system for the changes to take effect. Just edited the initial post to take your remark into account.
Thanks


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2) - romain - 04-08-2020

(04-08-2020, 02:18 PM)romain Wrote:
(04-08-2020, 12:39 PM)the_bertrum Wrote: One thing I forgot to mention, I found I needed to issue a systemctl start on both the service and the timer after the systemctl enable.  Not sure if that is a glitch on my system, or if I just didn't wait long enough.
You're right, you have to start both systemd units or reboot the system for the changes to take effect. Just edited the initial post to take your remark into account.
Thanks

Added a missing semicolon at the end of line 12 in checksources.sh and reuploaded the script


LED control on rpi 3B+ and 4B (moOde 6.4.2+) - romain - 04-27-2020

New version, see initial post


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2+) - the_bertrum - 04-27-2020

Top stuff, got it running on my 6.5.0 now Smile


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2+) - zazouboy - 05-13-2020

Thanks Romain,
Running it on moOde 6.5.2 with an external HDD connected via CIFS, and it works great Smile
Pretty cool to get something useful from the leds  Wink 
Have a nice day !


RE: LED control on rpi 3B+ and 4B (moOde 6.4.2+) - romain - 05-14-2020

It's my pleasure, I'm glad you enjoy it Smile