Example #1
0
def main():
    # parse command line argument
    args = command_line_parser("RPI_IN_DRIVER")
    prefix: str = hash_prefix(args.public_id)

    # parse configuration file
    app_config = configparser.ConfigParser()
    app_config.read("./app_config.ini")
    intercom_config = app_config["mumble"]
    video_config = app_config["video"]

    # set up pub sub
    logger.info("Setting up publisher and subscriber")
    pub, msg_q, listen_proc = set_up_pub_sub(prefix, "in_to_out", "out_to_in")
    logger.info("Publisher and subscriber set up successfully!")
    try:
        logger.info("Spinning up UI...")
        rokku_ui = rokku.Main(pub, msg_q, intercom_config, video_config)
        rokku_ui.run()
        logger.info("UI terminated.")
    except (KeyboardInterrupt, SystemExit):
        pass  # do nothing here because the code below completes the cleanup

    clean_up(logger, processes=[listen_proc], cmds=[])
    logger.info("\n******* rpi_in_driver ends *******\n")
Example #2
0
def mqtt_out():
    """Set up mqtt components of rpi_out."""
    mqtt_out = set_up_pub_sub(
        hash_prefix("Rokku/test_topic"), "out_to_in", "in_to_out"
    )
    yield mqtt_out
    print("tear down mqtt_out")
    _, _, out_listen_proc = mqtt_out
    out_listen_proc.terminate()
    out_listen_proc.join()
Example #3
0
def button():
    """Set up button via ui."""
    in_pub, in_msg_q, in_listen_proc = set_up_pub_sub(
        hash_prefix("Rokku/test_topic"), "in_to_out", "out_to_in"
    )
    app_config = configparser.ConfigParser()
    app_config.read(
        f"{os.path.dirname(__file__)}/fixtures/test_app_config.ini"
    )
    intercom_config = app_config["mumble"]
    ui = Main(in_pub, in_msg_q, intercom_config)
    yield ui.talk_button
    print("tear down button via UI")
    ui.close_application("", "")
    in_listen_proc.terminate()
    in_listen_proc.join()
Example #4
0
def main():
    # parse command line argument
    args = command_line_parser("RPI_OUT_DRIVER")
    prefix: str = hash_prefix(args.public_id)

    # parse configuration file
    app_config = configparser.ConfigParser()
    app_config.read("./app_config.ini")
    intercom_config = app_config["mumble"]

    # set up pub sub
    logger.info("Setting up publisher and subscriber")
    pub, msg_q, listen_proc = set_up_pub_sub(prefix, "out_to_in", "in_to_out")
    logger.info("Publisher and subscriber set up successfully!")

    motion_queue = Queue()  # set up queue for motion sensor

    # set up flag for camera
    camera_flags = {"livestream_on": False, "recording_on": False}
    cam = CameraInterface()  # Create camera object

    # Run mute button in separate process
    togglemute_proc = start_togglemute_proc(logger)

    try:
        # forever listening on topic "{prefix}/in_to_out"
        while True:
            if not msg_q.empty():
                msg: str = msg_q.get()
                identifier, flag = json.loads(msg)
                if identifier == "alarm":
                    alarm.alarm(pub, flag)
                elif identifier == "intercom":
                    intercom.intercom(pub, flag, intercom_config, logger)
                elif identifier == "motion":
                    motion.motion(pub, flag, motion_queue)
                elif identifier == "record":
                    record.record(pub, cam, camera_flags)
                elif identifier == "livestream":
                    livestream.livestream(pub, cam, camera_flags)
            sleep(1)
    except (KeyboardInterrupt, SystemExit):
        logger.warning("Termination signal sensed.")
        clean_up(logger, processes=[listen_proc, togglemute_proc], cmds=[])
    logger.info("\n******* rpi_out_driver ends *******\n")
    GPIO.cleanup()
Example #5
0
def test_hash_prefix():
    res = hash_prefix("rokku")
    expected = (
        "320bda34a3c7f8dc49e5c976792f20ef5ec6f400b970138393020709bc2c1bc1")
    assert res == expected
Example #6
0
def main():
    # parse command line argument
    args = command_line_parser("RPI_OUT_DRIVER")
    prefix: str = hash_prefix(args.public_id)

    # parse configuration file
    app_config = configparser.ConfigParser()
    app_config.read("./app_config.ini")
    intercom_config = app_config["mumble"]
    motion_sensor_config = app_config["motion_sensor"]

    # set up pub sub
    logger.info("Setting up publisher and subscriber")
    pub, msg_q, listen_proc = set_up_pub_sub(prefix, "out_to_in", "in_to_out")
    logger.info("Publisher and subscriber set up successfully!")

    # set up flag for camera
    camera_flags = {"livestream_on": False, "recording_on": False}
    cam = CameraInterface()  # Create camera object

    # set up motion sensor
    motion_queue = Queue()  # set up queue for motion sensor
    motion_pin = 23  # channel 23 (GPIO23) is connected to motion sensor
    led_pin = 12  # GPIO12 is connected to motion sensor LED indicator
    sensor = MotionPir(motion_queue, motion_pin, led_pin, motion_sensor_config)
    led_proc = None  # placeholder for process lighting up LED.

    # Run mute button in separate process
    togglemute_proc = start_togglemute_proc(logger)

    try:
        # forever listening on topic "{prefix}/in_to_out"
        while True:
            if not msg_q.empty():
                msg: str = msg_q.get()
                identifier, flag = json.loads(msg)
                if identifier == "alarm":
                    alarm.alarm(pub, flag)
                elif identifier == "intercom":
                    intercom.intercom(pub, flag, intercom_config, logger)
                elif identifier == "motion":
                    motion.motion(pub, flag, sensor)
                elif identifier == "record":
                    record.record(pub, cam, camera_flags)
                elif identifier == "livestream":
                    livestream.livestream(pub, cam, camera_flags)
                elif identifier == "motion_ackd":
                    # User acknowledged motion has been detected.
                    # Resume motion sensor
                    terminate_proc(led_proc, logger)
                    sensor.set_armed()

            if not motion_queue.empty():  # motion detected
                motion_queue.get()
                pub.publish(json.dumps(["motion_detected",
                                        True]))  # alert user
                # Halt motion sensor as user deals with alert without explicitly
                # change rpi_in's UI (use should NOT be able to interact with
                # UI when the alert is on)
                sensor.set_disarmed()
                led_proc = Process(target=sensor.led_on,
                                   name="LED proc",
                                   args=())
                led_proc.start()
            sleep(1)
    except (KeyboardInterrupt, SystemExit):
        logger.warning("Termination signal sensed.")
        clean_up(logger, processes=[listen_proc, togglemute_proc], cmds=[])
    logger.info("\n******* rpi_out_driver ends *******\n")
    GPIO.cleanup()