Last active
June 7, 2024 05:22
-
-
Save xssfox/a5f06a3aa6f864cdde05094966379148 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 pulsectl | |
import time | |
import paramiko | |
import traceback | |
while 1: | |
try: | |
pulse = pulsectl.Pulse('my-client-name') | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect("aprs.foxden", username="pi") | |
on_command = "sudo /root/MotorShield/rf.py icom" | |
off_command = "sudo /root/MotorShield/rf.py digi" | |
state = False | |
while 1: | |
time.sleep(1) | |
if [x for x in pulse.sink_input_list() if "wfview" in x.proplist['application.name']]: | |
if state == False: | |
print("detected connection") | |
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(on_command) | |
print(ssh_stdout.readlines()) | |
state = True | |
else: | |
if state == True: | |
print("lost connection") | |
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(off_command) | |
print(ssh_stdout.readlines()) | |
state = False | |
except: | |
traceback.print_exc() | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment