Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Last active April 19, 2024 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicFinn/45fb19acaf0c97afae02793fa99c988b to your computer and use it in GitHub Desktop.
Save DominicFinn/45fb19acaf0c97afae02793fa99c988b to your computer and use it in GitHub Desktop.
Signal Strength Logging on Mac
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