Automate Fan Speed Control on OpenWrt: A Complete Guide

This guide walks you through the complete process of detecting, configuring, and automating fan speed control on OpenWrt OS.
It supports routers and systems with PWM, GPIO, or I2C fan hardware.


Overview

Fan control on OpenWrt is handled through the Linux Hardware Monitoring (hwmon) subsystem.
If your device includes a controllable fan (via pwm-fan, gpio-fan, or other drivers), OpenWrt can adjust speeds automatically or manually using scripts.


Step 1: Access Your Router

SSH into your router:

ssh root@192.168.x.x

(Replace the IP address with your router’s management IP, such as 192.168.8.1 or 10.0.84.1.)


Step 2: Detect Fan Control Hardware

Run the following to check for fan or temperature monitoring hardware:

ls /sys/class/hwmon/
cat /sys/class/hwmon/hwmon*/name

You’re looking for entries like:

pwm-fan
gpio-fan
it87
nct6775

If you see one of these, your router supports software-based fan control.


Step 3: Install Required Packages

Update your package lists and install fan control modules:

opkg update
opkg install kmod-hwmon kmod-hwmon-pwmfan kmod-gpio-pwm kmod-i2c-core

Optional — Add Temperature Sensors

For devices with temperature sensors:

opkg install lm-sensors
sensors-detect

Run sensors to view live temperature readings:

sensors

🧮 Step 4: Identify Fan Control Interface

List available PWM control files:

ls /sys/class/hwmon/hwmon*/pwm*

If found, test fan speeds manually:

echo 0 > /sys/class/hwmon/hwmon0/pwm1      # Fan off
echo 128 > /sys/class/hwmon/hwmon0/pwm1    # Medium speed
echo 255 > /sys/class/hwmon/hwmon0/pwm1    # Full speed

🧠 Tip: Adjust the number (0–255) for fine-tuning.
If the fan changes speed, you’ve found the correct control file.


🔁 Step 5: Automate Fan Control with Temperature

Create a startup script to automatically adjust fan speed based on CPU temperature.

File path:

/etc/init.d/fancontrol

Contents:

#!/bin/sh /etc/rc.common
START=99

start() {
  echo "Automatic fan control started"
  while true; do
    TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
    if [ "$TEMP" -lt 50000 ]; then
      echo 80 > /sys/class/hwmon/hwmon0/pwm1
    elif [ "$TEMP" -lt 70000 ]; then
      echo 160 > /sys/class/hwmon/hwmon0/pwm1
    else
      echo 255 > /sys/class/hwmon/hwmon0/pwm1
    fi
    sleep 10
  done
}

Make it executable and enable on boot:

chmod +x /etc/init.d/fancontrol
/etc/init.d/fancontrol enable
/etc/init.d/fancontrol start

📊 Step 6: Add GUI Monitoring (Optional)

If you prefer a web-based view through LuCI, install the stats package:

opkg install luci-app-statistics collectd-mod-sensors

Access your router’s LuCI web interface and go to:

Statistics → Sensors

From there, you can:

  • View CPU and board temperatures
  • Verify fan speeds
  • Adjust thresholds for thermal zones

🧾 Step 7: Make the Changes Persistent

To ensure your configuration persists through reboots:

Add your fan control logic to /etc/rc.local (above exit 0):

# Start fan control
/etc/init.d/fancontrol start

💡 Notes

  • Not all devices have PWM or sensor support.
  • If /sys/class/hwmon/ doesn’t show any fan devices, your router may use a fixed-speed or voltage-controlled fan.
  • For beta devices like the Flint 3e, fan control may depend on firmware support from GL.iNet or OpenWrt kernel drivers.

Tip: Provide your exact model (e.g., GL.iNet Flint 3e, OpenWrt 23.05-SNAPSHOT) for tailored driver and configuration paths.

Leave a ReplyCancel reply