Exemplo n.º 1
0
def main():
    """main"""
    config = get_config()

    if config["use_proxy"]:
        proxies = {"http": config["http_proxy_config"], "https": config["https_proxy_config"]}
    else:
        proxies = None

    client = MyInfluxDBClient(
        host=config["host"],
        port=config["port"],
        username=config["username"],
        password=config["password"],
        database=DATABASE_NAME,
        ssl=config["ssl"],
        proxies=proxies,
        verify_ssl=config["verify_ssl"],
    )

    client.validate_db()

    qry_co2 = "select last(value) as last_co2 from co2 WHERE time > now() - 1d"
    if qry_co2:
        for item in client.query(qry_co2):
            _dict = item
        last_co2 = int(_dict[0][u"last_co2"])

    qry_tmp = "select last(value) as last_tmp from tmp WHERE time > now() - 1d"
    if qry_tmp:
        for item in client.query(qry_tmp):
            _dict = item
        last_tmp = int(_dict[0][u"last_tmp"])

    print("Last Temp: " + str(last_tmp) + " last CO2: " + str(last_co2))

    # it above limit play audo message
    if last_co2 > CO2_LIMIT:
        mesg = "Achtung: Der aktuelle C O 2 Wert beträgt " + str(last_co2)
        print(mesg)
        audio.play_tts(mesg, lang="de-DE")
Exemplo n.º 2
0
def main():
    """main"""

    # use lock on socket to indicate that script is already running
    try:
        lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        ## Create an abstract socket, by prefixing it with null.
        lock_socket.bind('\0ow_monitor_lock')
    except socket.error:
        # if script is already running just exit silently
        sys.exit(0)

    device = AirControlMini.auto_detect_sensor()

    devnull = open("/dev/null", "w")
    subprocess.call(["sudo", "/bin/chmod", "a+rw", device], stderr=devnull)

    acm = AirControlMini(device=device)
    acm.connect()

    try:
        config = get_config(config_file=sys.argv[1])
    except IndexError:
        config = get_config()

    if config["use_proxy"]:
        print("using proxy")
        proxies = {
            "http": config["http_proxy_config"],
            "https": config["https_proxy_config"]
        }
    else:
        proxies = None

    client = MyInfluxDBClient(host=config["host"],
                              port=config["port"],
                              username=config["username"],
                              password=config["password"],
                              database=DATABASE_NAME,
                              ssl=config["ssl"],
                              proxies=proxies,
                              verify_ssl=config["verify_ssl"])

    client.validate_db()

    tags = {
        "office": config["office"],
        "sensor": config["sensor"]
    }

    stamp = now()

    for cur_co2, cur_tmp in acm.get_values():
        print("CO2: %4i TMP: %3.1f" % (cur_co2, cur_tmp))

        if now() - stamp > 5:
            print(">>>")
            dataset = client.create_dataset(tags, tmp=cur_tmp, co2=cur_co2)
            client.write_points(dataset)
            stamp = now()