Exemplo n.º 1
0
def main(args):
    # Read in the configuration file
    config = loadConfig(CONFIG_FILE)

    # Record some data and extract the bits on-the-fly
    bits = readRTL(int(config['duration']))

    # Read in the most recent state
    db = Archive()
    tLast, output = db.getData()

    # Find the packets and save the output
    output = parseBitStream(bits,
                            elevation=config['elevation'],
                            inputDataDict=output,
                            verbose=config['verbose'])

    # Save to the database
    db.writeData(time.time(), output)

    # Upload
    wuUploader(config['ID'],
               config['PASSWORD'],
               output,
               archive=db,
               includeIndoor=config['includeIndoor'],
               verbose=config['verbose'])
Exemplo n.º 2
0
def main(args):
    # Parse the command line and read in the configuration file
    cmdConfig = parseOptions(args)

    # Setup logging
    logger = logging.getLogger(__name__)
    logFormat = logging.Formatter('%(asctime)s [%(levelname)-8s] %(message)s',
                                  datefmt='%Y-%m-%d %H:%M:%S')
    logFormat.converter = time.gmtime
    logHandler = WatchedFileHandler(cmdConfig['logfile'])
    logHandler.setFormatter(logFormat)
    logger.addHandler(logHandler)
    if cmdConfig['debug']:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    # PID file
    if cmdConfig['pidFile'] is not None:
        fh = open(cmdConfig['pidFile'], 'w')
        fh.write("%i\n" % os.getpid())
        fh.close()

    # CherryPy configuration
    cherrypy.config.update({
        'server.socket_host': '0.0.0.0',
        'environment': 'production'
    })
    cpConfig = {
        '/css': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': CSS_PATH
        },
        '/js': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': JS_PATH
        }
    }

    # Report on who we are
    logger.info('Starting wxPi.py with PID %i', os.getpid())
    logger.info('All dates and times are in UTC except where noted')

    # Load in the configuration
    config = loadConfig(cmdConfig['configFile'])

    # Get the latest from the database
    db = Archive()
    db.start()

    tData, sensorData = db.getData()
    if time.time() - tData > 2 * config.getfloat('Station', 'duration'):
        sensorData = {}

    # Initialize the LEDs
    leds = initLEDs(config)

    # Make sure the database has provided something useful.  If not, we need to
    # run several iterations to build up the current picture of what is going on.
    if len(sensorData.keys()) == 0:
        buildState = True
        loopsForState = 3
    else:
        buildState = False
        loopsForState = 1

    # Start the sensor polling
    bg = PollingProcessor(config,
                          db,
                          leds,
                          buildState=buildState,
                          loopsForState=loopsForState,
                          sensorData=sensorData)
    bg.start()

    # Initialize the web interface
    ws = Interface(config, db, leds)
    #cherrypy.quickstart(ws, config=cpConfig)
    cherrypy.tree.mount(ws, "/", config=cpConfig)
    cherrypy.engine.start()
    cherrypy.engine.block()

    # Shutdown process
    logger.info('Shutting down wxPi, please wait...')

    # Stop the polling thread
    bg.cancel()

    # Make sure the LEDs are off
    for color in leds.keys():
        leds[color].off()

    # Shutdown the archive
    db.cancel()