I got a pi3 thats it’s running a bit hot now during the summer, so i cooked up a little gadget with a mini fan that checks via crontab every 10min what’s the temperature and fires up the fan if its over 45 oC.
Everything works fine, the only thing that doesnt work is the states of the GPIOs on boot and/or during these 10minutes.
I’ve set up my rc.local like so to enable GPIO2 to be the ‘signal’ for the fan to turn on:
!/bin/sh
echo "2">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio2/direction
exit 0
Now my main script (fan.sh) is this:
#!/bin/sh
timestamp() {
date +"%Y-%m-%d %T"
}
LOGDIR="/var/log/fan.log"
VALUE=45
TEMP=`vcgencmd measure_temp | cut -c6,7`
STATUS=`cat /sys/class/gpio/gpio2/value`
echo `timestamp` " Info: Temperature: $TEMP">>$LOGDIR
if [ $TEMP -ge $VALUE ] && [ $STATUS -eq 0 ]
then
echo `timestamp` " Warning: Fan started.">>$LOGDIR
echo "1">/sys/class/gpio/gpio2/value
elif [ $TEMP -le $VALUE ] && [ $STATUS -eq 1 ]
then
echo `timestamp` " Warning: Fan stopped.">>$LOGDIR
echo "0">/sys/class/gpio/gpio2/value
fi
The problem is during these 10 minutes the GPIO symlinks are getting deleted for some reason and the $TEMP value is null…so i have to manually do the lines in the rc.local for the whole thing to work again.
- Why is this happening ?
- Right now as a temp solution i’ve added those 2 lines from the rc.local in my main script under the STATUS line. I know its wrong, but what else can i do ? Any ideas ?
This is my setup btw (where speaker = fan obviously) if anyone wants to do the same :
-Thanks