3 from subprocess import call, Popen, PIPE, STDOUT
4 import paho.mqtt.client as mqtt
8 MQTT_SERVER = 'mqtt.suanzi.ai'
10 URI = 'debug@autossh.suanzi.ai'
12 def on_connect(client, userdata, flags, rc):
14 client.subscribe(id + "-response")
15 print("Connected with result code "+str(rc))
16 client.publish(id + '-request', 0)
18 def on_message(client, userdata, msg):
20 print(msg.topic+" "+str(msg.payload))
21 if msg.topic == id + '-response':
23 print 'run "ssh ' + URI + ' -p ' + str(port) + '" to connect to device (%s)' % id
26 if __name__ == '__main__':
27 parser = argparse.ArgumentParser(description='Choose an avaiable port and run ssh.')
28 parser.add_argument('-i', '--id', dest='id', help='the unique id of remote machine, such as rpdzkj-080027a6f8dc, where the rpdzkj is the user, and 080027a6f8dc is the mac addres', required=True)
29 #parser.add_argument('connect', help='list all connected devices')
30 #parser.add_argument('list', help='list all connected devices')
31 args = parser.parse_args()
33 client = mqtt.Client()
35 client.on_connect = on_connect
36 client.on_message = on_message
37 client.connect(MQTT_SERVER, MQTT_PORT, 60)