pimoroni / fanshim-python

Python library for the Fan SHIM for Raspberry Pi
https://shop.pimoroni.com/products/fan-shim
MIT License
295 stars 85 forks source link

Fanshim service issue Raspbian 9.11 #60

Closed rei-vilo closed 4 years ago

rei-vilo commented 4 years ago

I went through a problem similar to #58, albeit on a Raspberry Pi 3 with Raspbian 9.11.

When I run python3 automatic.py, the fan runs fine.

But it doesn't work when installed as a service.

$ sudo ./install-service.sh --on-threshold 65 --off-threshold 55 --delay 2
Setting up with:
Off Threshold:  55 C
On Threshold:   65 C
Delay:          2 seconds
Preempt:        no
Disable LED:    no
Disable Button: no
Brightness:     255

To change these options, run:
sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> --brightness <n> (--preempt) (--noled) (--nobutton)

Or edit: /etc/systemd/system/pimoroni-fanshim.service

Checking for rpi.gpio>=0.7.0 (for Pi 4 support)
rpi.gpio >= 0.7.0 already installed
Checking for Fan SHIM
Fan SHIM already installed
Checking for psutil
psutil already installed

Installing service to: /etc/systemd/system/pimoroni-fanshim.service
● pimoroni-fanshim.service - Fan Shim Service
   Loaded: loaded (/etc/systemd/system/pimoroni-fanshim.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-12-09 18:46:34 CET; 409ms ago
 Main PID: 6041 (python3)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/pimoroni-fanshim.service
           └─6041 python3 /home/pi/fanshim-python/examples/automatic.py --on-threshold 65 --off-threshold 55 --delay 2…55

Dec 09 18:46:34 myPiTwo.local systemd[1]: Started Fan Shim Service.

Checking with systemctl

$ systemctl | grep pimoroni
● pimoroni-fanshim.service   loaded failed failed    Fan Shim Service        

I went through different solutions, but the pimoroni-fanshim.service is still not working.

Thank you for your help!

Already checked: psutil —from #33

Check with Python 3

import psutil
psutil.sensors_temperatures()

In case of an error, install and upgrade psutil to the latest version

$ pip3 install --upgrade psutil

And check again with Python

import psutil
psutil.__version__
'5.6.7'
psutil.sensors_temperatures()
{'cpu-thermal': [shwtemp(label='', current=55.148, high=None, critical=None)]}

Already checked: GPIO —from #39

Run on Python 3

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, 0) # Should turn fan off
GPIO.output(18, 1) # Should turn fan on

GPIO works fine.

Gadgetoid commented 4 years ago

Does systemctl status pimoroni-fanshim give any useful output- Python errors, or other messages in the log?

rei-vilo commented 4 years ago

Here is the result of systemctl status pimoroni-fanshim:

$ systemctl status pimoroni-fanshim ● pimoroni-fanshim.service - Fan Shim Service Loaded: loaded (/etc/systemd/system/pimoroni-fanshim.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2019-12-09 19:18:41 CET; 30min ago Main PID: 10716 (code=exited, status=1/FAILURE)

Dec 09 19:18:41 myPiTwo.local systemd[1]: pimoroni-fanshim.service: Unit entered failed state. Dec 09 19:18:41 myPiTwo.local systemd[1]: pimoroni-fanshim.service: Failed with result 'exit-code'. Dec 09 19:18:41 myPiTwo.local systemd[1]: pimoroni-fanshim.service: Service hold-off time over, scheduling restart. Dec 09 19:18:41 myPiTwo.local systemd[1]: Stopped Fan Shim Service. Dec 09 19:18:41 myPiTwo.local systemd[1]: pimoroni-fanshim.service: Start request repeated too quickly. Dec 09 19:18:41 myPiTwo.local systemd[1]: Failed to start Fan Shim Service. Dec 09 19:18:41 myPiTwo.local systemd[1]: pimoroni-fanshim.service: Unit entered failed state. Dec 09 19:18:41 myPiTwo.local systemd[1]: pimoroni-fanshim.service: Failed with result 'exit-code'.

rei-vilo commented 4 years ago

The only workaround I've found so far is to launch

python3 fanshim-python/examples/automatic.py &

Not very clean, especially if the Raspberry Pi reboots.

rei-vilo commented 4 years ago

Any answer?

Gadgetoid commented 4 years ago

I had no idea what the problem was in this case, so I was at a loss to providing a fix. However it might be related to- https://github.com/pimoroni/fanshim-python/issues/66

I've since added a fix for the executable path, so re-running install-service.sh might help.

rei-vilo commented 4 years ago

Unfortunately, the fix from #66 didn't solve the issue.

$ git clone https://github.com/pimoroni/fanshim-python
$ cd fanshim-python
$ sudo ./install.sh

$ cd examples
$ sudo ./install-service.sh --on-threshold 50 --off-threshold 40 --delay 2

$ systemctl | grep pimoroni
● pimoroni-fanshim.service                                                                                          
      loaded failed     failed          Fan Shim Service             
DKeppi commented 4 years ago

Same problem here, so i reinstalled it and now it works :)

Gadgetoid commented 4 years ago

@rei-vilo did you ever get to the bottom of this?

rei-vilo commented 4 years ago

Thank you for asking.

A clean install (OS + Fanshim utility) solved the issue on the Raspberry Pi 4B.

FlorentLM commented 3 years ago

I had the same issue... turns out that you need to launch the install-service.sh from the examples folder.

If you launch it, for instance, from the base folder like so sudo install ./examples/install-service.sh

then the $(pwd) in install-service.sh (lines 212 and 213)

WorkingDirectory=$(pwd)
ExecStart=$PYTHON $(pwd)/automatic.py --on-threshold $ON_THRESHOLD --off-threshold $OFF_THRESHOLD --low-temp $LOW_TEMP --high-temp $HIGH_TEMP --delay $DELAY --brightness $BRIGHTNESS $EXTRA_ARGS

takes the wrong working directory, and the service never finds the automatic.py file...