Example #1
0
def main():
    gate = Ubigate('marmitek-gw',
                   default_file='resources/conf.json.default')

    logger.info("Starting application")
    logger.debug('Timezone: %s' % gate.timezone)

    for data in mochad_reader.run(gate.timezone):
        if data['type'] != 'error':
            try:
                data['house'] = gate.find_house(data['sensor'])
            except KeyError:
                logger.warning("Unknown sensor: %s" % data['sensor'])
            else:
                # Appending house prefix if dealing with door sensor
                if data['sensorKind'] == 'door':
                    for house in gate.config['houses']:
                        if house['id'] == data['house']:
                            prefix = house['prefix']
                            break
                    else:
                        prefix = ''
                    data['sensor'] = prefix.lower() + data['sensor']

                topic = "/marmitek/sensor/%s" % data['sensor']
                gate.push(data['house'], topic, data)
Example #2
0
def main():
    gate = Ubigate('zigbee-gw', default_file='resources/conf.json.default')

    logger.info("Starting application")
    logger.debug('Timezone: %s' % gate.timezone)

    for data in zigbee_IO.run(gate):
        if data['type'] != 'error':
            try:
                data['house'] = gate.find_house(data['sensor'])
            except KeyError:
                logger.warning("Unknown sensor: %s" % data['sensor'])
            else:
                topic = "/zigbee/sensor/%s/%s" % (data['sensor'], data['type'])
                gate.push(data['house'], topic, data)
Example #3
0
def read_from_mochad():
    Sock = _init()
    while True:
        lines = None
        try:
            data = Sock.recv(1024)
            line = repr(data).strip("b'")
            lines = line.split('\\n')
        except socket.timeout:
            logger.warning("Will try to reconnect to mochad")
        finally:
            Sock.shutdown(2)
            Sock.close()
            Sock = _init()
            if lines is not None:
                yield lines
Example #4
0
def read_from_mochad():
    Sock = _init()
    while True:
        lines = None
        try:
            data = Sock.recv(1024)
            line = repr(data).strip("b'")
            lines = line.split('\\n')
        except socket.timeout:
            logger.warning("Will try to reconnect to mochad")
        finally:
            Sock.shutdown(2)
            Sock.close()
            Sock = _init()
            if lines is not None:
                yield lines