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