Added a config.ini and made TablePI.py work with it
This commit is contained in:
parent
7f6c950ea7
commit
da1f8b8d02
@ -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
|
25
TablePI.py
25
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
|
||||
|
4
config.ini
Normal file
4
config.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[settings]
|
||||
ip = 10.26.48.2
|
||||
debug_mode = false
|
||||
tables = PiStatus
|
Loading…
Reference in New Issue
Block a user