1) The sensor script I run is supposed to start the sensor, gather data over a given period to get a fresh air sample, and then stop.
Sometimes though, for reasons unknown, the code dies or throws a fit and then the fan continues to run. This leads me to reason #2
2) I have a reset script to kill it ready for the next attempt
In my aqireset.py code it is exactly the same as the aqi.py code *except* that the main program section of the code is cut down to just these few lines
Code: Select all
if __name__ == "__main__":
cmd_set_sleep(0)
time.sleep(1)
cmd_firmware_ver()
time.sleep(1)
cmd_set_sleep(1)
quit()
However, after all that, this sometimes fails as well. So, I have a 3rd script to nuke everything: aqikill.py:
Code: Select all
import os
import signal
import sys
import time
print("Searching for 'aqi.py' in processes")
for line in os.popen("ps ax | grep aqi.py | grep -v grep"):
fields = line.split()
print(line)
with open("/home/pi/aqikilled.log", "a") as logfile:
logtext = ' '.join([time.strftime("%Y/%m/%d %H:%M:%S "), "killed: ", line])
logfile.write(logtext)
logfile.close()
print(logtext)
pid = fields[0]
os.kill(int(pid), signal.SIGKILL)
print("Searching for 'aqireset.py' in processes")
for line in os.popen("ps ax | grep aqireset.py | grep -v grep"):
fields = line.split()
print(line)
with open("/home/pi/aqikilled.log", "a") as logfile:
logtext = ' '.join([time.strftime("%Y/%m/%d %H:%M:%S "), "killed: ", line])
logfile.write(logtext)
logfile.close()
print(logtext)
pid = fields[0]
os.kill(int(pid), signal.SIGKILL)
print("Completed.")
Code: Select all
*/30 * * * * python /home/pi/aqi.py > /home/pi/aqi.log 2>&1
03,25,29,33,55,59 * * * * python /home/pi/aqikill.py > /home/pi/aqikill.log 2>&1
04,26,34,56 * * * * python /home/pi/aqireset.py > /home/pi/aqireset.log 2>&1
@reboot sleep 30 && python /home/pi/aqireset.py > /home/pi/aqireset.log 2>&1