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):
	# 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.º 3
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', 'server.socket_port': 80, '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 Pi2O.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'])
    
    # Initialize the archive
    history = Archive(config)
    history.start()
    
    # Initialize the hardware
    hardwareZones = initZones(config)
    for previousRun in history.getData(scheduledOnly=True):
        logger.info('Previous run of zone %i was on %s LT', previousRun['zone'], datetime.fromtimestamp(previousRun['dateTimeStart']))
        
        if hardwareZones[previousRun['zone']-1].lastStart == 0:
            hardwareZones[previousRun['zone']-1].lastStart = previousRun['dateTimeStart']
            hardwareZones[previousRun['zone']-1].lastStop = previousRun['dateTimeStop']
            
    # Initialize the scheduler
    bg = ScheduleProcessor(config, hardwareZones, history)
    bg.start()
    
    # Initialize the web interface
    ws = Interface(config, hardwareZones, history)
    #cherrypy.quickstart(ws, config=cpConfig)
    cherrypy.tree.mount(ws, "/", config=cpConfig)
    cherrypy.engine.start()
    cherrypy.engine.block()
    
    # Shutdown process
    logger.info('Shutting down Pi2O, please wait...')
    
    # Stop the scheduler thread
    bg.cancel()
    
    # Make sure the sprinkler zones are off
    for i,zone in enumerate(hardwareZones):
        if zone.isActive():
            zone.off()
            history.writeData(time.time(), i, 'off')
            
    # Shutdown the archive
    history.cancel()
    
    # Save the final configuration
    saveConfig(cmdConfig['configFile'], config)