Beispiel #1
0
def setup(broker, threshold):
    lux = SensorPub(LuxSensor())
    lux.subscribe(print)
    led = GpioPinOut()
    actions = lux.map(lambda event: event.val > threshold)
    actions.subscribe(led)
    actions.subscribe(lambda v: print('ON' if v else 'OFF'))
    lux.to_json().subscribe(MQTTWriter(broker, topics=[('bogus/bogus', 0)]))
    lux.print_downstream()
    return (lux, led)
def setup(threshold=25):
    lux = SensorPub(LuxSensor())
    lux.subscribe(print)
    lux.csv_writer(os.path.expanduser('~/lux.csv'))
    led = GpioPinOut()
    actions = lux.map(lambda event: event.val > threshold)
    actions.subscribe(led)
    actions.subscribe(lambda v: print('ON' if v else 'OFF'))
    lux.print_downstream()
    return (lux, led)
Beispiel #3
0
def test_bokeh_manager():
    loop = asyncio.get_event_loop()
    s1 = ValueListSensor(1, value_stream)
    p1 = SensorPub(s1)
    s2 = ValueListSensor(1, value_stream2)
    p2 = SensorPub(s2)

    bm = BokehPlotManager()
    bplot1 = BokehPlot('Sensor1', y_axis_label='value')  
    bplot2 = BokehPlot('Sensor2', y_axis_label='value')  
    bm.register(bplot1)
    bm.register(bplot2)
    p1.map(lambda v: ('Sensor1', v)  ).subscribe(bm)
    p2.map(lambda v: ('Sensor2', v)  ).subscribe(bm)
    bm.start()
 
    scheduler = Scheduler(loop)
    scheduler.schedule_periodic(p1, 1.0) # sample every second
    scheduler.schedule_periodic(p2, 0.5) # sample twice every second
    scheduler.run_forever()
    # self.assertTrue(vo.completed,
    #     "Schedule exited before validation observer completed")
    print("That's all folks")