def main(argv=sys.argv[1:]): parser = argparse.ArgumentParser( description='Distributed lux example, data capture process') parser.add_argument('-i', '--interval', type=float, default=5.0, help="Sample interval in seconds") parser.add_argument( '-t', '--threshold', type=float, default=25.0, help="Threshold lux level above which light should be turned on") parser.add_argument('broker', metavar="BROKER", type=str, help="hostname or ip address of mqtt broker") parsed_args = parser.parse_args(argv) (lux, led) = setup(parsed_args.broker, parsed_args.threshold) scheduler = Scheduler(asyncio.get_event_loop()) stop = scheduler.schedule_periodic_on_separate_thread( lux, parsed_args.interval) print("starting run...") try: scheduler.run_forever() except KeyboardInterrupt: led.on_completed() stop() return 0
def test_blocking_publisher(self): o = BlockingPublisher() o.output() scheduler = Scheduler(asyncio.get_event_loop()) c = scheduler.schedule_periodic_on_separate_thread(o, 1) vs = ValidationSubscriber([i+1 for i in range(EVENTS)], self, extract_value_fn=lambda v:v) o.subscribe(vs) o.subscribe(StopLoopAfter(EVENTS, c)) o.print_downstream() scheduler.run_forever() print("that's it")
def main(argv=sys.argv[1:]): if len(argv) != 2: print("%s threshold interval" % sys.argv[0]) return 1 threshold = float(argv[0]) interval = float(argv[1]) print("%f seconds interval and an led threshold of %f lux" % (interval, threshold)) (lux, led) = setup(threshold) scheduler = Scheduler(asyncio.get_event_loop()) stop = scheduler.schedule_periodic_on_separate_thread(lux, interval) print("starting run...") try: scheduler.run_forever() except KeyboardInterrupt: led.on_completed() stop() return 0