Last active
April 19, 2024 12:30
-
-
Save DominicFinn/45fb19acaf0c97afae02793fa99c988b to your computer and use it in GitHub Desktop.
Signal Strength Logging on Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
def get_wifi_rssi(): | |
# Command to get WiFi details, you can just call this actually if you want all the deets. system_profiler SPAirPortDataType | |
command = ["system_profiler", "SPAirPortDataType"] | |
# Executing the command with all outputs suppressed, otherwise it'll output it in the terminal still | |
result = subprocess.run( | |
command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True | |
) | |
if result.returncode == 0: | |
lines = result.stdout.split("\n") | |
for line in lines: | |
if "Signal / Noise:" in line: | |
signal_noise = line.split(":")[1].strip() | |
split_on_slash = signal_noise.split("/") | |
signal_value_without_dbm = int(split_on_slash[0].strip().split(" ")[0]) | |
noise_value_without_dbm = int(split_on_slash[1].strip().split(" ")[0]) | |
signal_strength = signal_value_without_dbm - noise_value_without_dbm | |
return line, signal_strength | |
else: | |
print("Failed to execute command") | |
return None | |
if __name__ == "__main__": | |
while True: | |
result = get_wifi_rssi() | |
signal_noise = result[0] | |
signal_strength = result[1] | |
print( | |
"📡 " + signal_noise.strip() + ", signal strength: " + str(signal_strength) | |
) | |
now = time.strftime("%Y-%m-%d %H:%M:%S") | |
with open("signal_strength.csv", "a") as f: | |
f.write(now + "," + str(signal_strength) + "\n") | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment