示例#1
0
def json_file_reading(reading):
    try:
        if "jsonfile.enabled" not in configs or configs[
                "jsonfile.enabled"] != 1:
            return

        reading_for_json = {"level": reading, "timestamp": time.time() * 1000}

        with open(configs["jsonfile.path"], mode='w') as jsonfile:
            json.dump(reading_for_json, jsonfile)
        os.chmod(configs["jsonfile.path"],
                 stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
        log.log_restarts("wrote json file to {filename}".format(
            filename=configs["jsonfile.path"]))
    except Exception as ex:
        log.log_errors("problem streaming to json file!")
示例#2
0
def initialstate_stream_reading(reading):
    if "initialstate.enabled" not in configs or configs[
            "initialstate.enabled"] != 1:
        return

    try:
        from ISStreamer.Streamer import Streamer
        streamer = Streamer(bucket_name=configs["initialstate.bucket_name"],
                            bucket_key=configs["initialstate.bucket_key"],
                            access_key=configs["initialstate.access_key"])
        streamer.log(key=configs["initialstate.item_key"], value=reading)
        streamer.flush()
        streamer.close()
        log.log_restarts("sent initialstate reading")
    except Exception as ex:
        log.log_errors("problem streaming reading to initialstate!")
示例#3
0
def water_reading():
    """Initiate a water level reading."""
    pit_depth = configs["pit_depth"]
    trig_pin = configs["trig_pin"]
    echo_pin = configs["echo_pin"]
    temperature = configs["temperature"]
    unit = configs["unit"]

    value = sensor.Measurement(trig_pin, echo_pin, temperature, unit)

    try:
        raw_distance = value.raw_distance(sample_wait=0.3)
    except SystemError:
        log.log_errors(
            "**ERROR - Signal not received. Possible cable or sensor problem.")
        exit(0)

    return round(value.depth(raw_distance, pit_depth), 1)
示例#4
0
def water_reading():
    '''Initiate a water level reading.'''
    pit_depth = configs['pit_depth']
    trig_pin = configs['trig_pin']
    echo_pin = configs['echo_pin']
    temperature = configs['temperature']
    unit = configs['unit']

    value = sensor.Measurement(trig_pin, echo_pin, temperature, unit)

    try:
        raw_distance = value.raw_distance(sample_wait=0.3)
    except SystemError:
        log.log_errors(
            "**ERROR - Signal not received. Possible cable or sensor problem.")
        exit(0)

    if unit == 'imperial':
        return round(value.depth_imperial(raw_distance, pit_depth), 1)
    if unit == 'metric':
        return round(value.depth_metric(raw_distance, pit_depth), 1)