예제 #1
0
def checktemp():
    while True:
        global humidity
        global temperature
        humidity, temperature = Adafruit_DHT.read_retry(11, 4)
        print 'Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity)
        lcd.show('Temperat: {0:0.1f} C'.format(temperature),'Humidity: {0:0.1f} %'.format(humidity))
        time.sleep(0.5)
예제 #2
0
파일: tmon.py 프로젝트: on1dds/tmon
def signal_handler(sig, frame):
    """ cleanup on exit """
    print('You pressed Ctrl+C!')
    if log:
        log.close()
    sensors.Sensor.exitapp = True
    print "awaiting threads to stop"
    while threading.active_count() > 1:
        time.sleep(0.1)
    GPIO.output(LED_OK, False)
    GPIO.output(LED_ERROR, False)
    lcd.show("", "")
    GPIO.cleanup()

    sys.exit(0)
예제 #3
0
파일: tmon.py 프로젝트: on1dds/tmon
def show_status():
    """ show sensors status or alerts on lcd display """
    global btn_info_ispressed, error_index
    global timer_lcd, timer_errdisp
    global status_index

    # check press on up button
    if not btn_info_ispressed:
        if GPIO.input(BTN_INFO):
            btn_info_ispressed = True
            timer_errdisp = now
            error_index += 1
    else:
        btn_info_ispressed = GPIO.input(BTN_INFO)

    # show errors on lcd
    if now < (timer_errdisp + DELAY_ERRDISP):
        errorlist = get_errorlist()

        if len(errorlist) > 0:
            error_index %= len(errorlist)
            lcd.show(errorlist[error_index].name, errorlist[error_index].msg)

    # show status on lcd
    elif now > timer_lcd:
        error_index = 0
        while now > timer_lcd:
            timer_lcd += DELAY_DISPLAY
        _list = sensors.getlist('Thermometer')
        if status_index < len(_list):
            _sensor = _list[status_index]
            _msg = str(round(_sensor.value, 1)) + \
                    chr(223) + " " + _sensor.name
            status_index += 1
        else:
            _msg = getipaddress()
            status_index = 0
        lcd.show("tmon " + __version__, _msg)
예제 #4
0
def send_sms(to, message):
    """ does what it says """
    twilio = cfg['twilio']
    if DEBUG:
        print("ERROR: " + to + ":"+message)
        return True
        
    try:
        account = twilio['account_sid']
        token= twilio['auth_token']
        client = TwilioRestClient(account,token)
        
        client.messages.create(
            to= to, 
            from_= twilio['number'], body= message)
    except twilio.rest.exceptions.TwilioRestException:
        lcd.show(to, "not SMS capable")
        return False

    except twilio.rest.exceptions:
        lcd.show("Error:","Twilio SMS fault")
        return False

    return True
예제 #5
0
    def __init__(self, db_server, db_name, db_user, db_pass, db_expire):
        self.cursor = None
        self.db = None
        self.cursor = None
        self.expire = int(db_expire)

        # create database object
        try:
            self.db = MySQLdb.connect(db_server, db_user, db_pass)
            self.cursor = self.db.cursor()
        except MySQLdb.Warning as e:
            lcd.show("DB open warning", "OK")
        except MySQLdb.Error as e:
            lcd.show("DB open failed:", "TMON Stopped")
            sys.exit(1)

        # create database
        try:
            self.cursor.execute("CREATE DATABASE IF NOT EXISTS tmon")
            self.cursor.execute("USE " + db_name)
        except MySQLdb.Warning as e:
            lcd.show("DB create warn", "OK")
        except MySQLdb.Error as e:
            lcd.show("DB create fault:", "Failed")
            self.db.rollback()
            self.db.close()
            sys.exit(1)

        # create log table
        try:
            self.cursor.execute(("CREATE TABLE IF NOT EXISTS log("
                                 "id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,"
                                 "timestamp DATETIME,"
                                 "type CHAR(1),"
                                 "sensor VARCHAR(20),"
                                 "value DECIMAL(4,1)"
                                 ") "))
        except MySQLdb.Warning as e:
            lcd.show("DB create table", "OK")
        except MySQLdb.Error as e:
            lcd.show("DB new table", "Failed: Stopped")
            self.db.rollback()
            self.db.close()
            sys.exit(1)
예제 #6
0
def addInfo():
    global temperature
    global humidity
    while True:
        time.sleep(10)
        os.system("/usr/bin/curl -k -s http://127.0.0.1/insert/temp/{0:0.1f}/hum/{1:0.1f} > /dev/null".format(temperature, humidity))

def sendemail():
   time.sleep(10)
   os.system("/usr/bin/curl -k -s http://127.0.0.1/sendemail > /dev/null")

def checktemp():
    while True:
        global humidity
        global temperature
        humidity, temperature = Adafruit_DHT.read_retry(11, 4)
        print 'Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity)
        lcd.show('Temperat: {0:0.1f} C'.format(temperature),'Humidity: {0:0.1f} %'.format(humidity))
        time.sleep(0.5)

#Start Main
try:
	main()
except KeyboardInterrupt:
	pass
finally:
	alarm.stop()
	lcd.show('Termostato','parado')


예제 #7
0
def conway_go(num_frames):
    for i in range(num_frames):
        conway_step()           # do 1 iteration
        lcd.show()              # update the LCD
        pyb.delay(300)
예제 #8
0
파일: conwaylife.py 프로젝트: zzambia/f32c
def conway_go(num_frames):
    for i in range(num_frames):
        conway_step()  # do 1 iteration
        lcd.show()  # update the LCD
        pyb.delay(300)
예제 #9
0
파일: tmon.py 프로젝트: on1dds/tmon
# *****************************************************
#  main
# *****************************************************

# initialize
check_cfg()

# init GPIO for thermometers
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

signal.signal(signal.SIGINT, signal_handler)

gpio_init()
lcd.init()
lcd.show("tmon " + __version__, "initializing ...")
sensors.create()

# check for IP address
_count = 0
while not getipaddress():
    _count = _count+1
    time.sleep(1)
    lcd.show("start delayed","waiting for IP")
    if _count > 10:
        lcd.writeline("err: No IP", 2)
        terminate("No IP address was found")

lcd.writeline(getipaddress(), 2)

# hold execution while info button is pressed
예제 #10
0
파일: db.py 프로젝트: on1dds/tmon
    def __init__(self, db_server, db_name, db_user, db_pass, db_expire):
        self.cursor = None
        self.db = None
        self.cursor = None
        self.expire = int(db_expire)

        # create database object
        try:
            self.db = MySQLdb.connect(db_server, db_user, db_pass)
            self.cursor = self.db.cursor()
        except MySQLdb.Warning as e:
            lcd.show("DB open warning", "OK")
        except MySQLdb.Error as e:
            lcd.show("DB open failed:", "TMON Stopped")
            sys.exit(1)

        # create database
        try:
            self.cursor.execute("CREATE DATABASE IF NOT EXISTS tmon")
            self.cursor.execute("USE " + db_name)
        except MySQLdb.Warning as e:
            lcd.show("DB create warn", "OK")
        except MySQLdb.Error as e:
            lcd.show("DB create fault:", "Failed")
            self.db.rollback()
            self.db.close()
            sys.exit(1)

        # create log table
        try:
            self.cursor.execute((
                "CREATE TABLE IF NOT EXISTS log("
                "id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,"
                "timestamp DATETIME,"
                "type CHAR(1),"
                "sensor VARCHAR(20),"
                "value DECIMAL(4,1)"
                ") "))
        except MySQLdb.Warning as e:
            lcd.show("DB create table", "OK")
        except MySQLdb.Error as e:
            lcd.show("DB new table", "Failed: Stopped")
            self.db.rollback()
            self.db.close()
            sys.exit(1)