예제 #1
0
def schedule_edit(schedule, new=False):
    print(schedule)
    sqlConn = SqlHelper()
    sqlStr = """UPDATE schedule SET
        startdate={0},
        enddate={1},
        sunday={2},
        monday={3},
        tuesday={4},
        wednesday={5},
        thursday={6},
        friday={7},
        saturday={8},
        starttime={9},
        duration={10},
        repeating={11},
        station={12}
    WHERE id={13}""".format(schedule['startdate'], schedule['enddate'],
                            schedule['sunday'], schedule['monday'],
                            schedule['tuesday'], schedule['wednesday'],
                            schedule['thursday'], schedule['friday'],
                            schedule['saturday'], schedule['starttime'],
                            schedule['duration'], schedule['repeat'],
                            schedule['station'], schedule['id'])
    print(sqlStr)
    sqlConn.execute(sqlStr)
예제 #2
0
def station_edit(station):
    sqlConn = SqlHelper()
    sqlStr = """UPDATE stations SET
        gpio='{0}',
        notes='{1}'
        WHERE id={2}""".format(station['gpio_pin'], station['notes'],
                               station['sid'])
    print(sqlStr)
    sqlConn.execute(sqlStr)
예제 #3
0
 def add(self, gpio_pin, notes=''):
     sqlConn = SqlHelper()
     try:
         self.gpio_pin = gpio_pin
         self.notes = notes
         sqlStr = '''INSERT INTO stations (ID, GPIO, NOTES) VALUES ({0}, {1}, \'{2}\')'''.format(
             self.sid, self.gpio_pin, self.notes)
         sqlConn.execute(sqlStr)
     except Exception as e:
         raise e
예제 #4
0
def add_or_edit_station_nodes(dripnode, new=False):
    sqlConn = SqlHelper()
    sqlStr = ""
    if new:
        sqlStr = """
            INSERT INTO dripnodes (gph, sid, count) VALUES ({0},{1},{2})
        """.format(dripnode['gph'], dripnode['sid'], dripnode['count'])
    else:
        sqlStr = """
            UPDATE dripnodes SET gph={0}, sid={1}, count={2} WHERE id={3}
        """.format(dripnode['gph'], dripnode['sid'], dripnode['count'],
                   dripnode['id'])
    sqlConn.execute(sqlStr)
예제 #5
0
def dripnodes_edit(nodes_data, new=False, delete=False):
    sqlConn = SqlHelper()
    sqlStr = ""
    if new:
        sqlStr = """
            INSERT INTO dripnodes (gph, sid, count) VALUES ({0}, {1}, {2});
        """.format(nodes_data['gph'], nodes_data['sid'], nodes_data['count'])
    elif delete:
        sqlStr = """
            DELETE FROM dripnodes WHERE gph={0} AND sid={1}
        """.format(nodes_data['gph'], nodes_data['sid'])
    else:
        sqlStr = """
            UPDATE dripnodes SET gph={0}, sid={1}, count={2} WHERE sid={1} and gph={0};
        """.format(nodes_data['gph'], nodes_data['sid'], nodes_data['count'])
    sqlConn.execute(sqlStr)
예제 #6
0
class RelayController:
    def __init__(self):
        self.sqlConn = SqlHelper()
        self.__setup_pins()

    def __setup_pins(self):
        pins = []
        sqlStr = """SELECT gpio FROM gpio_pins"""
        for pin in self.sqlConn.read(sqlStr):
            pins.append(pin[0])
        GPIO.setmode(GPIO.BCM)
        for pin in pins:
            GPIO.setup(pin,
                       GPIO.OUT,
                       initial=CONFIG.SETTINGS['GPIO_RELAY_OFFSTATE'])

    def __reset(self):
        GPIO.setmode(GPIO.BCM)
        self.__setup_pins

    def __log_relay_activity(self, sid, duration, schedule_id):
        sqlStr = """ INSERT INTO history (sid, schedule_id, duration, starttime)
        VALUES ({0},{1},{2},'{3}')""".format(sid, schedule_id, duration,
                                             datetime.now())
        self.sqlConn.execute(sqlStr)

    def __get_gpio_from_sid(self, sid):
        sqlStr = """ SELECT gpio FROM stations WHERE id={0}""".format(sid)
        gpio = self.sqlConn.read(sqlStr)[0]
        return gpio

    def activate_relay(self, sid, duration, schedule_id=0):
        pin = self.__get_gpio_from_sid(sid)
        self.__log_relay_activity(sid, duration, schedule_id)

        timer = 0
        GPIO.output(pin, CONFIG.SETTINGS['GPIO_RELAY_ONSTATE'])
        GPIO.output(CONFIG.SETTINGS['COMMON_WIRE_GPIO'],
                    CONFIG.SETTINGS['GPIO_RELAY_ONSTATE'])
        while timer < duration:
            sleep(1)
            timer += 1
        GPIO.output(pin, CONFIG.SETTINGS['GPIO_RELAY_OFFSTATE'])
        GPIO.output(CONFIG.SETTINGS['COMMON_WIRE_GPIO'],
                    CONFIG.SETTINGS['GPIO_RELAY_OFFSTATE'])
예제 #7
0
def schedule_add(schedule):
    print(schedule)
    sqlConn = SqlHelper()
    sqlStr = """INSERT INTO schedule (
            startdate,
            enddate,
            sunday,
            monday,
            tuesday,
            wednesday,
            thursday,
            friday,
            saturday,
            starttime,
            duration,
            repeating,
            station
        ) VALUES (
            {0},
            {1},
            {2},
            {3},
            {4},
            {5},
            {6},
            {7},
            {8},
            {9},
            {10},
            {11},
            {12})""".format(schedule['startdate'], schedule['enddate'],
                            schedule['sunday'], schedule['monday'],
                            schedule['tuesday'], schedule['wednesday'],
                            schedule['thursday'], schedule['friday'],
                            schedule['saturday'], schedule['starttime'],
                            schedule['duration'], schedule['repeat'],
                            schedule['station'])
    print(sqlStr)
    sqlConn.execute(sqlStr)
예제 #8
0
def delete_station_node(id):
    sqlConn = SqlHelper()
    sqlStr = """
        DELETE FROM dripnodes WHERE id={0}
    """.format(id)
    sqlConn.execute(sqlStr)
예제 #9
0
def schedule_delete(schedule_id):
    sqlConn = SqlHelper()
    sqlStr = """DELETE FROM schedule WHERE id={0}""".format(schedule_id)
    sqlConn.execute(sqlStr)