Files
rpi-fan-control/README.md
2026-04-05 21:06:16 +03:00

41 lines
1.5 KiB
Markdown

# rpi-fan-control
Daemon that reads CPU temperature and toggles a fan on GPIO pin 17. Uses hysteresis to avoid rapid on/off cycling.
## How it works
Polls `/sys/class/thermal/thermal_zone0/temp` every 1.5 seconds. Fan turns on when temperature crosses `threshold + variance`, turns off when it drops below `threshold - variance`. With defaults (55°C threshold, 5°C variance), that means on at 60°C, off at 50°C.
## Hardware
GPIO pin 17 → relay or MOSFET → fan. Nothing else special.
## Install
Requires `libgpiod`. Build with cargo:
```sh
cargo build --release
```
For NixOS there's a `service.nix` that wires everything up. Drop it into your configuration and enable the `rpi-fan-control` systemd service.
## Config
Copy `example_configuration.toml` to `/var/fan_control/config.toml` and adjust:
```toml
threshold = 55.0 # °C
variance = 5.0 # fan on at threshold+variance, off at threshold-variance
interval_ms = 1500
gpio_line = 17
gpio_chip = "/dev/gpiochip0"
log_path = "/var/log/fan_control.log"
```
All fields are optional, the defaults worked fine for me.
## Legacy C version
There's an `archived-c` branch with the original implementation. It's a single C file that runs as a one-shot binary via systemd timer (fires every minute), persisting fan state to `/var/log/fanstatus` between invocations. It uses pigpio instead of libgpiod. Same hysteresis logic, same defaults. It works, but I decided to rewrite it in Rust because it's blazingly faster. /s