import requests import datetime import time def GetVoltageInfo(): return_voltage = None return_status = None try: # TODO change this IP address to match your system r = requests.get('http://192.168.1.10:8000/cmd/status_json') status_output = r.json() for entry in status_output["Status"]: if isinstance(entry, dict): for key, value in entry.items(): if key == "Engine": if isinstance(value, list): for subentry in value: if isinstance(subentry, dict): if "Output Voltage" in subentry.keys(): return_voltage = subentry["Output Voltage"] elif "Engine State" in subentry.keys(): return_status = subentry["Engine State"] else: continue return return_voltage, return_status except Exception as e1: print("Error: " + str(e1)) return return_voltage, return_status while True: voltage_date, status_data = GetVoltageInfo() currenttime = datetime.datetime.now() print(str(currenttime) + "," + voltage_date + "," + status_data) # sleep for 30 seconds time.sleep(30)