before it would say sending data even if server is unreachable, fixed that

This commit is contained in:
wildercayden 2025-06-25 22:19:50 -04:00
parent 53e0c9f900
commit bfd0f10511

View File

@ -5,7 +5,7 @@ import argparse
import subprocess import subprocess
def ping(host): def ping(host):
result = subprocess.run(['ping', '-c', '1', '-W', '0', host], result = subprocess.run(['ping', '-c', '1', '-W', '1', host],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
# Return True if returncode is 0 (success), else False # Return True if returncode is 0 (success), else False
@ -37,7 +37,12 @@ table_name = args.table
server_ip = args.ip server_ip = args.ip
table = NetworkTables.getTable(table_name) table = NetworkTables.getTable(table_name)
NetworkTables.initialize(server=server_ip) NetworkTables.initialize(server=server_ip)
print ("Sending data to server") if __name__ == '__main__':
ip = server_ip
if ping(ip):
print("sending data to server")
else:
print("rio is unreachable")
print (server_ip, table_name) print (server_ip, table_name)
while True: while True:
cpu = psutil.cpu_percent() cpu = psutil.cpu_percent()