def waterIsLow(channel): #Turn Blue indicator LED on relay.relayOnOff(blueLEDPin, "on") message = """ Subject: Mushroom Water level is Low The Digital water level sensor was triggered, Refill the mushroom humidifier water. """ #send email sendEmail.sendEmail(emailRecipients, message)
import relay sunlightPin = 5 # remember the relay uses inverted logic relay.relayOnOff(sunlightPin, "on")
def startGrowthCycle(channel): import relay ledpin = 26 delay = 1 relay.relayOnOff(ledpin, "on")
def waterIsHigh(channel): relay.relayOnOff(blueLEDPin, "off")
####################################################################################### startDate = dt.datetime.now() endDate = startDate + dt.timedelta(weeks=timeOfGrowth) writeDate.addDateToData("startDate", startDate.strftime("%c")) #the strftime("%c") will print as "Tue Apr 30 19:41:43 2019" for example writeDate.addDateToData("endDate", endDate.strftime("%c")[0:10]) #just using the [0:10] shortens it to "Tue Apr 30" #write the start and end date to single file (the LCD code will use this so it can read the dates quickly and easily) dates = {"startDate": startDate.strftime("%c")[0:10], "endDate": endDate.strftime("%c")[0:10], "cycleStatus": "in use"} with open("dates.json", "w") as outfile: json.dump(dates, outfile) ####################################################################################### #turn on green LED to indicate the grow cycle has started #and #tell the data in the website that the mushrooms are currently in the chamber for the three week cycle ####################################################################################### relay.relayOnOff(greenLEDPin, "on") writeDate.addDateToData(cycleStatus, "in use") #the website can use this ####################################################################################### #Continuous loop while mushrooms sit in the chamber (just sunlight LED control) ####################################################################################### daysPast = 0 while daysPast < 3*7: #until 3 weeks have past, keep turning on and off the sunlight in this loop hour = 60*60 #one hour in seconds onTime = 18 * hour # on time is 18 hours offTime = 6 * hour # off time is 6 hours #turn on sunlight (uses inverted logic because of relay) relay.relayOnOff(sunlightPin, "off") time.sleep(onTime)
#if the growth cycle is taking place, display this to the LCD screen if dates["cycleStatus"].lower() == "in use": LCDLinesDuringGrowCycle(humidity,temperature, dates) #if the growth cycle is taking place, display this to the LCD screen elif dates["cycleStatus"].lower() == "waiting for next batch": LCDLinesNotDuringGrowCycle(humidity,temperature, dates) #if the temp is out of range if temperature > tempMax or temperature < tempMin: #turn on the red indicator (warning) LED relay.relayOnOff(redLEDPin, "on") #check how long its been out of range in seconds timeOutOfRange = time.time() - startTime #if its been out of range for an hour... if timeOutOfRange > 3600: message =""" Subject: Temperature Out Of Range The mushroom chamber temperature has been out of range for an hour """ + "The current temperature is: " + str(temperature) + " F" #send email sendEmail.sendEmail(emailRecipients, message)
#if the humidifier is already off else: #don't do anything pass #rest the Pi time.sleep(delay) #take another measurement humidity, temperature = DHT22.humidityAndTempCheck(humidityInputPin) #if the humidity is out of range if humidity < humidMin: #turn on the red indicator (warning) LED relay.relayOnOff(yellowLEDPin, "on") #check how long its been out of range in seconds timeOutOfRange = time.time() - startTime #if its been out of range for an hour... if timeOutOfRange > 3600: message = """ Subject: Humidity Out Of Range The mushroom chamber humidity has been out of range for an hour """ + "The current temperature is: " + str(humidity) + " %" #send email sendEmail.sendEmail(emailRecipients, message)