My name is Joey and I have a serious problem that I can't solve. The problem is that my python script stops running after some hours. To give a little background, I'm building an automatic grow tent to grow house plants like Philodendrons, Syngoniums, Monstera's etc. I'm a mechanical engineering student so I'm very new to python and raspberry. I only worked with arduino for some small projects. So please assume I know nothing and if you can, please explain like you're talking to a child ;)
So there are 5 main components used in the tent:
- Grow light
- Humidifier
- Floor heating
- Fans
- Exhaust fan (refresh air)
I'm using a SCD30 seeed sensor for measuring temperature, humidity and CO2.
Now to the coding. The plan was using SSH on the Pi so I could acces it by my laptop. This worked. Then I started writing the code on my laptop with VScode, PIGPIO and the sensor library. This all works as well. In the code I redirect the output to the tent_data.txt where I can see timestamps, temp, humidity, co2 and which devices are on/off in the tent. The idea was putting this data in an grafana dashboard and everything would be good.
Now to the problem! For some reason the code turns off after some hours. It seems pretty random when it does but it seems to be more like after 6-8 hours. So maybe something with memory? I tried ps aux | grep joes_kweektent but it says that it isn"t running anymore. So it doesn't give an error so I don't know where to start. I can also see the timestamps stopping so I know it isn't printing anymore. At the link drive there are two pictures, stoppedhere and syslog. At that moment the code stopped at 0:37 at night, I also screenshotted the syslog. I tried /var/log/messages but it says nothing. I've been searching on the internet for days now for a solution but I can't find any explanation. Maybe there is a voltage drop and it crashes? Maybe the sensor can't read fast enough and it crashes? Maybe the memory is to full (see unable to watch large file picture in link)? Maybe it's something I'm totally unaware of since I'm so new?
I really really really hope someone can help me out! If you ever need help with CAD software or need a part created for you i will help you out! If you live in the Netherlands I can send you a plant or something! :) Thanks in advance everyone!
Links:
Code and some pictures: https://drive.google.com/drive/folders/1qbOtcluAanKll6cTUWEDwjfUR-fYzdG2?usp=sharing
# Imports
import adafruit_scd30
import board
import time
import busio
import datetime
import kweekparameters
import RPi.GPIO as GPIO
import sys
# Setup
# Sensor
i2c = busio.I2C(board.SCL, board.SDA, frequency=50000)
scd = adafruit_scd30.SCD30(board.I2C())
# Opstart-bericht
print ("Joe's Kweektent© by Joey Slager")
time.sleep(2)
# Hardware pinnen
ventilatorenPin = 5
bevochtigerPin = 16
kweeklichtPin = 20
buisVentilatorPin = 19
vloerVerwarmingPin = 26
# Zet de GPIO op board pin layout
GPIO.setmode(GPIO.BCM)
# Pin setup
GPIO.setup(ventilatorenPin, GPIO.OUT)
GPIO.setup(bevochtigerPin, GPIO.OUT)
GPIO.setup(kweeklichtPin, GPIO.OUT)
GPIO.setup(buisVentilatorPin, GPIO.OUT)
GPIO.setup(vloerVerwarmingPin, GPIO.OUT)
# Dict om de booleans te vertalen naar aan/uit
aan_uit = {True: "Uit", False: "Aan"}
# Loop
while True:
# Huidige tijd
tijd = datetime.datetime.now()
# Als er data beschikbaar is print dan de waardes
if scd.data_available:
# Aangeven dat data naar tent_data.txt moet
sys.stdout = open('/home/joeyslager/Joes_Kweektent/tent_data.txt', 'a')
# Variabelen voor parameters
temperatuur = scd.temperature
luchtvochtigheid = scd.relative_humidity
koolstofDioxide = scd.CO2
# Prints
print("---------------------------------------------")
print(f"Tijd: {tijd.strftime('%X')}")
print(f"Temperatuur: {temperatuur:0.2f} °C")
print(f"Luchtvochtigheid: {luchtvochtigheid:0.1f}%")
print(f"CO2: {koolstofDioxide:0.0f} PPM")
print("---------------------------------------------")
print(f"Kweeklicht: {aan_uit[GPIO.input(kweeklichtPin)]}")
print(f"Bevochtiger: {aan_uit[GPIO.input(bevochtigerPin)]}")
print(f"Ventilatoren: {aan_uit[GPIO.input(ventilatorenPin)]}")
print(f"Buisventilator: {aan_uit[GPIO.input(buisVentilatorPin)]}")
print(f"Vloerverwarming: {aan_uit[GPIO.input(vloerVerwarmingPin)]}")
print("---------------------------------------------")
sys.stdout.close()
time.sleep(0.5)
# Test (true = false)
#GPIO.output(ventilatorenPin, True)
#GPIO.output(bevochtigerPin, True)
#GPIO.output(kweeklichtPin, True)
#GPIO.output(buisVentilatorPin, True)
#GPIO.output(vloerVerwarmingPin, True)
# Variabelen voor parameters
temperatuur = scd.temperature
luchtvochtigheid = scd.relative_humidity
koolstofDioxide = scd.CO2
# Kweeklicht
kweeklichtAan = bool(tijd.hour >= kweekparameters.kweekLichtStart and tijd.hour < kweekparameters.kweekLichtEind)
if kweeklichtAan:
GPIO.output(kweeklichtPin, False)
else:
GPIO.output(kweeklichtPin, True)
# Ventilatoren
ventilatorAan = bool(tijd.hour >= kweekparameters.ventilatorStart1 and tijd.hour < kweekparameters.ventilatorEind1
or tijd.hour >= kweekparameters.ventilatorStart2 and tijd.hour < kweekparameters.ventilatorEind2)
if ventilatorAan:
GPIO.output(ventilatorenPin, False)
else:
GPIO.output(ventilatorenPin, True)
# Temperatuur
if temperatuur < kweekparameters.minimumTemperatuur:
GPIO.output(vloerVerwarmingPin, False)
elif temperatuur > kweekparameters.minimumTemperatuur:
GPIO.output(vloerVerwarmingPin, True)
if temperatuur > kweekparameters.maximumTemperatuur:
GPIO.output(buisVentilatorPin, False)
elif temperatuur < kweekparameters.maximumTemperatuur:
GPIO.output(buisVentilatorPin, True)
# Luchtvochtigheid
if luchtvochtigheid < kweekparameters.minimumLuchtvochtigheid:
GPIO.output(bevochtigerPin, False)
elif luchtvochtigheid > kweekparameters.minimumLuchtvochtigheid:
GPIO.output(bevochtigerPin, True)
# CO2