# DHSB Entry # Import gpio library import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) # Import datetime library from datetime import datetime, time now = datetime.now() now_time = now.time() #Import email lib import smtplib server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login("dhsbpillbox@gmail.com", "passwdRedacted") # Input pin GPIO.setup(15, GPIO.IN) # Pin 13 output 3v GPIO.setup(13, GPIO.OUT) GPIO.output(13, GPIO.HIGH) # Pin 15 goes high when box is open and check time is allowed # Check if pill was taken within parameters of 10.30 to 14.30 breaker = "true" while not (GPIO.input (15)): while now_time >= time(10,30) and now_time <= time(15,30) and breaker is "true" : print "within time period" msg = "Patient took pill at the correct time!" server.sendmail("dhsbpillbox@gmail.com", "carer.email@example.com", msg) server.quit() print ("Message sent") # Stops the while loop breaker = "false" else: if (breaker is "true"): print "outside of time period" msg = "Patient took pill at the wrong time!" server.sendmail("dhsbpillbox@gmail.com", "carer.email@example.com", msg) server.quit() break else: break else: print "box is closed"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question