from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero.tools import all_values
from signal import pause

factory3 = PiGPIOFactory(host='192.168.1.3')
factory4 = PiGPIOFactory(host='192.168.1.4')

led = LED(17)
button_1 = Button(17, pin_factory=factory3)
button_2 = Button(17, pin_factory=factory4)

led.source = all_values(button_1, button_2)

pause()
Exemple #2
0
def main():
    # from picamera import PiCamera
    from gpiozero import LED, Button, MotionSensor
    from gpiozero.tools import all_values, any_values
    from signal import pause
    # import logging
    import json
    import sys

    print('')
    print('# RPiMS is running #')
    print('')

    global redis_db
    redis_db = db_connect('localhost', 0)

    config_yaml = config_load('/var/www/html/conf/rpims.yaml')
    config = config_yaml['setup']
    zabbix_agent = config_yaml['zabbix_agent']
    gpio = config_yaml.get("gpio")

    redis_db.flushdb()
    redis_db.set('gpio', json.dumps(gpio))
    redis_db.set('config', json.dumps(config))
    redis_db.set('zabbix_agent', json.dumps(zabbix_agent))

    get_hostip()
    hostnamectl_sh(**zabbix_agent)

    if bool(config['verbose']) is True:
        for k, v in config.items():
            print(f'{k} = {v}')
        for k, v in zabbix_agent.items():
            print(f'{k} = {v}')
        print('')

    if bool(config['use_door_sensor']) is True:
        global door_sensors_list
        door_sensors_list = {}
        for item in gpio:
            if (gpio[item]['type'] == 'DoorSensor'):
                door_sensors_list[item] = Button(gpio[item]['gpio_pin'],
                                                 hold_time=int(
                                                     gpio[item]['hold_time']))

    if bool(config['use_motion_sensor']) is True:
        global motion_sensors_list
        motion_sensors_list = {}
        for item in gpio:
            if (gpio[item]['type'] == 'MotionSensor'):
                motion_sensors_list[item] = MotionSensor(
                    gpio[item]['gpio_pin'])

    if bool(config['use_system_buttons']) is True:
        global system_buttons_list
        system_buttons_list = {}
        for item in gpio:
            if (gpio[item]['type'] == 'ShutdownButton'):
                system_buttons_list['shutdown_button'] = Button(
                    gpio[item]['gpio_pin'],
                    hold_time=int(gpio[item]['hold_time']))

    global led_indicators_list
    led_indicators_list = {}
    for item in gpio:
        if (gpio[item]['type'] == 'door_led'):
            led_indicators_list['door_led'] = LED(gpio[item]['gpio_pin'])
        if (gpio[item]['type'] == 'motion_led'):
            led_indicators_list['motion_led'] = LED(gpio[item]['gpio_pin'])
        if (gpio[item]['type'] == 'led'):
            led_indicators_list['led'] = LED(gpio[item]['gpio_pin'])

    if bool(config['use_door_sensor']) is True:
        for k, v in door_sensors_list.items():
            if v.value == 0:
                door_status_open(k, **config)
            else:
                door_status_close(k, **config)
        for k, v in door_sensors_list.items():
            v.when_held = lambda s=k: door_action_closed(s, **config)
            v.when_released = lambda s=k: door_action_opened(s, **config)
        if bool(config['use_door_led_indicator']) is True:
            led_indicators_list['door_led'].source = all_values(
                *door_sensors_list.values())

    if bool(config['use_motion_sensor']) is True:
        for k, v in motion_sensors_list.items():
            if v.value == 0:
                motion_sensor_when_no_motion(k, **config)
            else:
                motion_sensor_when_motion(k, **config)
        for k, v in motion_sensors_list.items():
            v.when_motion = lambda s=k: motion_sensor_when_motion(k, **config)
            v.when_no_motion = lambda s=k: motion_sensor_when_no_motion(
                k, **config)
        if bool(config['use_motion_led_indicator']) is True:
            led_indicators_list['motion_led'].source = any_values(
                *motion_sensors_list.values())

    if bool(config['use_system_buttons']) is True:
        system_buttons_list['shutdown_button'].when_held = shutdown

    if bool(config['use_CPU_sensor']) is True:
        threading_function(get_cputemp_data, **config)

    if bool(config['use_BME280_sensor']) is True:
        threading_function(get_bme280_data, **config)

    if bool(config['use_DS18B20_sensor']) is True:
        threading_function(get_ds18b20_data, **config)

    if bool(config['use_DHT_sensor']) is True:
        threading_function(get_dht_data, **config)

    if bool(config['use_weather_station']) is True:
        threading_function(rainfall, **config)
        threading_function(wind_speed, **config)
        threading_function(wind_direction, **config)

    if bool(config['use_serial_display']) is True:
        threading_function(serial_displays, **config)

    if bool(config['use_picamera']) is True and bool(
            config['use_picamera_recording']) is False and bool(
                config['use_door_sensor']) is False and bool(
                    config['use_motion_sensor']) is False:
        av_stream('start')

    pause()
from gpiozero import Button, LED
from gpiozero.tools import all_values
from signal import pause

button_a = Button(2)
button_b = Button(3)
led = LED(17)

led.source = all_values(button_a, button_b)

pause()
Exemple #4
0
from gpiozero import LED, Button
from gpiozero.tools import all_values, any_values, negated
from signal import pause

in_1 = Button(23)
in_2 = Button(15)

out_1 = LED(24)
out_2 = LED(18)
out_3 = LED(14)

out_1.source = all_values(in_1.values, in_2.values)
out_2.source = any_values(in_1.values, in_2.values)
out_3.source = negated(out_1.values)

pause()
from gpiozero import Button, LED
from gpiozero.tools import all_values
from signal import pause

button_a = Button(2)
button_b = Button(3)
led = LED(17)

led.source = all_values(button_a.values, button_b.values)

pause()
Exemple #6
0
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero.tools import all_values
from signal import pause

factory3 = PiGPIOFactory(host='192.168.1.3')
factory4 = PiGPIOFactory(host='192.168.1.4')

led = LED(17)
button_1 = Button(17, pin_factory=factory3)
button_2 = Button(17, pin_factory=factory4)

led.source = all_values(button_1.values, button_2.values)

pause()
Exemple #7
0
def main():
    #from picamera import PiCamera
    from gpiozero import LED, Button, MotionSensor
    from gpiozero.tools import all_values, any_values
    from signal import pause
    #import logging
    import sys

    print('# RPiMS is running #')
    try:
        db_connect('localhost', 0)
    except Exception as err :
        print("Blad połączenia")
        sys.exit(1)

    #redis_db.flushdb()

    for key in redis_db.scan_iter("motion_sensor_*"):
        redis_db.delete(key)
    for key in redis_db.scan_iter("door_sensor_*"):
        redis_db.delete(key)

    config_yaml=config_load('/var/www/html/conf/rpims.yaml')

    config = config_yaml['setup']
    zabbix_agent = config_yaml['zabbix_agent']
    hostnamectl_sh(**zabbix_agent)

    if bool(config['use_door_sensor']) is True:
        global door_sensors_list
        door_sensors_list = {}
        redis_db.delete("door_sensors")
        for item in config_yaml.get("door_sensors"):
            door_sensors_list[item] = Button(config_yaml['door_sensors'][item]['gpio_pin'], hold_time=config_yaml['door_sensors'][item]['hold_time'])
            redis_db.sadd("door_sensors", item)

    if bool(config['use_motion_sensor']) is True:
        global motion_sensors_list
        motion_sensors_list = {}
        redis_db.delete("motion_sensors")
        for item in config_yaml.get("motion_sensors"):
            motion_sensors_list[item] = MotionSensor(config_yaml['motion_sensors'][item]['gpio_pin'])
            redis_db.sadd("motion_sensors", item)

    if bool(config['use_system_buttons']) is True:
        global system_buttons_list
        system_buttons_list = {}
        for item in config_yaml.get("system_buttons"):
            system_buttons_list[item] = Button(config_yaml['system_buttons'][item]['gpio_pin'], hold_time=config_yaml['system_buttons'][item]['hold_time'])

    if bool(config['use_led_indicators']) is True:
        global led_indicators_list
        led_indicators_list = {}
        for item in config_yaml.get("led_indicators"):
            led_indicators_list[item] = LED(config_yaml['led_indicators'][item]['gpio_pin'])

    if bool(config['verbose']) is True :
        print('')

    for s in config :
        redis_db.set(s, str(config[s]))
        if bool(config['verbose']) is True :
            print(s + ' = ' + str(config[s]))

    if bool(config['verbose']) is True :
        print('')

    for s in zabbix_agent :
        redis_db.set(s, str(zabbix_agent[s]))
        if bool(config['verbose']) is True :
            print(s + ' = ' + str(zabbix_agent[s]))

    if bool(config['verbose']) is True :
        print('')

    if bool(config['use_door_sensor']) is True :
        for s in door_sensors_list:
            if door_sensors_list[s].value == 0:
                door_status_open(s,**config)
            else:
                door_status_close(s,**config)
        for s in door_sensors_list:
                door_sensors_list[s].when_held = lambda s=s : door_action_closed(s,**config)
                door_sensors_list[s].when_released = lambda s=s : door_action_opened(s,**config)
        if bool(config['use_led_indicators']) is True :
            led_indicators_list['door_led'].source = all_values(*door_sensors_list.values())

    if bool(config['use_motion_sensor']) is True :
        for s in motion_sensors_list:
            if motion_sensors_list[s].value == 0:
                motion_sensor_when_no_motion(s,**config)
            else:
                motion_sensor_when_motion(s,**config)
        for s in motion_sensors_list:
                motion_sensors_list[s].when_motion = lambda s=s : motion_sensor_when_motion(s,**config)
                motion_sensors_list[s].when_no_motion = lambda s=s : motion_sensor_when_no_motion(s,**config)
        if bool(config['use_led_indicators']) is True :
            led_indicators_list['motion_led'].source = any_values(*motion_sensors_list.values())

    if bool(config['use_system_buttons']) is True:
        system_buttons_list['shutdown_button'].when_held = shutdown

    if bool(config['use_CPU_sensor']) is True:
        threading_function(get_cputemp_data, **config)

    if bool(config['use_BME280_sensor']) is True:
        threading_function(get_bme280_data, **config)

    if bool(config['use_DS18B20_sensor']) is True:
        threading_function(get_ds18b20_data, **config)

    if bool(config['use_DHT_sensor']) is True:
        threading_function(get_dht_data, **config)

    if bool(config['use_weather_station']) is True:
        threading_function(rainfall, **config)
        threading_function(wind_speed, **config)
        threading_function(wind_direction, **config)

    if bool(config['use_serial_display']) is True:
        threading_function(serial_displays, **config)

    if bool(config['use_picamera']) is True and bool(config['use_picamera_recording']) is False and bool(config['use_door_sensor']) is False and bool(config['use_motion_sensor']) is False :
        av_stream('start')

    pause()
from gpiozero import LED, MotionSensor, LightSensor
from gpiozero.tools import booleanized, all_values
from signal import pause

garden = LED(2)
motion = MotionSensor(4)
light = LightSensor(5)

garden.source = all_values(booleanized(light, 0, 0.1), motion)

pause()