Exemplo n.º 1
0
def sprinkler():
    command = request.form['command']
    if(command == "ON"):
        pytronics.digitalWrite(2, 'HIGH')
    else:
        pytronics.digitalWrite(2, 'LOW')
    return ('Sprinkler toggled')
Exemplo n.º 2
0
def flash_led():
    if pytronics.digitalRead('LED') == '1':
        pytronics.digitalWrite('LED', 'LOW')
        message = "LED off"
    else:
        pytronics.digitalWrite('LED', 'HIGH')
        message = "LED on"
    return (message)
Exemplo n.º 3
0
def flash_led():
    if pytronics.digitalRead('LED') == '1':
        pytronics.digitalWrite('LED', 'LOW')
        message = "LED off"
    else:
        pytronics.digitalWrite('LED', 'HIGH')
        message = "LED on"
    return (message)
Exemplo n.º 4
0
def digital_toggle(pin_name):
    if pin_name in DIGITAL_PINS:
        if str(pytronics.digitalRead(pin_name)) == '1':
            pytronics.digitalWrite(pin_name, 'LOW')
            return 'Set pin {0} to LOW'.format(pin_name)
        else:
            pytronics.digitalWrite(pin_name, 'HIGH')
            return 'Set pin {0} to HIGH'.format(pin_name)
    else:
        return DIGITAL_PIN_NAME_ERROR.format(pin_name)
Exemplo n.º 5
0
def toggle():
    if(request.form['target_state'] == '1'):
        pytronics.digitalWrite(2, 'HIGH')
        result = 'Pins set high'
    elif(request.form['target_state'] == '0'):
        pytronics.digitalWrite(2, 'LOW')
        result = 'Pins set low'
    else:
        result = 'Target_state is screwed up'
    return result
Exemplo n.º 6
0
def digital_toggle(pin_name):
    if pin_name in DIGITAL_PINS:
        if pytronics.digitalRead(pin_name) == '1':
            pytronics.digitalWrite(pin_name, 'LOW')
            return 'Set pin {0} to LOW'.format(pin_name)
        else:
            pytronics.digitalWrite(pin_name, 'HIGH')
            return 'Set pin {0} to HIGH'.format(pin_name)
    else:
        return DIGITAL_PIN_NAME_ERROR.format(pin_name)
Exemplo n.º 7
0
def update_relay(num):
    import thermostat
    actual = float(thermostat.read_sensor(0x48)) * 1.8 + 32.0
    target = float(thermostat.get_target_temp('/var/www/public/static/basic.ics', 'America/New_York'))
    print("Measured temperature: %f degrees. Target is %f degrees." % (actual, target))
    if actual < target:
        pytronics.digitalWrite(2, 'HIGH')
        print("Heat on")
    else:
        pytronics.digitalWrite(2, 'LOW')
        print("Heat off")
Exemplo n.º 8
0
def update_relay(num):
    import thermostat
    actual = float(thermostat.read_sensor(0x48)) * 1.8 + 32.0
    target = float(thermostat.get_target_temp('/var/www/public/static/basic.ics', 'America/New_York'))
    print("Measured temperature: %f degrees. Target is %f degrees." % (actual, target))
    if actual < target:
        pytronics.digitalWrite(2, 'HIGH')
        print("Heat on")
    else:
        pytronics.digitalWrite(2, 'LOW')
        print("Heat off")
Exemplo n.º 9
0
def pvs_read():
    pytronics.spiSetSpeed(1000000)
    pytronics.pinMode("3", "INPUT")
    pytronics.pinMode("5", "OUTPUT")
    pytronics.digitalWrite("5", "LOW")
    pytronics.digitalWrite("5", "HIGH")
    start = time.time()
    while (time.time() < start + 1000) and (pytronics.digitalRead("4") == "1"):
        pass
    data = pytronics.spiRead(14)
    b = bitstring.BitArray(hex=binascii.hexlify(data))
    return ", ".join([str(5 * float(chunk.int) / 16384) for chunk in b.cut(14)])
Exemplo n.º 10
0
def digital_write_shortcut(pin_name, state):
    if pin_name in DIGITAL_PINS:
        if state.upper() in ['1', 'ON', 'HIGH']:
            pytronics.digitalWrite(pin_name, 'HIGH')
            return 'Set pin {0} to HIGH'.format(pin_name)
        elif state.upper() in ['0', 'OFF', 'LOW']:
            pytronics.digitalWrite(pin_name, 'LOW')
            return 'Set pin {0} to LOW'.format(pin_name)
        else:
            return DIGITAL_PIN_STATE_ERROR.format(pin_name, data)
    else:
        return DIGITAL_PIN_NAME_ERROR.format(pin_name)
Exemplo n.º 11
0
def digital_write_shortcut(pin_name, state):
    if pin_name in DIGITAL_PINS:
        if state.upper() in ['1', 'ON', 'HIGH']:
            pytronics.digitalWrite(pin_name, 'HIGH')
            return 'Set pin {0} to HIGH'.format(pin_name)
        elif state.upper() in ['0', 'OFF', 'LOW']:                       
            pytronics.digitalWrite(pin_name, 'LOW')
            return 'Set pin {0} to LOW'.format(pin_name)
        else:
            return DIGITAL_PIN_STATE_ERROR.format(pin_name, data)
    else:
        return DIGITAL_PIN_NAME_ERROR.format(pin_name)
Exemplo n.º 12
0
def pvs_read():
    pytronics.spiSetSpeed(1000000)
    pytronics.pinMode('3', 'INPUT')
    pytronics.pinMode('5', 'OUTPUT')
    pytronics.digitalWrite('5', 'LOW')
    pytronics.digitalWrite('5', 'HIGH')
    start = time.time()
    while((time.time() < start + 1000) and (pytronics.digitalRead('4') == '1')):
        pass
    data = pytronics.spiRead(14)
    b = bitstring.BitArray(hex=binascii.hexlify(data))
    return ', '.join([str(5*float(chunk.int)/16384) for chunk in b.cut(14)])
Exemplo n.º 13
0
def digital_write(pin_name):
    if pin_name in DIGITAL_PINS:
        data = request.form['data'].upper()
        if data in ['1', 'ON', 'HIGH']:
            pytronics.digitalWrite(pin_name, 'HIGH')
            return 'Set pin {0} to HIGH'.format(pin_name)
        elif data in ['0', 'OFF', 'LOW']:
            pytronics.digitalWrite(pin_name, 'LOW')
            return 'Set pin {0} to LOW'.format(pin_name)
        else:
            return DIGITAL_PIN_STATE_ERROR.format(pin_name, data)
    else:
        return DIGITAL_PIN_NAME_ERROR.format(pin_name)
Exemplo n.º 14
0
def digital_write(pin_name):
    if pin_name in DIGITAL_PINS:
        data = request.form['data'].upper()
        if data in ['1', 'ON', 'HIGH']:
            pytronics.digitalWrite(pin_name, 'HIGH')
            return 'Set pin {0} to HIGH'.format(pin_name)
        elif data in ['0', 'OFF', 'LOW']:
            pytronics.digitalWrite(pin_name, 'LOW')
            return 'Set pin {0} to LOW'.format(pin_name)
        else:
            return DIGITAL_PIN_STATE_ERROR.format(pin_name, data)
    else:
        return DIGITAL_PIN_NAME_ERROR.format(pin_name)
Exemplo n.º 15
0
def update_pin(pin, state):
    try:
        if state.lower() == 'on':
            pytronics.digitalWrite(pin, 'HIGH')
            return 'Set pin %s high' % pin
        elif state.lower() == 'off':                       
            pytronics.digitalWrite(pin, 'LOW')
            return 'Set pin %s low' % pin
        elif state.lower() == 'in':
            pytronics.pinMode(pin,'INPUT')
            return 'Set pin %s input' % pin
        elif state.lower() == 'out':
            pytronics.pinMode(pin,'OUTPUT')
            return 'Set pin %s output' % pin
        return "Something's wrong with your syntax. You should send something like: /pin/2/on"
    except:
        return 'Forbidden', 403
Exemplo n.º 16
0
def update_pin(pin, state):
    try:
        if state.lower() == 'on':
            pytronics.digitalWrite(pin, 'HIGH')
            return 'Set pin %s high' % pin
        elif state.lower() == 'off':                       
            pytronics.digitalWrite(pin, 'LOW')
            return 'Set pin %s low' % pin
        elif state.lower() == 'in':
            pytronics.pinMode(pin,'INPUT')
            return 'Set pin %s input' % pin
        elif state.lower() == 'out':
            pytronics.pinMode(pin,'OUTPUT')
            return 'Set pin %s output' % pin
        return "Something's wrong with your syntax. You should send something like: /pin/2/on"
    except:
        return 'Forbidden', 403
Exemplo n.º 17
0
def digital_write_shortcut(pin_name, state):
    try:
        if pin_name in DIGITAL_PINS:
            data = state.upper()
            if data in ['1', 'ON', 'HIGH']:
                pytronics.digitalWrite(pin_name, 'HIGH')
                return 'Set pin {0} to HIGH'.format(pin_name)
            elif data in ['0', 'OFF', 'LOW']:
                pytronics.digitalWrite(pin_name, 'LOW')
                return 'Set pin {0} to LOW'.format(pin_name)
            elif data in ['IN', 'INPUT']:
                pytronics.pinMode(pin_name, 'INPUT')
                return 'Set pin {0} to INPUT'.format(pin_name)
            elif data in ['OUT', 'OUTPUT']:
                pytronics.pinMode(pin_name, 'OUTPUT')
                return 'Set pin {0} to OUTPUT'.format(pin_name)
            else:
                return DIGITAL_PIN_STATE_ERROR.format(pin_name, data)
        else:
            return DIGITAL_PIN_NAME_ERROR.format(pin_name)
    except Exception, e:
        print '## digital_write_shortcut ## Unexpected error: %s' % str(e)
        return 'Bad request', 400
Exemplo n.º 18
0
def pvs_reset():
    pytronics.pinMode("4", "OUTPUT")
    pytronics.digitalWrite("4", "HIGH")
    pytronics.digitalWrite("4", "LOW")
    return "reset line pulsed high"
Exemplo n.º 19
0
def toggle_pin(pin):
    if pytronics.digitalRead(pin) == '1':
        pytronics.digitalWrite(pin, 'LOW')
    else:
        pytronics.digitalWrite(pin, 'HIGH')
Exemplo n.º 20
0
def pvs_reset():
    pytronics.pinMode('4', 'OUTPUT')
    pytronics.digitalWrite('4', 'HIGH')
    pytronics.digitalWrite('4', 'LOW')
    return 'reset line pulsed high'
Exemplo n.º 21
0
def toggle_pin(pin):
    if pytronics.digitalRead(pin) == '1':
        pytronics.digitalWrite(pin, 'LOW')
    else:
        pytronics.digitalWrite(pin, 'HIGH')