diff --git a/README.md b/README.md index be8caa4..c12169e 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,6 @@ Examples - --help +Also the config.ini file can toggle debug and change the IP and table permantly+ (Or until you touch config.ini again) + The TableLaptop.py is 1 poorly named because it will work on anything and 2 can be used to test the tablePI.py, just enter the devices IP (example --ip 192.168.1.76) in TablePI.py and the PI will send data to the device, and the TableLaptop.py will show you the output of what the PI is sending \ No newline at end of file diff --git a/TablePI.py b/TablePI.py index 796c0d2..b935c8f 100644 --- a/TablePI.py +++ b/TablePI.py @@ -3,6 +3,14 @@ import time import psutil import argparse import subprocess +import configparser + +config = configparser.ConfigParser() +config.read('config.ini') + +ip = config.get('settings', 'ip') +debug_mode = config.getboolean('settings', 'debug_mode') +table = config.get('settings', 'tables') def ping(host): result = subprocess.run(['ping', '-c', '1', '-W', '1', host], @@ -16,14 +24,14 @@ parser = argparse.ArgumentParser(description="Run TablePi client") parser.add_argument( '--table', type=str, - default='PiStatus', + default=table, help='Name of the NetworkTable (default: %(default)s)' ) parser.add_argument( '--ip', type=str, - default='10.26.48.2', + default=ip, help='IP address of the server (default: %(default)s)' ) parser.add_argument( @@ -37,12 +45,11 @@ table_name = args.table server_ip = args.ip table = NetworkTables.getTable(table_name) NetworkTables.initialize(server=server_ip) -if __name__ == '__main__': - ip = server_ip - if ping(ip): - print("sending data to server") - else: - print("rio is unreachable") +ip = server_ip +if ping(ip): + print("sending data to server") +else: + print("rio is unreachable") print (server_ip, table_name) while True: cpu = psutil.cpu_percent() @@ -65,7 +72,7 @@ while True: table.putNumber("CPU Usage", cpu) table.putNumber("Temperature", float(cputemp) if cputemp != "Unavailable" else -1) table.putNumber("Memory", mem.used // (1024**2)) - if args.debug: + if args.debug or debug_mode: print("mem", mem.used // 1024**2,"temp", float(cputemp) if cputemp != "Unavailable" else -1,"CPU", cpu) if __name__ == '__main__': ip = server_ip diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..fb31ced --- /dev/null +++ b/config.ini @@ -0,0 +1,4 @@ +[settings] +ip = 10.26.48.2 +debug_mode = false +tables = PiStatus