Ejemplo n.º 1
0
def switch_led(state):
    if led_state[GPIO_NUM] != state:
        GPIO.output(GPIO_NUM, not state)  #Low to glow!
        conn.update_status({'state': 'on' if state else 'off'})
        led_state[GPIO_NUM] = state


def on_control_message(conn, key, value):
    if key == 'on_button':
        switch_led(True)
    elif key == 'off_button':
        switch_led(False)


def main_loop():
    switch_led(True)
    while True:
        time.sleep(3)  #Yield for a while but keep main thread running


conn = ControlMyPi(JABBER_ID, JABBER_PASSWORD, SHORT_ID, FRIENDLY_NAME,
                   PANEL_FORM, on_control_message)
if conn.start_control():
    try:
        main_loop()
    finally:
        conn.stop_control()
else:
    print("FAILED TO CONNECT")
Ejemplo n.º 2
0
from time import sleep
import mcp3008
from controlmypi import ControlMyPi
import logging


def on_msg(conn, key, value):
    pass


logging.basicConfig(level=logging.INFO)

p = [
    [['G', 'moist', 'level', 0, 0, 1023]],
]

conn = ControlMyPi('*****@*****.**', 'password3649', 'moisture',
                   'Moisture monitor', p, on_msg)
if conn.start_control():
    try:
        while True:
            m = mcp3008.readadc(5)
            conn.update_status({'moist': m})
            sleep(30)
    finally:
        conn.stop_control()
Ejemplo n.º 3
0
    server.sendmail(sender, recipient, msg + body)
    server.quit()


logging.basicConfig(level=logging.INFO)

p = [
    [['G', 'moist', 'level', 0, 0, 100],
     ['LC', 'chart1', 'Time', 'Value', 0, 100]],
]

c1 = load([])

readings = []

conn = ControlMyPi('*****@*****.**', 'password', 'moisture', 'Moisture monitor',
                   p, on_msg)

delta = datetime.timedelta(minutes=30)
next_time = datetime.datetime.now()

delta_email = datetime.timedelta(days=1)
next_email_time = datetime.datetime.now()

if conn.start_control():
    try:
        while True:
            dt = datetime.datetime.now()
            m = mcp3008.read_pct(5)
            readings.append(m)
            update_lcd(m)
            to_update = {'moist': m}
Ejemplo n.º 4
0
    else:
        print key, value


def main_loop():
    # Block here. When you exit this function the connection to controlmypi.com will be closed
    raw_input("Press Enter to finish\n")


# Setup logging - change the log level here to debug faults
logging.basicConfig(level=logging.ERROR, format='%(levelname)-8s %(message)s')

jid = raw_input("Jabber ID: ")
password = getpass.getpass("Jabber password: "******"Control panel ID: ")
name = raw_input("Control panel name: ")

panel_form = [[['L', 'Echo box:']],
              [['E', 'echobox', 'send'], ['S', 'echo', '-']]]

conn = ControlMyPi(jid, password, id, name, panel_form, on_control_message,
                   'hid', on_registered)
print "Connecting to ControlMyPi..."
if conn.start_control():
    try:
        main_loop()
    finally:
        conn.stop_control()
else:
    print("FAILED TO CONNECT")
Ejemplo n.º 5
0
passMail = 'visualizar'
updateControlMyPi = True
updateEmailSender = False

p = [ 
    [ ['G','moist','level',0,0,100], ['LC','chart1','Time','Value',0,100] ], 
    ]

c1 = load([])

readings = []



if updateControlMyPi:
	conn = ControlMyPi(idMail, passMail, 'moisbanc', 'Sensor de Humedad Bancal', p, on_msg)

delta = datetime.timedelta(minutes=120)
next_time = datetime.datetime.now()

delta_email = datetime.timedelta(days=1)
next_email_time = datetime.datetime.now()

if conn.start_control():
    try:
        while True:
            dt = datetime.datetime.now()
            m = mcp3008.read_pct(3)
            readings.append(m)
            to_update = {'moist':m}
            if(debugMode):