Added debug feature
This commit is contained in:
parent
e7eacbdede
commit
53e0c9f900
21
TablePI.py
21
TablePI.py
@ -2,6 +2,14 @@ from networktables import NetworkTables
|
||||
import time
|
||||
import psutil
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
def ping(host):
|
||||
result = subprocess.run(['ping', '-c', '1', '-W', '0', host],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
# Return True if returncode is 0 (success), else False
|
||||
return result.returncode == 0
|
||||
|
||||
parser = argparse.ArgumentParser(description="Run TablePi client")
|
||||
|
||||
@ -18,6 +26,11 @@ parser.add_argument(
|
||||
default='10.26.48.2',
|
||||
help='IP address of the server (default: %(default)s)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--debug',
|
||||
action='store_true',
|
||||
help='It will show what data is being sent and also pings the rio (to show you if there is a network error)'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
table_name = args.table
|
||||
@ -47,5 +60,13 @@ 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:
|
||||
print("mem", mem.used // 1024**2,"temp", float(cputemp) if cputemp != "Unavailable" else -1,"CPU", cpu)
|
||||
if __name__ == '__main__':
|
||||
ip = server_ip
|
||||
if ping(ip):
|
||||
print(f"{ip} is reachable")
|
||||
else:
|
||||
print(f"{ip} is unreachable")
|
||||
time.sleep(1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user