From 6cd1b4fe4b18c538fe73eedd72e7ec584b0b1475 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Sat, 27 Aug 2022 17:21:35 +0200 Subject: [PATCH 1/2] Added GUDE script to read from power meter --- tools/GUDEPowerMeter/README.md | 13 +++++ tools/GUDEPowerMeter/check_gude_modified.py | 60 +++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tools/GUDEPowerMeter/README.md create mode 100644 tools/GUDEPowerMeter/check_gude_modified.py diff --git a/tools/GUDEPowerMeter/README.md b/tools/GUDEPowerMeter/README.md new file mode 100644 index 0000000..db49cea --- /dev/null +++ b/tools/GUDEPowerMeter/README.md @@ -0,0 +1,13 @@ +Slimmed down version of check_gude.py from https://github.com/gudesystems/check_gude.py +for the Blauer Engel für Software Measurements +=============== + +- Create **venv**: `python3 -m venv venv` +- Activate: `source venv/bin/activate` +- Install requests: `pip3 install requests` +- Supply the `-i` parameter for the resolution in ms and the `-x` parameter for the IP + + Example: `python3 check_gude_modified.py -i 100 -x 192.168.178.1` + +The script reports the Watts by default. If you want Joules, which will be the integration +over the time since the last poll, supply `--joules` + diff --git a/tools/GUDEPowerMeter/check_gude_modified.py b/tools/GUDEPowerMeter/check_gude_modified.py new file mode 100644 index 0000000..5364e98 --- /dev/null +++ b/tools/GUDEPowerMeter/check_gude_modified.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +import requests +import json +import time +import subprocess + +def main(ip, resolution, joules): + url = f'http://{ip}/status.json' + + ONLY_VALUES = 0x4000 + cgi = {'components': ONLY_VALUES} # simple-sensors + and only values + + resolution = float(resolution); + + target_sleep_time = resolution/1000.0 + + while True: # loop until CTRL+C + timestamp_before = time.time_ns() + time.sleep(target_sleep_time) + + data = json.loads(requests.get(url, params=cgi, verify=False, auth=None).text) + + # print(data) # DEBUG + timestamp_after = time.time_ns() + effective_sleep_time = timestamp_after - timestamp_before + # print(effective_sleep_time / 1_000_000_000) # DEBUG + conversion_factor = effective_sleep_time / 1_000_000 # we want microjoule. Therefore / 10**9 to get seconds and then * 10**3 to get mJ + if joules: + print(int(timestamp_after / 1_000), int(data["sensor_values"][0]['values'][0][4]['v']*conversion_factor), flush=True) + else: + print(int(timestamp_after / 1_000), int(data["sensor_values"][0]['values'][0][4]['v']), flush=True) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument("-i", type=int, help="Resolution") + parser.add_argument("-x", type=str, help="IP") + parser.add_argument("--joules", action='store_true', help="Report Joules instead of Watts") + + args = parser.parse_args() + + if args.i is None: + parser.print_help() + print("Please supply -i to set resolution in milliseconds") + exit(2) + + if args.x is None: + parser.print_help() + print("Please supply -x to set the IP where to find the JSON API from GUDE") + exit(2) + + if args.joules is None: + parser.print_help() + print("Please supply -x to set the IP where to find the JSON API from GUDE") + exit(2) + + main(args.x, args.i, args.joules) -- GitLab From d6424685045b367522dfdf2f19d087ddd7854c69 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Sat, 27 Aug 2022 17:27:25 +0200 Subject: [PATCH 2/2] Help was wrong --- tools/GUDEPowerMeter/check_gude_modified.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/GUDEPowerMeter/check_gude_modified.py b/tools/GUDEPowerMeter/check_gude_modified.py index 5364e98..9cf3407 100644 --- a/tools/GUDEPowerMeter/check_gude_modified.py +++ b/tools/GUDEPowerMeter/check_gude_modified.py @@ -54,7 +54,7 @@ if __name__ == "__main__": if args.joules is None: parser.print_help() - print("Please supply -x to set the IP where to find the JSON API from GUDE") + print("Please supply --joules to switch to Joules reporting") exit(2) main(args.x, args.i, args.joules) -- GitLab