import os import sys import time from socket import gethostbyname, gaierror from tools.zookeeper import Zookeeper def is_online(ip): try: addr = gethostbyname(ip) return (os.system(f"ping -c 1 {addr} > /dev/null") == 0) except gaierror: return False if __name__ == "__main__": z = Zookeeper() z.set_device_power(True) ip = str(sys.argv[1]) timeout = int(sys.argv[2]) start_time = time.time() while not is_online(ip): print(f"{ip} not online yet!") if time.time() - start_time > timeout: print("Timed out!") raise TimeoutError() time.sleep(1)
#!/usr/bin/env python3 import sys import time import datetime from common.realtime import Ratekeeper from common.filter_simple import FirstOrderFilter from tools.zookeeper import Zookeeper if __name__ == "__main__": z = Zookeeper() z.set_device_power(True) z.set_device_ignition(False) duration = None if len(sys.argv) > 1: duration = int(sys.argv[1]) rate = 123 rk = Ratekeeper(rate, print_delay_threshold=None) fltr = FirstOrderFilter(0, 5, 1. / rate, initialized=False) measurements = [] start_time = time.monotonic() try: while duration is None or time.monotonic() - start_time < duration: fltr.update(z.read_power()) if rk.frame % rate == 0: print(f"{fltr.x:.2f} W") measurements.append(fltr.x)
#!/usr/bin/env python import sys import time from tools.zookeeper import Zookeeper # Usage: check_consumption.py <averaging_time_sec> <max_average_power_W> # Exit code: 0 -> passed # 1 -> failed if __name__ == "__main__": z = Zookeeper() duration = None if len(sys.argv) > 1: duration = int(sys.argv[1]) try: start_time = time.monotonic() measurements = [] while duration is None or time.monotonic() - start_time < duration: p = z.read_power() print(round(p, 3), "W") measurements.append(p) time.sleep(0.25) except KeyboardInterrupt: pass finally: average_power = sum(measurements) / len(measurements) print(f"Average power: {round(average_power, 4)}W")
#!/usr/bin/env python3 import sys import time from tools.zookeeper import Zookeeper # Usage: check_consumption.py <averaging_time_sec> <max_average_power_W> # Exit code: 0 -> passed # 1 -> failed if __name__ == "__main__": z = Zookeeper() averaging_time_s = int(sys.argv[1]) max_average_power = float(sys.argv[2]) start_time = time.time() measurements = [] while time.time() - start_time < averaging_time_s: measurements.append(z.read_power()) time.sleep(0.1) average_power = sum(measurements) / len(measurements) print(f"Average power: {round(average_power, 4)}W") if average_power > max_average_power: exit(1)
#!/usr/bin/env python from tools.zookeeper import Zookeeper z = Zookeeper() z.set_device_power(False)
#!/usr/bin/env python3 import sys from tools.zookeeper import Zookeeper if __name__ == "__main__": z = Zookeeper() z.set_device_ignition(1 if int(sys.argv[1]) > 0 else 0)
#!/usr/bin/env python3 import time from tools.zookeeper import Zookeeper if __name__ == "__main__": z = Zookeeper() z.set_device_power(True) i = 0 ign = False while 1: voltage = round(z.read_voltage(), 2) current = round(z.read_current(), 3) power = round(z.read_power(), 2) z.set_device_ignition(ign) print( f"Voltage: {voltage}V, Current: {current}A, Power: {power}W, Ignition: {ign}" ) if i > 200: ign = not ign i = 0 i += 1 time.sleep(0.1)