Ejemplo n.º 1
0
def auto_water(toggle):
 running = False
 if toggle == "ON":
 templateData = template(text = "Auto Watering ON")
 for process in psutil.process_iter():
 try:
 if process.cmdline()[1] == 'auto_water.py':
 templateData = template(text = "Already running")
running = True
 except:
 pass
 if not running:
 os.system("python auto_water.py")
 else:
 templateData = template(text = "Auto Watering OFF")
 os.system("pkill -f water.py")
 main.sendAndReceive("Pump Off")
 return render_template('main.html', **templateData)
if __name__ == "__main__":
 app.run(host='0.0.0.0', port=8000, debug=True)
Ejemplo n.º 2
0
def auto_water(delay = 2):
 print("Press CTRL+C to exit")
 try:
 while True:
 print("Entered the loop")
 time.sleep(delay)
 main.sendAndReceive('Led Off')
 main.sendAndReceive('Pump Off')
 storeLastWatered()
 dry = int(main.sendAndReceive('Moisture')) == 0 #True if dry
 print(dry)
 if dry:
 pump_on()
 except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
 main.sendAndReceive('Stop')
def pump_on(delay = 1):
 main.sendAndReceive('Led On')
 main.sendAndReceive('Pump On')
 storeLastWatered()
 time.sleep(delay)
def storeLastWatered():
 f = open("storage/last_watered.txt", "w")
 now = datetime.datetime.now()
 dateString = now.strftime("%A, %d %B %Y %X")
 f.write("Last watered: {}".format(dateString))
 f.close()
Ejemplo n.º 3
0
def action():
 status = int(main.sendAndReceive('Moisture'))
 message = ""
 if (status == 0):
 message = "Water me please!"
 else:
 message = "I'm a happy plant"
 templateData = template(text = message)
 return render_template('main.html', **templateData)
@app.route("/wateron")
def action2():
 water.pump_on()
 print('Pump on')
 templateData = template(text = "Watering...")
 return render_template('main.html', **templateData)
@app.route("/wateroff")
def action3():
 main.sendAndReceive("Pump Off")
 main.sendAndReceive("Led Off")
 print('Pump off')
 templateData = template(text = "Turned OFF")
D-1
 return render_template('main.html', **templateData)
Ejemplo n.º 4
0
def auto_water(delay = 2):
 print("Press CTRL+C to exit")
 try:
 while True:
 print("Entered the loop")
 time.sleep(delay)
 main.sendAndReceive('Led Off')
 main.sendAndReceive('Pump Off')
 storeLastWatered()
 dry = int(main.sendAndReceive('Moisture')) == 0 #True if dry
 print(dry)
 if dry:
 pump_on()
 except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
 main.sendAndReceive('Stop')
def pump_on(delay = 1):
 main.sendAndReceive('Led On')
 main.sendAndReceive('Pump On')
 storeLastWatered()
D-1
 time.sleep(delay)
Ejemplo n.º 5
0
def action3():
 main.sendAndReceive("Pump Off")
 main.sendAndReceive("Led Off")
 print('Pump off')
 templateData = template(text = "Turned OFF")
Ejemplo n.º 6
0
def pump_on(delay = 1):
 main.sendAndReceive('Led On')
 main.sendAndReceive('Pump On')
 storeLastWatered()
 time.sleep(delay)