A simple NodeJS application that can control the fan speed of a Argon ONE V2 case based on the CPU temperature.
- NodeJS 12
- PhpStorm 2020.1.1
- Enable I2C
Go to
sudo raspi-config
Interface Options > I2C
and select Yes - Use NVM to switch NodeJS versions (optional, requires NVM to be installed)
nvm use 12
- Make a copy of
example.fan_config.json
and rename it tofan_config.json
cp example.fan_config.json fan_config.json
- Change the settings in
fan_config.json
if you want to customize the default settings - Install the Node packages
npm install
- Run the
fan.js
file with NodeJSnode fan.js
The fan should now go quiet or start spinning, based on the current temperature and config. It's recommended that you also run this as a service, so you don't have to start it up manually on every boot.
You can create a service for this Node application, so it automatically runs at startup in the background.
-
Make sure
service_start.sh
is executablechmod +x service_start.sh
-
Creating the service
sudo nano /etc/systemd/system/argonone-fanjs.service
Inside the file, add the following code. Please note that you might have to change paths depending on your setup.
[Unit] Description=Argon ONE V2 FanJS Service [Service] WorkingDirectory=/home/pi/projects/ArgonONEV2-FanJS/ ExecStart=/home/pi/projects/ArgonONEV2-FanJS/service_start.sh Restart=on-failure [Install] WantedBy=default.target
-
Enabling the service so it starts with the OS.
sudo systemctl enable argonone-fanjs
-
Reboot the Raspberry Pi and see if the service is running
sudo reboot
After the reboot, run this to see if the service is running
systemctl status argonone-fanjs
You should now have a service that automatically runs service_start.sh
on boot with NodeJS 12.
It runs the script with the --quiet
parameter, so it only logs errors. If you don't want this, remove the --quiet
parameter from service_start.sh