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