Skip to content

Instantly share code, notes, and snippets.

@axce1
Forked from abulte/.gitignore
Last active August 29, 2015 14:20
Show Gist options
  • Save axce1/f520a7c6e440301f0cee to your computer and use it in GitHub Desktop.
Save axce1/f520a7c6e440301f0cee to your computer and use it in GitHub Desktop.

Revisions

  1. @abulte abulte revised this gist Feb 25, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions humidity_mapping.csv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Sensor reading, Humidity %
    100, 75
    200,
  2. @abulte abulte revised this gist Feb 22, 2013. 2 changed files with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions monitor_serial.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    #!/usr/bin/python

    # apt-get install screen python python-serial sqlite3
    # 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 float(thum) < 120:
    if mail_alerts and float(thum) < LOW_LIMIT:
    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()
    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 modified temps_w_tobacco.db
    Binary file not shown.
  3. @abulte abulte revised this gist Feb 22, 2013. 3 changed files with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion .gitignore
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    *.db
    Binary file added temps.db
    Binary file not shown.
    Binary file added temps_w_tobacco.db
    Binary file not shown.
  4. @abulte abulte revised this gist Feb 22, 2013. 1 changed file with 0 additions and 0 deletions.
    Binary file added salon.db
    Binary file not shown.
  5. @abulte abulte revised this gist Feb 22, 2013. 3 changed files with 66 additions and 11 deletions.
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    *.db
    44 changes: 33 additions & 11 deletions monitor_serial.py
    Original 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 temps (ts integer, temp real);
    #conn = sqlite3.connect('temps.db')
    #c = conn.cursor()
    # create table readings (ts integer, temp real, hum real, humt real);
    conn = sqlite3.connect('temps_w_tobacco.db')
    c = conn.cursor()

    serialport = '/dev/ttyAMA0'
    #serialport = '/dev/usbdev1.4'
    # 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('degrees') != -1:
    temp = chopped_line.split(' ')[0]
    ts = int(time.time())
    #c.execute("INSERT INTO temps VALUES (?, ?)", (ts, temp))
    #conn.commit()
    # 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

    32 changes: 32 additions & 0 deletions read_serial.py
    Original 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
  6. @abulte abulte created this gist Oct 20, 2012.
    39 changes: 39 additions & 0 deletions monitor_serial.py
    Original 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()