def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) try: self.spi_port = self.config['spi_port'] except KeyError as e: logger = logging.getLogger(__name__) err = "Key error in LEDS Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) self.pattern_classes = { "BLANK": SolidPattern, "GREEN_CLOCKWISE": SpinPattern, "GREEN_COUNTERCLOCKWISE": SpinPattern, "RED_CLOCKWISE": SpinPattern, "RED_COUNTERCLOCKWISE": SpinPattern, "BLUE_CLOCKWISE": SpinPattern, "BLUE_COUNTERCLOCKWISE": SpinPattern, "CYAN_CLOCKWISE": SpinPattern, "CYAN_COUNTERCLOCKWISE": SpinPattern, "COUNTDOWN": CountdownPattern } self.current_pattern = None
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) try: self.camera_device = self.config['camera_device'] self.image_width = self.config['image_width'] self.image_height = self.config['image_height'] self.picture_path = self.config['picture_path'] self.picture_prefix = self.config['picture_prefix'] self.camera_topic = self.config['sub_topic'] self.google_folder = self.config['google_folder'] except KeyError as e: logger = logging.getLogger(__name__) err = "Key error in Camera Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) self.flags = argparse.ArgumentParser( parents=[tools.argparser]).parse_args() # Fix for spurious google file_cache error logging.getLogger('googleapiclient.discovery_cache').setLevel( logging.ERROR) pygame.camera.init()
def __init__(self, config_file, secure_file): # Initialize self.ready to False before mqtt is initialized and # starts getting messages self.ready = False BaseModule.__init__(self, config_file, secure_file) try: self.input_topic = self.config['input_topic'] self.piezo_topic = self.config['piezo_topic'] self.camera_topic = self.config['camera_topic'] self.close_input = self.config['close_input'] self.open_input = self.config['open_input'] self.hold_input = self.config['hold_input'] self.pir_input = self.config['pir_input'] self.light_level_topic = self.config['light_level_topic'] self.hold_led = self.config['hold_led'] self.led_topic = self.config['led_topic'] self.piezo_topic = self.config['piezo_topic'] self.door_control_topic = self.config['door_control_topic'] except KeyError as e: logger = logging.getLogger(__name__) err = "Key error in Controller Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) self.open_state = "XX" self.close_state = "XX" self.door_close_timer = None self.command_response_timer = None self.on_hold = False self.error_state = False self.states = enum.Enum('DoorStates', 'CLOSED OPENED CLOSING OPENING UNKNOWN') self.current_state = self.states.UNKNOWN self.force_close = False self.led_mapping = { "CLOSED": "GREEN_CLOCKWISE", "OPENED": "COUNTDOWN", "CLOSING": "CYAN_COUNTERCLOCKWISE", "OPENING": "CYAN_CLOCKWISE", "UNKNOWN": "RED_COUNTERCLOCKWISE", "HOLD": "BLUE_CLOCKWISE", "ERROR": "RED_CLOCKWISE" } self.texter = Texter(self.mqtt_client) self.PIR = PIR(self.config, self.mqtt_client) self.initial_close_time = 570.0 self.alarm_close_time = 30.0 self.door_move_timer = 10.0 self.ready = True self._get_door_state()
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) try: self.lux_topic = self.config['lux_topic'] self.temp_topic = self.config['temp_topic'] self.hum_topic = self.config['hum_topic'] self.max_addr = self.config['max_addr'] self.hih_addr = self.config['hih_addr'] self.sub_topic = self.config['sub_topic'] except KeyError as e: logger = logging.getLogger(__name__) err = "Key error in Sensor Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2)
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) self.logger = logging.getLogger(__name__) try: self.on_time = self.config['on_time'] self.light_switch = self.config['light_switch'] self.light_level_topic = self.config['light_level_topic'] self.light_control_topic = self.config['light_control_topic'] except KeyError as e: err = "Key error in Camera Init: {}".format(e) self.logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) self.cur_lux = -1 self.lighting_timer = None
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) try: self.lux_topic = self.config['lux_topic'] self.temp_topic = self.config['temp_topic'] self.hum_topic = self.config['hum_topic'] self.api_key = self.config['thingspeak_api_key'] except KeyError as e: logger = logging.getLogger(__name__) err = "Key error in Thingspeak Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) self.lux = -1 self.temp = -1 self.hum = -1
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) logger = logging.getLogger(__name__) if "inputs" not in self.config: logger.error("No inputs Configuration in {}".config_file) self.config['inputs'] = [] self.input_pipes = {} (self.recvQueue, q) = Pipe() for b in self.config["inputs"]: try: getattr(wiringpi.GPIO, b["pupdown"]) except AttributeError: logger.error( "Input On topic {}, pupdown value {} is invalid".format( b["topic"], b["pupdown"])) continue try: getattr(wiringpi.GPIO, b["edge_type"]) except AttributeError: logger.error( "Input On topic {}, pupdown value {} is invalid".format( b["topic"], b["edge_type"])) continue (parent_pipe, child_pipe) = Pipe() self.input_pipes[b['topic']] = parent_pipe bobj = GPIOInput(b["pin"], b["edge_type"], b["debounce"] / 1000.0, b["pupdown"], b["topic"], child_pipe) bobj.start() t = threading.Thread(name="queueReader" + b["topic"], target=self._pipeThread, args=(b["topic"], )) t.setDaemon(True) t.start()
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) wiringpi.wiringPiSetup() logger = logging.getLogger(__name__) if "outputs" not in self.config: logger.error("No outputs Configuration in {}".config_file) self.config['outputs'] = [] self.outputs = {} for o in self.config['outputs']: try: topic = o['topic'] logger.debug("Setting up output on {}".format(topic)) self.outputs[topic] = {} self.outputs[topic]['type'] = o['type'] self.outputs[topic]['initial_state'] = o['initial_state'] self.outputs[topic]['pin'] = o['pin'] if o['type'] == 'momentary': self.outputs[topic]['active_time'] = o['active_time'] except KeyError as e: err = "Key error in GPIOOutputModule Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) wiringpi.pinMode(o['pin'], wiringpi.GPIO.OUTPUT) wiringpi.digitalWrite(o['pin'], self._gpio_value(o['initial_state'])) # Set the output enable pin to low, to let the signals flow thought the 74386 buffer if 'locks' in self.config: for l in self.config['locks']: if 'pin' in l: logger.debug('Bringing lock pin {} LOW'.format(l['pin'])) wiringpi.pinMode(l['pin'], wiringpi.GPIO.OUTPUT) wiringpi.digitalWrite(l['pin'], wiringpi.LOW)
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file)
def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) self.Texter = Texter() # Wait to send text until OPI is completely up threading.Timer(60, self._send_text).start()