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()