def test_gpio(self):
     import thingflow.adapters.rpi.gpio
     o = thingflow.adapters.rpi.gpio.GpioPinOut()
     sensor_thing = SensorAsOutputThing(ValueListSensor("sensor-1", values))
     sensor_thing.map(lambda evt: evt.val > 0).passthrough(
         output()).connect(o)
     s = Scheduler(asyncio.get_event_loop())
     s.schedule_periodic(sensor_thing, 1.0)
     s.run_forever()
def setup(threshold=25):
    lux = SensorAsOutputThing(LuxSensor())
    lux.connect(print)
    lux.csv_writer(os.path.expanduser('~/lux.csv'))
    led = GpioPinOut()
    actions = lux.map(lambda event: event.val > threshold)
    actions.connect(led)
    actions.connect(lambda v: print('ON' if v else 'OFF'))
    lux.print_downstream()
    return (lux, led)
Esempio n. 3
0
def setup(broker, threshold):
    lux = SensorAsOutputThing(LuxSensor())
    lux.connect(print)
    led = GpioPinOut()
    actions = lux.map(lambda event: event.val > threshold)
    actions.connect(led)
    actions.connect(lambda v: print('ON' if v else 'OFF'))
    lux.to_json().connect(MQTTWriter(broker, topics=[('bogus/bogus', 0)]))
    lux.print_downstream()
    return (lux, led)
Esempio n. 4
0
    def on_completed(self):
        print("LED Completed")

    def __str__(self):
        return 'LED'


# instantiate an LED
led = LED()

# Now, build a pipeline to sample events returned from the sensor,
# convert to a boolean based on whether the value is greater than
# the mean, and output to the LED.
import thingflow.filters.map
sensor.map(lambda evt: evt.val > MEAN).connect(led)

# If you want to see the raw value of each sensor, just add the output() element
import thingflow.filters.output
sensor.output()

# Call a debug method on the base output_thing class to see the element tree rooted
# at sensor.
sensor.print_downstream()

# Now, we need to schedule the sensor to be sampled
import asyncio
from thingflow.base import Scheduler
scheduler = Scheduler(asyncio.get_event_loop())
scheduler.schedule_periodic(sensor, 1.0)  # sample once a second
scheduler.run_forever()  # run until all sensors complete