This is a useless commit message
This commit is contained in:
parent
6732c483cd
commit
b7a58675c6
@ -1,19 +1,17 @@
|
||||
import time
|
||||
import datetime
|
||||
import smtplib
|
||||
import configparse
|
||||
import math
|
||||
from email.mime.text import MIMEText
|
||||
import smtplib
|
||||
import time
|
||||
from datetime import datetime
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
import requests
|
||||
from microstacknode.hardware.accelerometer.mma8452q import MMA8452Q
|
||||
|
||||
|
||||
EMAIL_USERNAME = 'noreply@ianonavy.com'
|
||||
EMAIL_PASSWORD = 'S2PENjQbO6=cHgchw@CXs.bJ'
|
||||
RECIPIENT_EMAILS = [
|
||||
'ianonavy@gmail.com', 'dmurvihill@gmail.com',
|
||||
'5038304363@tmomail.net'
|
||||
]
|
||||
RECIPIENT_EMAILS = ['ianonavy@gmail.com']
|
||||
ALERT_EMAIL_TEXT = """Hi,
|
||||
|
||||
Your laundry is done. Or maybe your roomate's. I don't know.
|
||||
@ -25,7 +23,7 @@ G_RANGE = 2
|
||||
INTERVAL = 0.005 # seconds
|
||||
WINDOW_SIZE = 40 # intervals
|
||||
THRESHOLD = 0.003 # G's
|
||||
MAX_EMAIL_FREQUENCY = 60 # seconds
|
||||
MAX_NOTIFICATION_FREQUENCY = 60 # seconds
|
||||
|
||||
|
||||
def average(s):
|
||||
@ -75,16 +73,24 @@ def amplitude_stdev(sliding_window):
|
||||
return standard_deviations
|
||||
|
||||
|
||||
def send_emails(last_email_sent_at):
|
||||
print((datetime.now() - last_email_sent_at).seconds) # for debugging
|
||||
# limit frequency of emails
|
||||
if (datetime.now() - last_email_sent_at).seconds > MAX_EMAIL_FREQUENCY:
|
||||
def send_notifications(last_notification_sent_at, iftttkey):
|
||||
seconds_since_last_notification = \
|
||||
(datetime.now() - last_notification_sent_at).seconds
|
||||
# Log the time notifications were sent
|
||||
print(seconds_since_last_notification)
|
||||
# limit frequency of notifications
|
||||
if seconds_since_last_notification > MAX_NOTIFICATION_FREQUENCY:
|
||||
[notify_user(email) for email in RECIPIENT_EMAILS]
|
||||
# Notify if this, then that
|
||||
requests.get('https://maker.ifttt.com/trigger/{event}/with/key/%s'
|
||||
% iftttkey)
|
||||
return datetime.now()
|
||||
return last_email_sent_at
|
||||
return last_notification_sent_at
|
||||
|
||||
|
||||
def main():
|
||||
config = configparser.ConfigParser().read('laundry_notifier.conf')
|
||||
iftttkey = config['notifications']['ifttt_key']
|
||||
with MMA8452Q() as accelerometer:
|
||||
# Configure accelerometer
|
||||
accelerometer.standby()
|
||||
@ -96,7 +102,7 @@ def main():
|
||||
|
||||
sliding_window = []
|
||||
dryer_state = 'off'
|
||||
last_email_sent_at = datetime(1970, 1, 1, 0, 0, 0)
|
||||
last_notification_sent_at = datetime(1970, 1, 1, 0, 0, 0)
|
||||
|
||||
while True:
|
||||
g_values = accelerometer.get_xyz()
|
||||
@ -107,7 +113,9 @@ def main():
|
||||
if g_values:
|
||||
if sliding_stdev['x'] < THRESHOLD:
|
||||
if dryer_state == 'on':
|
||||
last_email_sent_at = send_emails(last_email_sent_at)
|
||||
last_notification_sent_at = send_notifications(
|
||||
last_notification_sent_at,
|
||||
iftttkey)
|
||||
dryer_state = 'off'
|
||||
else:
|
||||
dryer_state = 'on'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user