Exemplo n.º 1
0
Arquivo: gateway.py Projeto: prmtl/mgw
def main():
  parser = argparse.ArgumentParser(description='Moteino gateway')
  parser.add_argument('--dir', required=True, help='Root directory, should cotains *.config.json')
  parser.add_argument('--create-db', required=False, help='Crate mgw database. CAUTION: IT WILL REMOVE OLD DATA', action="store_true")
  parser.add_argument('--sync-db-desc', required=False, help='Sync boards description', action="store_true")
  args = parser.parse_args()

  conf = utils.load_config(args.dir + '/global.config.json')
  sensors_map = utils.load_config(args.dir + '/sensors.config.json')
  boards_map = utils.load_config(args.dir + '/boards.config.json')

  db = database.connect(conf['db_file'])

  if args.create_db:
    database.create_db(db, boards_map)
    print('Database created in {}'.format(conf['db_file']))
    sys.exit(0)

  if args.sync_db_desc:
    database.sync_boards(db, boards_map)
    print('Syned boards in {}'.format(conf['db_file']))
    sys.exit(0)

  utils.create_logger(conf['logging']['level'])

  mgmt = mgmt_Thread(
    conf=conf,
    boards_map=boards_map,
    sensors_map=sensors_map,
  )
  mgmt.start()
Exemplo n.º 2
0
Arquivo: gateway.py Projeto: prmtl/mgw
  def run(self):
    LOG.info('Starting')
    self.db = database.connect(self.db_file)
    while True:
      self.enabled.wait()

      result = self.db.execute(self.query)
      self.handle_query_result(result)

      time.sleep(self.loop_sleep)
Exemplo n.º 3
0
Arquivo: gateway.py Projeto: prmtl/mgw
  def run(self):
    LOG.info('Starting')
    self.db = database.connect(self.db_file)

    while True:
      self.enabled.wait()

      sensor_data = self._read_sensors_data()
      if not sensor_data:
        continue

      LOG.debug("Got data from serial '%s'", sensor_data)

      self._save_sensors_data(sensor_data)

      ACTION_QUEUE.put(sensor_data)