Esempio n. 1
0
def ftp_session():
    with powered([GPIO.IRD, GPIO.RTR, GPIO.HUB]):
        logger.debug(
            "Waiting {0} seconds before attempting ftp session".format(DIALOUT_WAIT)
        )
        sleep(DIALOUT_WAIT)
        retries = 0
        while retries <= FTP_CONNECT_RETRIES:
            try:
                with closing(FTP(FTP_HOST, timeout=FTP_TIMEOUT)) as ftp:
                    ftp.login(*get_creds(FTP_HOST))
                    yield ftp
                    break
            except socket.error:
                logger.debug(traceback.format_exc())
                logger.debug("FTP connection failed")
                if retries >= FTP_CONNECT_RETRIES:
                    raise Exception(
                        "FTP failed after {0} retries".format(FTP_CONNECT_RETRIES)
                    )
                retries += 1
                logger.debug(
                    "Waiting {0} seconds before retrying ftp session".format(
                        FTP_RETRY_WAIT
                    )
                )
                sleep(FTP_RETRY_WAIT)
Esempio n. 2
0
def get_binex():
    output_filepath = os.path.join(DATA_DIR(DATA_TAGS.BNX),
                                   DATA_LOG_FILENAME(DATA_TAGS.BNX))
    with powered([GPIO.SER, GPIO.GPS]):
        with closing(Serial(GPS_PORT, GPS_BAUD, timeout=60)) as serial:
            query_binex(serial, output_filepath)

    return output_filepath
Esempio n. 3
0
def get_samples(n=SOLAR_SAMPLES, wait=SOLAR_SAMPLE_WAIT):
    samples = []
    with powered([GPIO.SOL]):
        for _ in xrange(n):
            timestamp = datetime.now()
            samples.append(SolarSample(timestamp, *get_solar()))
            sleep(SOLAR_SAMPLE_WAIT)

    return samples
Esempio n. 4
0
def get_gga():
    with powered([GPIO.SER, GPIO.GPS]):
        sleep(GPS_STARTUP_WAIT)
        with closing(Serial(GPS_PORT, GPS_BAUD, timeout=60)) as serial:
            timestamp = get_datetime(serial)
            set_datetime(timestamp)
            sample = parse_gga(query_gga(serial), timestamp)

    return sample
Esempio n. 5
0
def get_tps():
    filename = datetime.now().strftime(TIMESTAMP_FILENAME_FMT) + ".tps"
    output_filepath = os.path.join(DATA_DIR(DATA_TAGS.TPS), filename)
    with powered([GPIO.SER, GPIO.GPS]):
        sleep(GPS_STARTUP_WAIT)
        with closing(Serial(GPS_PORT, GPS_BAUD, timeout=60)) as serial:
            query_tps(serial, output_filepath)

    return output_filepath
Esempio n. 6
0
def get_last_sample():
    with powered([GPIO.HUB, GPIO.CRX]):
        logger.debug(
            "Waiting {0} seconds for crx startup".format(CRX_STARTUP_WAIT))
        sleep(CRX_STARTUP_WAIT)
        with connection() as device:
            logger.debug("Getting last sample from CRX")
            recfrag = device.get_raw_packets("Public")[-1]["RecFrag"][-1]
            data = {"timestamp": recfrag["TimeOfRec"]}
            data.update(**recfrag["Fields"])
            sample = CRXSample(**data)

    return sample
Esempio n. 7
0
def get_samples(n=12):
    logger.debug("Getting {0} samples".format(n))
    samples = []
    start_time = time()
    with powered([GPIO.WXT]):
        with closing(Serial(WXT_PORT, WXT_BAUD, timeout=60)) as serial:
            while len(samples) < n and time() - start_time < WXT_TIMEOUT:
                line = serial.readline()
                logger.debug("Read line from vaisala: {0}".format(line))
                if re.search(LINE_PATTERN, line):
                    samples.append(parse_sample(line))
                    logger.debug("{0} of {1} samples collected".format(
                        len(samples), n))

    return samples
Esempio n. 8
0
def execute():
    logger.info("Turning on DTS and windows unit")
    with powered([GPIO.HUB, GPIO.WIN, GPIO.DTS]):
        logger.info(
            "Sleeping {0} seconds for acquisition".format(DTS_PULL_DELAY))
        sleep(DTS_PULL_DELAY)
        ssh = SSH(DTS_USER, DTS_HOST)
        raw_filepaths = pull_data(ssh)
        shutdown_win(ssh)

    processed_filepaths = process_data(raw_filepaths)

    tag = DATA_TAGS.DTS
    queue_filepaths_chunked(processed_filepaths, postfix=tag)
    archive_filepaths(raw_filepaths, postfix=tag)
    clear_directory(DATA_DIR(tag))
Esempio n. 9
0
def onboard_handler(args):
    import honcho.core.gpio as gpio
    import honcho.core.onboard as onboard

    if args.voltage or args.all:
        print("Voltage: {0}".format(onboard.get_voltage()))

    if args.current or args.all:
        print("Current: {0}".format(onboard.get_current()))

    if args.temperature or args.all:
        print("Temperature: {0}".format(onboard.get_temperature()))

    if args.humidity or args.all:
        print("Humidity: {0}".format(onboard.get_humidity()))

    if args.solar or args.all:
        with gpio.powered([GPIO.SOL]):
            print("Solar: {0}".format(onboard.get_solar()))
Esempio n. 10
0
def execute():
    with powered([GPIO.CAM, GPIO.HUB]):
        logger.debug("Sleeping {0} seconds for camera startup".format(
            CAMERA_STARTUP_WAIT))
        sleep(CAMERA_STARTUP_WAIT)
        raw_filepaths, processed_filepaths = [], []
        for look in LOOK_SERIES:
            logger.debug("Looking at {0}".format(look))
            ptz = LOOK_PTZ[look]["ptz"]
            scale = LOOK_PTZ[look]["scale"]
            crop = LOOK_PTZ[look]["crop"]
            set_ptz(**ptz._asdict())

            data_dir = DATA_DIR(DATA_TAGS.CAM)

            timestamp = datetime.now()
            raw_filename = "{timestamp}_{look}_full.jpg".format(
                timestamp=timestamp.strftime(TIMESTAMP_FILENAME_FMT),
                look=look)
            raw_filepath = os.path.join(data_dir, raw_filename)
            snapshot(raw_filepath)
            raw_filepaths.append(raw_filepath)

            processed_filename = "{timestamp}_{look}_low.jpg".format(
                timestamp=timestamp.strftime(TIMESTAMP_FILENAME_FMT),
                look=look)
            processed_filepath = os.path.join(data_dir, processed_filename)
            shutil.copy(raw_filepath, processed_filepath)
            processed_filepaths.append(processed_filepath)

            if crop is not None:
                crop_image(processed_filepath, processed_filepath, crop)
            if scale is not None:
                reduce_image(processed_filepath, processed_filepath, scale)

    tag = DATA_TAGS.CAM
    queue_filepaths(processed_filepaths, postfix=tag, tarball=False)
    archive_filepaths(raw_filepaths, postfix=tag)
    clear_directory(data_dir)
Esempio n. 11
0
def sbd_components():
    with powered([GPIO.SER, GPIO.SBD, GPIO.IRD]):
        logger.debug("Sleeping for {0} seconds for iridium startup".format(
            SBD_STARTUP_WAIT))
        sleep(SBD_STARTUP_WAIT)
        yield
Esempio n. 12
0
def imm_components():
    with powered([GPIO.SER, GPIO.IMM]):
        sleep(IMM_STARTUP_WAIT)
        yield