예제 #1
0
def main():
    led = LightController(led_pin)
    led.set_active_time_interval(5, 22)
    my_garden = GardenScheduler("garasjen")
    my_garden.set_update_interval(300)
    my_garden.add_device(led)
    my_garden.start()
 def __init__(self, request: bytes, client_address: Tuple[str, int],
              server: socketserver.BaseServer) -> None:
     self.heater_thread_stop = False
     self.heater_thread = Thread(target=self.run_heater,
                                 args=(lambda: self.heater_thread_stop, ))
     self.light_controller = LightController(
         light_pin)  # create light controller
     self.temp_controller = TempController(
         target_temp, heater_pin,
         sensor_pin)  # create temp controller at 40C
     self.post_mem = {"heater": "off", "lamp": "off", "color": "#FF0000"}
     super().__init__(request, client_address, server)
예제 #3
0
def main():
    #get config from json
    with open('config.json') as json_file:
        data = json.load(json_file)

        #set up listener
    listener = ControllerListener()
    lc = LightController(data['mac'], data['ip'])
    listener.assignLightController(lc)

    #get controller
    controller = Leap.Controller()
    controller.enable_gesture(Leap.Gesture.TYPE_SWIPE)
    controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP)

    controller.add_listener(listener)  #attach listener

    # Keep this process running until Enter is pressed
    print "Press Enter to quit..."
    try:
        sys.stdin.readline()
    except KeyboardInterrupt:
        pass
    finally:
        # Remove the sample listener when done
        controller.remove_listener(listener)
예제 #4
0
 def __init__(self):
     self.rlock = threading.RLock()
     self.light = LightController()
     self.motion = MotionController()
     self.name = 'CairnFORM_' + \
         "_".join("{:02x}".format(hat) for hat in MotionController.hats)
     self.rings = []
     for address in range(len(self.motion.maps)):
         self.rings.append(
             RingController(address, self.rlock, self.light, self.motion))
     self.reset()
예제 #5
0
파일: main.py 프로젝트: petr-kalinin/plants
graphite = Graphite("ije.algoprog.ru", "plants." + str(graphite_instance), config.graphite_attempts)
sht20 = SHT20(bus=config.i2c) if config.th_monitor else None
rtl433 = RTL433() if config.rtl433 else None
light_setter = LightSetter() if config.light else None
level = WaterLevel(config.invert_level) if config.level else None
pump = WaterPump()
soil = SoilHumidity(0x48, [i for i in range(soils)]) if config.soils > 0 else None
lightness = Lightness(0x48, config.lightness) if config.lightness else None
distance = DistanceMeter() if config.distance else None
heater = Heater() if config.heater else None
display = Display(config.i2c) if config.display else None
joystick = Joystick(0x48, [0, 1]) if config.joystick else None

monitor = Timer(THMonitor(sht20, graphite), enabled=config.th_monitor)
outdoor_monitor = Timer(OutdoorTHMonitor(rtl433, graphite), enabled=config.rtl433)
light_controller = Timer(LightController(light_setter), enabled=config.light)
level_monitor = Timer(WaterLevelMonitor(level, graphite), enabled=config.level)
pump_controller = Timer(PumpController(level, pump, graphite), enabled=config.pump)
soil_monitor = Timer(SoilMonitor(soil, graphite), enabled=config.soils > 0)
distance_monitor = Timer(DistanceMonitor(distance, graphite), enabled=config.distance)
lightness_monitor = Timer(LightnessMonitor(lightness, graphite), enabled=len(config.lightness)>0)
ping = Timer(Ping(graphite), enabled=config.ping)
heater_controller = Timer(HeaterController(heater, sht20, display, joystick, graphite, config.heater_t_max), enabled=config.heater)
dacha_pump_controller = Timer(DachaPumpController(distance, pump, graphite), enabled=config.dacha_pump)

async def all():
    while True:
        await asyncio.gather(
            light_controller(),
            monitor(),
            outdoor_monitor(),
예제 #6
0
파일: Main.py 프로젝트: EuanOR/FYP
bedroom1Rad = Rad(2500)
bedroom1Light = Light(98)
bedroom1Door = Door(1.5)
electricBlanket = ElectricBlanket(5)
bedroom1 = Bedroom("Bedroom 1", 12, 12, 8, 12.0, bedroom1Rad, bedroom1Door,
                   bedroom1Light, bedroom1Window, electricBlanket)

utilityRoomWindow = Window(3)
utilityRoomRad = Rad(1200)
utiilityRoomLight = Light(100)
utilityRoomDoor = Door(2)
dryer = Dryer(300)
utiilityRoom = UtilityRoom("Utility Room", 8,  8, 8, 12.0, \
    utilityRoomRad, utilityRoomDoor, utiilityRoomLight, utilityRoomWindow, dryer)

houseRooms = [livingRoom, kitchen, bedroom1, utiilityRoom]
houseRads = [livingRoomRad, kitchenRad, bedroom1Rad, utilityRoomRad]
houseLights = [livingRoomLight, kitchenLight, bedroom1Light, utiilityRoomLight]
Boiler = Heater(houseRads)
Light_Controller = LightController(houseLights)
Kitchen_Controller = KitchenController(kitchen)
Bedroom_Controller = BedroomController(bedroom1)
Utility_Room_Controller = UtilityRoomController(utiilityRoom)
Home = House(True, houseRooms, Boiler, "-37.8136", "144.9631")

Mon = Monitor(0, 30, Boiler, Light_Controller, Kitchen_Controller,
              Bedroom_Controller, Utility_Room_Controller)

c = Controller(Home, Mon)

c.run()
class LampServer(BaseHTTPRequestHandler):
    def __init__(self, request: bytes, client_address: Tuple[str, int],
                 server: socketserver.BaseServer) -> None:
        self.heater_thread_stop = False
        self.heater_thread = Thread(target=self.run_heater,
                                    args=(lambda: self.heater_thread_stop, ))
        self.light_controller = LightController(
            light_pin)  # create light controller
        self.temp_controller = TempController(
            target_temp, heater_pin,
            sensor_pin)  # create temp controller at 40C
        self.post_mem = {"heater": "off", "lamp": "off", "color": "#FF0000"}
        super().__init__(request, client_address, server)

    def do_HEAD(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def _redirect(self, path):
        self.send_response(303)
        self.send_header('Content-type', 'text/html')
        self.send_header('Location', path)
        self.end_headers()

    def do_GET(self):
        html = '''
            <html>
            <body style="width:960px; margin: 20px auto;">
            <h1>Lava Lamp Controller</h1>
            <p>Current Lamp temperature is {}C</p>
            <form action="/" method="POST">
                Turn Heater :
                <input type="submit" name="heater" value="On">
                <input type="submit" name="heater" value="Off">
            </form>
            <form action="/" method="POST">
                Turn Lamp :
                <input type="submit" name="lamp" value="On">
                <input type="submit" name="lamp" value="Off">
                <input type="color" name="color" value={}>
            </form>
            </body>
            </html>
        '''
        self.do_HEAD()
        self.wfile.write(
            html.format(self.temp_controller.read_temp(),
                        self.post_mem.get('color')).encode("utf-8"))

    def do_POST(self):
        content_length = int(
            self.headers['Content-Length'])  # Get the size of data
        post_data = self.rfile.read(content_length).decode(
            "utf-8")  # Get the data
        post_data = post_data.split("&")
        for data in post_data:
            split_data = data.split("=")
            self.post_mem[split_data[0]] = split_data[1]
        self.do_action()
        self._redirect('/')  # Redirect back to the root url

    def do_action(self):
        action_switch = {
            "heater": self.change_heater_state(),
            "lamp": self.change_lamp_state(),
            "color": self.change_color_state(),
        }
        for pair in self.post_mem:
            return action_switch.get(pair[0])

    def change_heater_state(self):
        state = self.post_mem.get('heater')
        if state == "On":
            self.heater_thread_stop = False
            self.heater_thread.start()
        else:
            self.heater_thread_stop = True

    def change_lamp_state(self):
        state = self.post_mem.get('lamp')
        if state == "On":
            self.light_controller.turn_on()
        else:
            self.light_controller.turn_off()

    def change_color_state(self):
        state = self.post_mem.get('color')
        state = state.replace('%23', '#')  # make standard hex color code
        self.post_mem['color'] = state
        self.light_controller.change_color(state)

    def run_heater(self, stop):
        while True:
            self.temp_controller.update()
            if stop():
                break