Example #1
0
import nebula

ON = 0
OFF = 1

# Load configuration YAML
path = os.path.dirname(os.path.realpath(__file__))
fp = open(path + '/config.yaml', 'r')
cfg = yaml.load(fp)

# Set up Nebula API client
nebula_client = nebula.Client(**cfg['nebula'])
nebula_client.set_level('WARNING')

# Set up Guard House Arduino client
arduino_client = arduino.Client(**cfg['guardhouse'])


def is_int(s):
    try:
        int(s)
        return True
    except ValueError:
        return False


if len(sys.argv) > 1:
    if 'off' in sys.argv[1]:
        if arduino_client.set_value('water_mode', OFF):
            nebula_client.info('Sprinklers manually disabled')
        else:
Example #2
0
def arduino_client(ip):
    return arduino.Client(ip)
import arduino

my_arduino = arduino.Client('http://192.168.1.112/')

print('Welcome to SmartHouseController')
while True:
    command = input('Please input your command: ')
    if command == 'l':
        print('[r] Read value')
        print('[w] Write value')
        print('[q] Exit program')
        print('[l] List of commands')
    elif command == 'r':
        vars = my_arduino.get_all()
        i = 0
        for var in sorted(vars):
            i += 1
            print('[%d] %s (%.2f)' % (i, var, vars[var]))
    elif command == 'w':
        vars = my_arduino.get_all()
        i = 0
        for var in sorted(vars):
            i += 1
            print('[%d] %s (%.2f)' % (i, var, vars[var]))
        id = input('Which variable do you want to write? ')
        if id == 0:
            print(my_arduino.get_all())
        else:
            new_value = input('What value do you want to write? ')
            my_arduino.set_value(list(vars)[int(id) - 1], new_value)
    elif command == 'q':
Example #4
0
def test_code():
    arduino_client = arduino.Client('192.168.1.112')
    if arduino_client.get_value('rain') is None:
        print('Failed to read from Guard House API')
    else:
        print(arduino_client.get_value('rain'))