Fixed iperf and ping address issues

This commit is contained in:
madrigal 2025-09-16 14:17:14 -04:00
parent 4283735722
commit b423d49a2b

View File

@ -129,7 +129,7 @@ def get_current_location(dictionary={}):
# Ping base station
def ping_basestation(
address="10.45.0.1", dictionary={}
address="10.46.0.1", dictionary={}
): # raspberry pi address 192.168.0.29, host1 is 0.30
try:
result = subprocess.run(
@ -157,7 +157,7 @@ def collect_iperf(
duration=10,
is_client=True,
):
if is_client:
if not is_client:
commands = [["iperf3", "-s"]]
else:
commands = [
@ -167,11 +167,12 @@ def collect_iperf(
for command in commands:
try:
# try:
# gps_data = read_gps_data()
# start_distance = calculate_distance(base_location, gps_data)
# except:
# print("Could not collect location")
try:
gps_data = read_gps_data()
start_distance = calculate_distance(base_location, gps_data)
except:
print("Could not collect location")
start_distance = None
# Run the command
result = subprocess.run(
@ -184,11 +185,11 @@ def collect_iperf(
print(f"Error running iperf3: {result.stderr}")
return result.stderr
# try:
# gps_data = read_gps_data()
# end_distance = calculate_distance(base_location, gps_data)
# except:
# pass
try:
gps_data = read_gps_data()
end_distance = calculate_distance(base_location, gps_data)
except:
end_distance = None
# Look for final sender and receiver bitrates (usually in summary lines)
matches = re.findall(
@ -216,6 +217,11 @@ def collect_iperf(
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", output)
sender_bitrate = float(bitrates[-2])
receiver_bitrate = float(bitrates[-1])
if "-R" in command:
test_type = "downlink"
else:
test_type = "uplink"
data = {
"iperf_full": output,
@ -225,22 +231,24 @@ def collect_iperf(
"avgs are calculated with the assumption "
"that all value are in Mbits/sec"
),
# "start_distance": start_distance,
# "end_distance": end_distance,
"start_distance": start_distance,
"end_distance": end_distance,
"type": test_type,
}
print("\nIPERF complete")
print(f"\n{test_type} IPERF complete")
print(f"IPERF sender bitrate: {sender_bitrate}")
print(f"IPERF receiver bitrate: {receiver_bitrate}")
save_data_to_json(data=data, filename=filename)
time.sleep(0.5)
except Exception as e:
print(f"iPerf Error: {e}")
# Collect and send data continuously
def collect_data(filename):
def collect_data(filename, address):
global base_location
global running
@ -257,7 +265,7 @@ def collect_data(filename):
data = get_modem_qnwcfg(dictionary=data)
data = get_modem_qnwinfo(dictionary=data)
data = get_modem_qspn(dictionary=data)
data = ping_basestation(dictionary=data)
data = ping_basestation(dictionary=data, address=address)
data["timestamp"] = time.time()
# Send to server
@ -299,7 +307,8 @@ def collect_sierra_data(filename):
# Main function
def main():
global running
foldername = "data/boat_relay_sept_11"
address = '10.46.0.1'
foldername = "data/boat_relay_sept_17"
os.makedirs(foldername, exist_ok=True)
filename = foldername + "/test_" + str(int(time.time())) + ".json"
@ -315,12 +324,12 @@ def main():
if command == "b" and not running:
print("Starting data collection...")
running = True
threading.Thread(target=collect_data, args=(filename,)).start()
threading.Thread(target=collect_data, args=(filename, address)).start()
elif command == "l":
base_location_data = set_base_location()
save_data_to_json(data=base_location_data, filename=filename)
elif command == "i":
threading.Thread(target=collect_iperf, args=(filename, "10.45.0.1")).start()
threading.Thread(target=collect_iperf, args=(filename, address)).start()
elif command == "s" and running:
print("Stopping data collection...")
running = False