ruundii / bthidhub

Bluetooth HID hub
MIT License
309 stars 51 forks source link

Cannot Control LED - Causes Crash #59

Closed lswee closed 1 year ago

lswee commented 1 year ago

I'm using Model: Raspberry Pi 3 Model B Rev 1.2

There are no LEDs listed under /sys/class/leds/, so I get:

echo 0 | sudo tee /sys/class/leds/led0/brightness > /dev/null
tee: /sys/class/leds/led0/brightness: No such file or directory

When trying to run setup the remapper.service fails:

Synchronizing state of bluetooth.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable bluetooth
Created symlink /etc/systemd/system/dbus-org.bluez.service → /lib/systemd/system/bluetooth.service.
Created symlink /etc/systemd/system/bluetooth.target.wants/bluetooth.service → /lib/systemd/system/bluetooth.service.
Job for remapper.service failed because the control process exited with error code.
See "systemctl status remapper.service" and "journalctl -xe" for details.

If I check the service, I can see it's due to the inability to control the LED:

systemctl status remapper.service
● remapper.service - Remapper
     Loaded: loaded (/lib/systemd/system/remapper.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2023-08-04 13:16:11 BST; 4min 19s ago
    Process: 690 ExecStart=/usr/bin/python3 /home/pi/bthidhub/remapper.py (code=killed, signal=TERM)
    Process: 691 ExecStartPost=/usr/bin/bash -c echo none > /sys/class/leds/led0/trigger (code=exited, status=1/FAILURE)
    Process: 693 ExecStopPost=/usr/bin/bash -c echo heartbeat > /sys/class/leds/led0/trigger (code=exited, status=1/FAILURE)
   Main PID: 690 (code=killed, signal=TERM)
        CPU: 38ms

Aug 04 13:16:11 bthidhub systemd[1]: Starting Remapper...
Aug 04 13:16:11 bthidhub bash[691]: /usr/bin/bash: line 1: /sys/class/leds/led0/trigger: No such file or directory
Aug 04 13:16:11 bthidhub systemd[1]: remapper.service: Control process exited, code=exited, status=1/FAILURE
Aug 04 13:16:11 bthidhub bash[693]: /usr/bin/bash: line 1: /sys/class/leds/led0/trigger: No such file or directory
Aug 04 13:16:11 bthidhub systemd[1]: remapper.service: Control process exited, code=exited, status=1/FAILURE
Aug 04 13:16:11 bthidhub systemd[1]: remapper.service: Failed with result 'exit-code'.
Aug 04 13:16:11 bthidhub systemd[1]: Failed to start Remapper.

It seems like it's a known problem and there's a different way to turn off the LED? https://overflow.hostux.net/questions/19863723/turn-off-leds-of-raspberry-pi#71492090 https://github.com/seamusdemora/PiFormulae/blob/master/LEDControlForRPi.md

I believe it can be controlled via ACT:

sudo find /sys/devices -name '*trigger*'
/sys/devices/platform/leds/leds/ACT/trigger
/sys/devices/platform/leds/leds/PWR/trigger
/sys/devices/virtual/leds/default-on/trigger
/sys/devices/virtual/leds/mmc0/trigger

It would be good if the LED thing was optional, I don't think it should crash the whole thing if it fails.

Update

For now I removed two lines from https://github.com/ruundii/bthidhub/blob/391044c2868255b2da6d593f6fa4826fa3bb330c/install/on_rpi/remapper.service#L8 ExecStartPost=/usr/bin/bash -c 'echo none > /sys/class/leds/led0/trigger' ExecStopPost=/usr/bin/bash -c 'echo heartbeat > /sys/class/leds/led0/trigger'

Which allowed it to run, although I'm now getting this issue: https://github.com/ruundii/bthidhub/issues/55

Dreamsorcerer commented 1 year ago

Yep, sounds like a reasonable change. If you'd like to make a PR and test it on your device, we can merge that.

lswee commented 1 year ago

What would you prefer me to do: simply remove the lines, disable the LED thing, and remove mention to it in the guide find a way for it to fail silently, but not crash the system find another way to control the LED that works on more Pi's?

Dreamsorcerer commented 1 year ago

I'd like to keep the LED function, but silently failing would be fine. If you think it's easy enough to add support for other devices, then it would be nice to get that included.

xiezhensheng commented 1 year ago

I think the issue here is that in the latest PI os lite (Bullseye), the name of the "LED0" changes to "ACT". So need to change all the LED0 in the script to ACT to fix the issue.

Dreamsorcerer commented 1 year ago

If it's a different Raspbian image (different version of Debian), then I'll be looking to update the project to use the latest version soon.