Exemplo n.º 1
0
    def __init__(self,
                 pin,
                 glitch_usec=GLITCH_USEC,
                 verbose=False,
                 debug=False):
        """
        Parameters
        ----------
        pin: int
        glitch_usec: int
        verbose: bool
        debug: bool
        """
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('pin=%d, glitch_usec=%d', pin, glitch_usec)

        self.pin = pin
        self.tick = 0

        self.pi = pigpio.pi()
        self.pi.set_mode(self.pin, pigpio.INPUT)
        self.pi.set_glitch_filter(self.pin, self.GLITCH_USEC)

        self.receiving = False
        self.raw_data = []
        self.verbose = verbose

        self.msgq = queue.Queue()
Exemplo n.º 2
0
Arquivo: rss.py Projeto: ytani01/RSS
    def __init__(self, url, debug):
        self._dbg = debug
        self._lgr = get_logger(__class__.__name__, self._dbg)
        self._lgr.debug('url=%s', url)

        self._url = url
        self._rss_data = feedparser.parse(self._url)
Exemplo n.º 3
0
    def __init__(self, host, port, user, pw, topic, debug=False):
        self.debug = debug
        self.logger = get_logger(__class__.__name__, self.debug)
        self.logger.debug('host=%s, port=%d, user=%s, pw=%s, topic=%s', host,
                          port, user, pw, topic)

        self.svr_host = host

        if port == 0:
            self.svr_port = self.DEF_PORT
        else:
            self.svr_port = port

        self.user = user
        self.password = pw

        self.topic = topic
        self.user = user
        self.password = pw

        self.msgq = queue.Queue()

        self.mqtt_client = mqtt.Client()
        self.mqtt_client.enable_logger()
        self.mqtt_client.on_log = self.on_log
        self.mqtt_client.on_connect = self.on_connect
        self.mqtt_client.on_disconnect = self.on_disconnect
        self.mqtt_client.on_message = self.on_message

        self.connection = False

        super().__init__()
        self.daemon = True
Exemplo n.º 4
0
def main(target_temp, tty, dev, button_header, pin, temp_topic, svr_port,
         stat_topic, kp, ki, kd, ki_i_max, debug):
    logger = get_logger(__name__, debug)
    logger.debug('target_temp=%.1f, tty=%s', target_temp, tty)
    logger.debug('dev=%s, button_header=%s, pin=%s', dev, button_header, pin)
    logger.debug('temp_topic=%s', temp_topic)
    logger.debug('svr_port=%s', svr_port)
    logger.debug('stat_topic=%s', stat_topic)
    logger.debug('kp=%s, ki=%s, kd=%s, ki_i_max=%s', kp, ki, kd, ki_i_max)

    logger.info('start')

    app = App(target_temp,
              tty,
              dev,
              button_header,
              pin,
              temp_topic,
              svr_port,
              stat_topic,
              kp,
              ki,
              kd,
              ki_i_max,
              debug=debug)
    try:
        app.main()
    finally:
        logger.debug('finally')
        app.end()
        logger.info('end')
Exemplo n.º 5
0
    def __init__(self,
                 bus,
                 addr_str,
                 token_str,
                 ch_name,
                 interval,
                 outfile,
                 debug=False):
        self.logger = get_logger(__class__.__name__, debug)

        self.logger.debug('bus      =%d', bus)
        self.logger.debug('addr_str =\'%s\'', addr_str)
        self.logger.debug('token_str=\'%s\'', token_str)
        self.logger.debug('ch_name  =\'%s\'', ch_name)
        self.logger.debug('interval =%d', interval)
        self.logger.debug('outfile  =\'%s\'', outfile)

        self.bus = bus

        if addr_str[:2] != '0x':
            self.logger.error('%s: invalid hex strings', addr_str)
            return None
        self.addr = int(addr_str[2:], 16)

        self.token_str = token_str
        self.ch_name = ch_name
        self.interval = interval
        self.outfile = outfile

        self.bbt = BBT(token=token_str, hostname=HOSTNAME)
        self.sht31 = SHT31(self.bus, self.addr, debug=debug)
Exemplo n.º 6
0
    def __init__(self, cmdq, irsend, port, debug=False):
        self._debug = debug
        self._logger = get_logger(__class__.__name__, self._debug)
        self._logger.debug('port=%s', port)

        self._cmdq = cmdq
        self._irsend = irsend
        self._port = port

        self._active = False
        self.allow_reuse_address = True  # Important !!
        while not self._active:
            try:
                super().__init__(('', self._port), IrSendHandler)
                self._active = True
                self._logger.debug('_active=%s', self._active)
            except PermissionError as e:
                self._logger.error('%s:%s.', type(e), e)
                raise
            except OSError as e:
                self._logger.error('%s:%s.', type(e), e)
                time.sleep(5)
            except Exception as e:
                self._logger.error('%s:%s.', type(e), e)
                raise

        self._logger.debug('done')
Exemplo n.º 7
0
    def __init__(self, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('')

        self.clf = nfc.ContactlessFrontend('usb')
        self._log.debug('clf=%s', self.clf)
Exemplo n.º 8
0
class App:
    _log = get_logger(__name__, False)

    def __init__(self, loop, debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('loop=%s', loop)

        self._loop = loop

        self._nfc = NfcType3Id(self.cb_connect,
                               self.cb_release,
                               loop=self._loop,
                               debug=self._dbg)

    def main(self):
        self._log.debug('')

        self._nfc.start()

    def end(self):
        self._log.debug('')
        self._nfc.end()
        self._log.debug('done')

    def cb_connect(self, id_str):
        print('*CONNECT: %s' % (id_str))
        return True

    def cb_release(self, id_str):
        print('*RELEASE: %s' % (id_str))
        return True
Exemplo n.º 9
0
    def __init__(self, host=DEF_SVR_HOST, port=DEF_SVR_PORT, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('host=%s, port=%s', host, port)

        self._svr_host = host
        self._svr_port = port
Exemplo n.º 10
0
def main(i2c_addr, channel, token, interval, count, ave_n, diff_t, diff_h,
         offset_t, offset_h, debug):
    log = get_logger(__name__, debug=debug)
    log.debug('i2c_addr=%s', i2c_addr)
    log.debug('channel=%s, token=%s', channel, token)
    log.debug('interval=%s, count=%s, ave_n=%s', interval, count, ave_n)
    log.debug('diff_t=%s, diff_h=%s', diff_t, diff_h)
    log.debug('offset_t=%s, offset_h=%s', offset_t, offset_h)

    app = App(int(i2c_addr, 16),
              channel,
              token,
              interval,
              count,
              ave_n,
              diff_t,
              diff_h,
              offset_t,
              offset_h,
              debug=debug)
    try:
        app.main()
    finally:
        app.end()
        log.info('done')
Exemplo n.º 11
0
    def __init__(self, svr_name, svr_ver, svr_id, image_dir, debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('svr_name=%s, svr_ver=%s, svr_id=%s, image_dir=%s',
                        svr_name, svr_ver, svr_id, image_dir)

        self._svr_name = svr_name
        self._svr_ver = svr_ver
        self._svr_id = svr_id
        self._image_dir = image_dir

        self._datafile_path = '%s/%s-%s.json' % (
            self.DATAFILE_DIR, self.DATAFILE_NAME, self._svr_id)
        self._log.debug('_datafile_path=%s', self._datafile_path)

        self._client_sid = []
        self._history = []
        self._fwd_hist = []
        self._cur_sn = 0

        self._bg = ytBackgammon(self._svr_ver, debug=self._dbg)
        self._repeat_flag = False

        [hist_len, fwd_hist_len] = self.load_data(self._datafile_path)
        if hist_len < 1:
            self._log.warning('load_data(%s): error', self._datafile_path)
            self.add_history(self._bg._gameinfo)
Exemplo n.º 12
0
    def __init__(self, pi=None, port=DEF_PORT, debug=False):
        """ __init__ """
        self._dbg = debug
        self._log = get_logger(__class__.__name__, debug)
        self._log.debug('pi=%s, port=%s', pi, port)

        if type(pi) == pigpio.pi:
            self._pi = pi
            self._mypi = False
        else:
            self._pi = pigpio.pi()
            self._mypi = True
        self._log.debug('mypi = %s', self._mypi)

        self._ctrl = OttoPiCtrl(self._pi, debug=self._dbg)
        self._ctrl.start()

        self._auto = OttoPiAuto(self._ctrl, debug=self._dbg)
        self._auto.start()

        self._dance = None
        self._dance2 = None

        time.sleep(1)

        self._port = port

        try:
            super().__init__(('', self._port), ServerHandler)
        except Exception as e:
            self._log.warning('%s:%s', type(e).__name__, e)
            return None
Exemplo n.º 13
0
class IpAddrApp:
    _log = get_logger(__name__, False)

    def __init__(self, debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('')

        self._ipaddr = IpAddr(debug=self._dbg)

    def main(self):
        self._log.debug('')

        while True:
            ipaddr = self._ipaddr.get_ipaddr()
            self._log.debug('ipaddr=%s', ipaddr)
            if ipaddr is not None:
                break

            self._log.warning('sleep to retry ..')
            time.sleep(2)

        print(ipaddr)

        self._log.debug('done')

    def end(self):
        self._log.debug('')

        self._log.debug('done')
Exemplo n.º 14
0
    def __init__(self, auto_aircon, msgq, port=None, debug=False):
        self._debug = debug
        self._logger = get_logger(__class__.__name__, self._debug)
        self._logger.debug('port=%s', port)

        self._aa = auto_aircon
        self._msgq = msgq
        self._port = port or self.DEF_PORT

        self.allow_reuse_address = True  # Important !!

        self._active = False
        while not self._active:
            try:
                super().__init__(('', self._port), AutoAirconHandler)
                self._active = True
                self._logger.debug('_active=%s', self._active)
            except PermissionError as e:
                self._logger.error('%s: %s.', type(e), e)
                raise
            except OSError as e:
                self._logger.warning('%s: %s. retry..', type(e), e)
                time.sleep(5)
            except Exception as e:
                self._logger.error('%s: %s.', type(e), e)
                raise

        self._logger.debug('done')
Exemplo n.º 15
0
class OttoPiBleServer(BlePeripheral):
    MY_NAME = 'OttoPi'
    DEF_ROBOT_PORT = 12345

    _log = get_logger(__name__, False)

    def __init__(self,
                 robot_host='localhost',
                 robot_port=DEF_ROBOT_PORT,
                 name=MY_NAME,
                 debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('name=%s', name)
        self._log.debug('robot_host=%s, robot_port=%s', robot_host, robot_port)

        self._name = name
        self._robot_host = robot_host
        self._robot_port = robot_port

        self._chara_resp = RespCharacteristic(debug=self._dbg)
        self._chara_cmd = CmdCharacteristic(self._robot_host,
                                            self._robot_port,
                                            self._chara_resp,
                                            debug=self._dbg)

        self._svc = OttoPiService(charas=[self._chara_cmd, self._chara_resp],
                                  debug=self._dbg)

        super().__init__(self._name, [self._svc], debug=self._dbg)
Exemplo n.º 16
0
    def __init__(self, app, port, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('port=%s', port)

        self._app = app
        self._port = port

        self._active = False
        self.allow_reuse_address = True  # Important !!

        while not self._active:
            try:
                super().__init__(('', self._port), CmdServerHandler)
                self._active = True
                self._log.info('_active=%s,_port=%s', self._active, self._port)
            except PermissionError as e:
                self._log.error('%s:%s.', type(e), e)
                raise
            except OSError as e:
                self._log.error('%s:%s .. retry', type(e), e)
                time.sleep(5)
            except Exception as e:
                self._log.error('%s:%s.', type(e), e)
                raise

        self._log.debug('done')
Exemplo n.º 17
0
class SampleApp:
    _log = get_logger(__name__, False)

    def __init__(self, arg, opt, debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('arg=%s, opt=%s')

        self._arg = arg
        self._opt = opt

        self.obj = TemplateClass(opt, debug=self._dbg)

    def main(self):
        self._log.debug('')

        for a in self._arg:
            self.obj.method1(a)

        self._log.debug('done')

    def end(self):
        self._log.debug('')

        self._log.debug('done')
Exemplo n.º 18
0
    def __init__(self, pin, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, debug)
        self._log.debug('pin=%d', pin)

        self.pin = pin
        self.waveform = []
Exemplo n.º 19
0
    def __init__(self,
                 topic_send,
                 topic_recv,
                 user,
                 password,
                 svr_host,
                 beebotte,
                 debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('topic_send=%s, topic_recv=%s', topic_send, topic_recv)
        self._log.debug('user=%s, password=%s', user, password)
        self._log.debug('svr_host=%s, beebotte=%s', svr_host, beebotte)

        self._topic_send = topic_send
        self._topic_recv = topic_recv
        self._user = user
        self._password = password
        self._svr_host = svr_host
        self._beebotte = beebotte

        if self._beebotte:
            self._svr = Beebotte(self.cb, [self._topic_recv, self._topic_send],
                                 user,
                                 debug=self._dbg)
        else:
            self._svr = Mqtt(self.cb, [self._topic_recv, self._topic_send],
                             user,
                             password,
                             svr_host,
                             debug=self._dbg)
Exemplo n.º 20
0
    def __init__(self, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)

        self.pi = pigpio.pi()
        self.robot_ctrl = OttoPiCtrl(self.pi, debug=debug)
        self.robot_ctrl.start()
Exemplo n.º 21
0
    def __init__(self, file, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('file=%s', file)

        self.file = file

        self.an = IrAnalyze(debug=self._dbg)
Exemplo n.º 22
0
    def __init__(self, dev_name=DEV_NAME, serial_max=SERIAL_MAX, debug=False):
        self._dbg = debug
        self._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('')

        self.dev_name   = dev_name
        self.serial_max = serial_max
        self._log.debug('dev_name=%s, serial_max=%d', dev_name, serial_max)
Exemplo n.º 23
0
    def __init__(self, uuid=UUID, debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('uuid=%s', uuid)

        super().__init__(uuid, ['read', 'notify'], debug=debug)

        self._updateValueCallback = None
Exemplo n.º 24
0
    def __init__(self, port, debug=False):
        """ init """
        self._dbg = debug
        self._log = get_logger(__class__.__name__, debug)
        self._log.debug('port=%d', port)

        self._port = port
        self._svr = OttoPiServer(None, self._port, debug=self._dbg)
Exemplo n.º 25
0
    def __init__(self, arg, opt, debug=False):
        self._dbg = debug
        __class__._log = get_logger(__class__.__name__, self._dbg)
        self._log.debug('arg=%s, opt=%s')

        self._arg = arg
        self._opt = opt

        self.obj = TemplateClass(opt, debug=self._dbg)
Exemplo n.º 26
0
    def __init__(self, conf_file=DEF_CONF_FILE, debug=False):
        self.debug = debug
        self.logger = get_logger(__class__.__name__, debug)
        self.logger.debug('conf_file = %s', conf_file)

        self.conf_file = conf_file
        self.conf_path_name = ''
        self.config = configparser.ConfigParser()
        self.load()
Exemplo n.º 27
0
    def __init__(self, topic=DEF_TOPIC, debug=False):
        self._debug = debug
        self._logger = get_logger(__class__.__name__, self._debug)
        self._logger.debug('topic=%s', topic)

        self._topic = topic

        # self._bbt = Beebotte(self._topic, debug=self._debug)
        self._bbt = Beebotte(self._topic, debug=False)
Exemplo n.º 28
0
def main(svr_port, debug):
    _log = get_logger(__name__, debug)
    _log.debug('svr_port=%s', svr_port)

    app = App(svr_port=svr_port, debug=debug)
    try:
        app.main()
    finally:
        app.end()
Exemplo n.º 29
0
    def __init__(self, command, svr_host, svr_port, debug=False):
        """ __init__ """
        self._dbg = debug
        self._log = get_logger(__class__.__name__, debug)
        self._log.debug('command=%s', command)
        self._log.debug('svr_host=%s, svr_port=%d', svr_host, svr_port)

        self.cl = OttoPiClient(svr_host, svr_port, debug=self._dbg)
        self.command = command
Exemplo n.º 30
0
def main(debug):
    logger = get_logger(__name__, debug)

    app = OttoPiCtrlApp(debug=debug)
    try:
        app.main()
    finally:
        logger.info('finally')
        app.end()