-
-
Save axce1/f520a7c6e440301f0cee to your computer and use it in GitHub Desktop.
Revisions
-
abulte revised this gist
Feb 25, 2013 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Sensor reading, Humidity % 100, 75 200, -
abulte revised this gist
Feb 22, 2013 . 2 changed files with 11 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,10 @@ #!/usr/bin/python # apt-get install screen python python-serial sqlite3 python-pip # pip install pyzmail mail_alerts = True LOW_LIMIT = 80 import serial, time, sqlite3, signal, sys @@ -45,12 +49,13 @@ def grexit(signal, frame): thum = values[5] ts = int(time.time()) # alert every 60 min if mail_alerts and float(thum) < LOW_LIMIT: if ts - previous_alert > 3600: print "Low!" from pyzmail import compose_mail, send_mail payload, mail_from, rcpt_to, msg_id = compose_mail((u'RPI42', '[email protected]'), [(u'Alexandre', '[email protected]')], u'Humidity is low! %s' % thum, 'utf-8', None) error = send_mail(payload, mail_from, rcpt_to, 'smtp.free.fr', smtp_port=25) previous_alert = ts # log every 5 min if ts - previous_ts > 300: Binary file not shown. -
abulte revised this gist
Feb 22, 2013 . 3 changed files with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ Binary file not shown.Binary file not shown. -
abulte revised this gist
Feb 22, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Binary file not shown. -
abulte revised this gist
Feb 22, 2013 . 3 changed files with 66 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ *.db This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ #!/usr/bin/python # apt-get install screen python python-serial sqlite3 import serial, time, sqlite3, signal, sys #EXIT @@ -10,12 +12,13 @@ def grexit(signal, frame): signal.signal(signal.SIGINT, grexit) # create table readings (ts integer, temp real, hum real, humt real); conn = sqlite3.connect('temps_w_tobacco.db') c = conn.cursor() # XRF serialport = '/dev/ttyACM0' #serialport = '/dev/usbdev1.3' baudrate = '9600' ser = serial.Serial(serialport, baudrate) @@ -25,15 +28,34 @@ def grexit(signal, frame): print "Working..." previous_ts = 0 previous_alert = 0 while True: input += ser.read() while input.find("\r\n") != -1: chopped_line = input[:input.find("\r\n")] input = input[input.find("\r\n")+2:] # print chopped_line if chopped_line.find('temperature') != -1: values = chopped_line.split(' ') if len(values) > 4: temp = values[1] rhum = values[3] thum = values[5] ts = int(time.time()) # alert every 60 min if float(thum) < 120: if ts - previous_alert > 3600: # import os print "Low !" # p = os.open('echo "Check the pots!" | mail -s "Low humidity : %s" [email protected]' % thum, 'r') # p.close() previous_alert = ts # log every 5 min if ts - previous_ts > 300: print "Writing in DB." c.execute("INSERT INTO readings VALUES (?, ?, ?, ?)", (ts, temp, rhum, thum)) conn.commit() previous_ts = ts This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/python # apt-get install screen python python-serial sqlite3 import serial, time, sqlite3, signal, sys #EXIT def grexit(signal, frame): # conn.close(); print("Bye.") sys.exit(0) signal.signal(signal.SIGINT, grexit) # XRF serialport = '/dev/ttyACM0' #serialport = '/dev/usbdev1.3' baudrate = '9600' ser = serial.Serial(serialport, baudrate) ser.stopbits = 2 input = '' print "Working..." while True: input += ser.read() while input.find("\r\n") != -1: chopped_line = input[:input.find("\r\n")] input = input[input.find("\r\n")+2:] print chopped_line -
abulte created this gist
Oct 20, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/usr/bin/python import serial, time, sqlite3, signal, sys #EXIT def grexit(signal, frame): # conn.close(); print("Bye.") sys.exit(0) signal.signal(signal.SIGINT, grexit) # create table temps (ts integer, temp real); #conn = sqlite3.connect('temps.db') #c = conn.cursor() serialport = '/dev/ttyAMA0' #serialport = '/dev/usbdev1.4' baudrate = '9600' ser = serial.Serial(serialport, baudrate) ser.stopbits = 2 input = '' print "Working..." while True: input += ser.read() while input.find("\r\n") != -1: chopped_line = input[:input.find("\r\n")] input = input[input.find("\r\n")+2:] print chopped_line if chopped_line.find('degrees') != -1: temp = chopped_line.split(' ')[0] ts = int(time.time()) #c.execute("INSERT INTO temps VALUES (?, ?)", (ts, temp)) #conn.commit()