import RPi.GPIO as GPIO import yaml import argparse from metis import motion, camera, led, telegram def parse_command_line(): parser = argparse.ArgumentParser() parser.add_argument( '-c', '--conf', default='config.yaml', help='set path to the config file') arguments = parser.parse_args() return arguments if __name__ == '__main__': with open(parse_command_line().conf, 'r') as stream: config = yaml.load(stream) print(config) GPIO.setmode(GPIO.BCM) detector = motion.MotionDetector(config['sensor_pin']) recorder = camera.CamRecorder() telega = telegram.Telegram(config['telegram_token'], config['recipient_id']) motion_led = led.Led(config['led_motion_pin']) no_motion_led = led.Led(config['led_no_motion_pin'], True) detector.start.connect(lambda sender: motion_led.on(), weak=False) detector.start.connect(lambda sender: no_motion_led.off(), weak=False) detector.start.connect(lambda sender: telega.send_message('Intruder detected'), weak=False) detector.start.connect(lambda sender: recorder.record(), weak=False) detector.end.connect(lambda sender: motion_led.off(), weak=False) detector.end.connect(lambda sender: no_motion_led.on(), weak=False) detector.end.connect(lambda sender: recorder.stop(), weak=False) recorder.end.connect(lambda sender, filename: print(filename, 'recorded'), weak=False) recorder.end.connect(lambda sender, filename: telega.send_doc(filename), weak=False) try: detector.run() except (KeyboardInterrupt, SystemExit): print('Exiting') finally: motion_led.off() no_motion_led.off() GPIO.cleanup()