Created
September 1, 2022 19:18
-
-
Save jbussdieker/2f8bb7dc073c3e29368fad89b91acda7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import logging | |
import busio | |
import adafruit_sgp30 | |
import board | |
import time | |
import sys | |
autoCalibrate = True | |
logging.basicConfig( | |
format='%(asctime)s %(levelname)-8s %(message)s', | |
level=logging.DEBUG, | |
datefmt='%Y-%m-%d %H:%M:%S') | |
logging.info("Starting up...") | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setwarnings(False) | |
GPIO.setup(17, GPIO.OUT) | |
i2c_bus = busio.I2C(board.SCL, board.SDA) | |
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus) | |
#sgp30.set_iaq_baseline(39649, 41175) | |
fan = None | |
if autoCalibrate: | |
logging.info("Auto Calibrate") | |
# CP | |
logging.info("FAN ON") | |
GPIO.output(17,GPIO.HIGH) | |
fan = True | |
for x in range(0,10): | |
sgp30temp = adafruit_sgp30.Adafruit_SGP30(i2c_bus) | |
for y in range(0,3): | |
# CP | |
eCO2, TVOC = sgp30temp.iaq_measure() | |
baseline_eCO2, baseline_TVOC = sgp30temp.get_iaq_baseline() | |
logging.info("Auto Calibrate: eCO2 = %d ppm \t TVOC = %d ppb \t baseline eCO2 = %d \t baseline TVOC = %d" % (eCO2, TVOC, baseline_eCO2, baseline_TVOC)) | |
time.sleep(15) | |
while True: | |
eCO2, TVOC = sgp30.iaq_measure() | |
baseline_eCO2, baseline_TVOC = sgp30.get_iaq_baseline() | |
logging.info("eCO2 = %d ppm \t TVOC = %d ppb \t baseline eCO2 = %d \t baseline TVOC = %d" % (eCO2, TVOC, baseline_eCO2, baseline_TVOC)) | |
if TVOC > 900 and fan != True: | |
logging.info("FAN ON") | |
GPIO.output(17,GPIO.HIGH) | |
fan = True | |
if TVOC < 700 and fan != False: | |
logging.info("FAN OFF") | |
GPIO.output(17,GPIO.LOW) | |
fan = False | |
time.sleep(15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Air Quality Monitor | |
After=network-online.target | |
StartLimitInterval=200 | |
StartLimitBurst=5 | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=30 | |
User=pi | |
WorkingDirectory=/home/pi | |
ExecStart=/usr/bin/python3 /home/pi/airquality.py | |
StandardOutput=append:/var/log/airquality.log | |
StandardError=append:/var/log/airquality.log | |
SyslogIdentifier=airquality | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment