Example #1
0
#Declaring variable relay_proc
relay_proc = None

#Declaring variable logsaved
logsaved = 0

try:

    #Time checking loop that starts irrigation at set times
    while True:

        #Checking to see what time it is and starts the subprocess if it should
        now = datetime.now()
        now_time = now.time()
        nirrigated = dbfetch('NIGHT_IRRIGATED', 'weather_settings')
        dirrigated = dbfetch('DAY_IRRIGATED', 'weather_settings')
        nirriseconds = dbfetch('NIGHT_SECONDS', 'weather_settings')

        if now_time >= time(01, 00) and now_time < time(02, 00):
            #Start subprocess if irrigation hasn't been done yet
            if nirrigated == 0:
                print("Time for some irrigation!")
                try:

                    if relay_proc is not None and relay_proc.poll() is None:
                        print('process is already running')
                    else:
                        relay_proc = subprocess.Popen(
                            ['/home/pi/GardenBrain/relay.py'],
                            stdout=subprocess.PIPE,
Example #2
0
        #Getting pressure from the SenseHat and printing the value
        pressure = sense.get_pressure()
        pressure = round(pressure, 1)
        print("Pressure:", pressure)
        time.sleep(1)

        #Showing weather data on the LED matrix (optional)
        #sense.show_message("  Temperature " + str(temp) + "C" + "  Humidity: " + str(humidity) + "%" + "  Pressure: " + str(pressure) + "hPA", scroll_speed=(0.08), text_colour=[102,0,204])

        #Clearing any data from the SenseHat
        sense.clear()

        #If fetching current pressure and humidity fails, then use previous entry in database (to remove incorrect zeros in the data)
        if pressure == 0:
            pressure = dbfetch("PRESSURE", "weather_date")
            dolog(
                "Weather.py - Failed to get current pressure, instead using the pressure from previous entry in database"
            )

        if humidity == 0:
            humidity = dbfetch("HUMIDITY", "weather_date")
            dolog(
                "Weather.py - Failed to get current humidity, instead using the humidity from previous entry in database"
            )

#Connecting to database again and writing the data into the weather_data table
#db_wd_insert(time.strftime("%Y-%m-%d %H:%M"),str(temp),str(humidity),str(pressure))
        db = MySQLdb.connect(config['database']['host'],
                             config['database']['user'],
                             config['database']['password'],
Example #3
0
# Import required Python libraries
import time as t
from datetime import datetime, time
from functions import dbfetch,dbupdate,relay_delay,relay_manual,dolog

#Checking to see what time it is for the following functions
now = datetime.now()
now_time = now.time()

#Sleeping for a moment
t.sleep(15)

#Getting data for the delay variable which determines how long the relay stays open
if now_time >= time(01,00) and now_time <= time(02,00):
    delay = dbfetch('NIGHT_SECONDS','weather_settings')
    dolog("NIGHT_SECONDS received from database in relay.py :")
    dolog(delay)
elif now_time >= time(16,00) and now_time <= time(17,00):
    delay = dbfetch('DAY_EXTRA','weather_settings')
    dolog("DAY_EXTRA received from database in relay.py :")
    dolog(delay)
else:
    #Setting delay to a default 60 seconds if the script is run outside of the set timeframes
    delay = 60

#If delay variable is not 0
if delay != 0:
    
    #Starting the delay
    relay_manual('on')
Example #4
0
#Sleeping for a second
t.sleep(1)

#Declaring variable relay_proc
relay_proc = None

try:

    #Time checking loop that starts irrigation at set times
    while True:

        #Checking to see what time it is and starts the subprocess if it should
        now = datetime.now()
        now_time = now.time()
        nirrigated = dbfetch('NIGHT_IRRIGATED', 'weather_settings')
        dirrigated = dbfetch('DAY_IRRIGATED', 'weather_settings')

        if now_time >= time(01, 00) and now_time < time(02, 00):
            #Start subprocess if irrigation hasn't been done yet
            if nirrigated == 0:
                print("Time for some irrigation!")
                try:
                    # Old part that was buggy
                    # p = subprocess.Popen(['/home/pi/GardenBrain/relay.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

                    if relay_proc is not None and relay_proc.poll() is None:
                        print('process is already running')
                    else:
                        relay_proc = subprocess.Popen(
                            ['/home/pi/GardenBrain/relay.py'],
        dolog("Analyzer.py - Weather data received from database")

        #Sleeping for a second
        t.sleep(1)

        #Get the average temperature, humidity and pressure for those 15 minutes
        temp_average = averager(temperature)
        humid_average = averager(humidity)
        press_average = averager(pressure)
        dolog("Analyzer.py - Weather data averaged")

        #Sleeping for a second
        t.sleep(1)

        #Read database if irrigation has been done and if so, then make sure the minutes number is reset to 0
        nighti = dbfetch('NIGHT_IRRIGATED', 'weather_settings')
        dayi = dbfetch('DAY_IRRIGATED', 'weather_settings')
        if nighti == 1:
            dbupdate('NIGHT_SECONDS', 'weather_settings', '0')
            dolog(
                "Analyzer.py - Updating NIGHT_SECONDS to value 0 in database")

        if dayi == 1:
            dbupdate('DAY_EXTRA', 'weather_settings', '0')
            dolog("Analyzer.py - Updating DAY_EXTRA to value 0 in database")

        #Sleeping for a second
        t.sleep(1)

        #Set a baseline for temperature, with adjustments depending on humidity and pressure, then make sure each run of this script adds to a starting 0 minutes of night irrigation until it runs. During a full 24h this will build up to around 100 times the 15 minute number.
# Import required Python libraries
from datetime import datetime, time
import MySQLdb
import RPi.GPIO as GPIO
import time
from functions import dbfetch, dbupdate, dolog, relay_manual, relay_delay, sysreboot, mandiff
import logging

#Sleeping for 1 seconds
time.sleep(1)

#Running a loop to check for scheduled tasks
while True:

    #Getting settings table from DB
    irrigatedata = dbfetch('IRRIGATE_NOW', 'weather_settings')
    rebootdata = dbfetch('REBOOTNOW', 'weather_settings')
    if irrigatedata == 3:
        difference = mandiff()
        if difference / 60 > 5:
            irrigatedata = 2
        else:
            print("Time doesn't exceed 5 minutes")

    if irrigatedata == 1:
        dbupdate('IRRIGATE_NOW', 'weather_settings', '3')
        print("Irrigating now")
        nowtime = time.strftime("%Y-%m-%d %H:%M:%S")
        dbupdate('MANTIME', 'weather_settings', str(nowtime))
        relay_manual('on')