A Pulse Width Modulation Fan For RaspberryPi written in Go
Fan speed is adjust by CPU temperature, to reduce fan noise and power consumption
This program still in EARLY development, function may missing or not work properly, use with caution.
This library still in EARLY development, APIs may change, use with caution.
- Easy to use, just a binary file and a simple configuration file
- Easy install/uninstall with handy script
- Run as systemd service
- remote fan state monitor
- A Raspberry Pi 1/2/3 serial
- A fan that support PWM signal, or you can build one by add a transistor (and resistor) to you origianl fan
Raspberry Pi support max +5V for power pin, and use +3.3V for other gpio pin, double check before connect anything to you pi.
- Raspberry Pi runs with linux.
- [OPTIONAL] If you want to use inbox system daemon configuration, a Systemd controlled system.
- [OPTIONAL] If you want to build programe yourself, a Go SDK.
- This program uses PWM signal to adjust hardware fan speed and run state.
- This program reads temperature data from system file, and compare with configuration file, then change fan speed and state at SampleRate.
- This program uses ratio speed to control fan speed, not hardware real speed.
Which means FullCycle in configuration file corresponds to the maximum capablility of fan speed.
And the ratio of xxxCycle divided by FullCycle define fan's speed. - There 3 states for fan, Stop, Start, Run.
- In Stop state, fan will run at StopCycle speed, which usually be 0.
If temperature is higher than Temp, this program will add one into count, otherwise remove one from count.
If count reaches Count settings, fan will shift into Start state. - In Start state, fan will run at Cycle speed, then shift into Run state.
This state designs for starting fan to run properly, not too fast nor too slow. - In Run state, fan's speed is adjust between a high Cycle and a low Cycle, with temperature as a ruler.
If temperature is lower than Temp, this program will add one into count, otherwise remove one from count.
If count reaches Count settings, fan will shift into Stop state.
Then fan will loop into step 5.
Since controller program uses pwm to control fan, it only works with root privillage.
You can get a very simple installation help when you run ./install.sh with no argument.
- Download release package from Releases to your Pi.
cd controller
- Modify configuration file, see Controller Configuration File below.
- Use
./install.sh install
to install controller program to your system.
- On your Pi
go get -v -u -d github.com/eZioPan/pwmfan-go
cd $/GOPATH/src/github.com/eZioPan/pwmfan-go/cmd/controller
./install.sh build
- Modify configuration file, see Controller Configuration File below.
- Use
./install.sh install
to install controller program to your system.
By default, the controller program use JSON style "config.json" file in the same directory of binary file, you can change it using -conifg command line parameter.
Here is an example of controller configuration file:
{
"Pin":18,
"CPUTempPath":"/sys/class/thermal/thermal_zone0/temp",
"SampleRate":2,
"PwmFreq":600,
"FullCycle":100,
"StopCycle":0,
"Start":{
"Temp":38,
"Cycle":50,
"Count":5
},
"Low":{
"Temp":30,
"Cycle":50,
"Count":5
},
"High":{
"Temp":45,
"Cycle":100,
"Count":0
},
"NetworkSettings":{
"InterfaceName":"lo",
"ListenPort":2334,
"Token":"123456789"
}
}
Pin defines the gpio pin number of PWM. This uses BCM Pinout number, you can check here.
CPUTempPath defines the system file path to read cpu's temperature.
SampleRate is the rate that program check CPU temperature and change fan speed in.
PwmFreq PWM signal frequence, should be set high enough for PWM signal.
FullCycle is maximum speed which fan is able to run at.
StopCycle is the speed when fan stays in Stop state, usually this value should be 0.
Stop,Start,Run as described in Basic Principle earlier, is the configurations for each state.
NetworkSettings contains all network configuration for sending and receiving information.
InterfaceName is the network interface which will be use to listen request and send fan data from.
ListenPort is the network port which will be use to listen request and send fan data by.
Token is the token that will be check during fan data request.
cd controller
./install.sh uninstall
- Download release package from Releases.
cd monitor
- Modify configuration file, see Monitor Configuration File below.
- Use
./monitor
to monitor your fan state.
- On your Pi
go get -v -u -d github.com/eZioPan/pwmfan-go
cd $/GOPATH/src/github.com/eZioPan/pwmfan-go/cmd/monitor
go build -v -ldflags "-s -w"
- Modify configuration file, see Monitor Configuration File below.
- Use
./monitor
to monitor your fan state.
By default, the monitor program use JSON style "config.json" file in the same directory of binary file, you can change it using -conifg command line parameter.
Here is an example of monitor configuration file:
{
"NetworkInterface":"lo",
"remoteHost":"localhost",
"remotePort": 2334,
"Token":"123456789",
"SampleRate":1
}
NetworkInterface is the network interface which will be use to send request and receive fan data from.
remoteHost is IP/hostname that your controller program exist.
remotePort is the port your controller program use to listen request and send data.
Token is the token that will be check during fan data request.
SampleRate is the rate that monitor will request fan state in.
Just remove binary file and configuration file.
- If you want to use fan monitor in a diffrent machine, please check your network/firewall settings.
pwmfan use UDP to send and receive message. - Token must be THE SAME both in controller configuration file and monitor configuration file.
As for now, token is sent in plain text, DO NO PUT ANY SENSITIVE DATA IN THIS FIELD. - As for now, fan data is sent in plain text, will change in future release.
go get -v -u -d github.com/eZioPan/pwmfan-go
import "github.com/eZioPan/pwmfan-go/common"
import "github.com/eZioPan/pwmfan-go"
stianeikeland/go-rpio for accessing RasberryPi gpio in pure go.
- Write fan log to system log
- Add support for user defined fan data
- Linux man page for commandline
- send network data with encryption
- [Done in v0.3.0]
Redesign configuration for more clear layer style - [Done in v0.2.0]
Network function to read fan state - [Done in v0.2.0]
run as a Systemd service - [WON'T DO]
Network function to change fan parameter(Too dangerous)
-
v0.3.0
Redesign configuration file into more clear layer style
Extract common code into sub directory for reusing
Bugs fix -
v0.2.0
Support systemd service
Support remote fan monitor
Support SampleRate parameter -
v0.1.0
Reconstruct code
Support StartCount and StopCount parameter -
v0.0.1
Init Release
Basic function