X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=mqtt-client.py;h=cbc7cd46177f3cd8dabd772bf96af5e4d303f46f;hb=a371c0f6b2d994a074eaeb56a2125cb4c0af85f8;hp=98215fc150e403744d32a7c7460b07d5c8d7a12d;hpb=e7a0ece8ec81cb8601c10c40af98867b66a2c531;p=remote-debug.git diff --git a/mqtt-client.py b/mqtt-client.py index 98215fc..cbc7cd4 100644 --- a/mqtt-client.py +++ b/mqtt-client.py @@ -4,40 +4,25 @@ from subprocess import call, Popen, PIPE, STDOUT import paho.mqtt.client as mqtt import argparse -ID = 'rpdzkj' -MQTT_SERVER = 'mqtt.suanzi.zi' +MQTT_SERVER = 'mqtt.suanzi.ai' MQTT_PORT = 1883 -SSH_SERVER = 'autossh.suanzi.ai' -PORT_RANGE = (20000, 30000) -USER = 'autossh' -PASSWORD = 'hard2guess' -# -#def run_ssh (port): -# pass -# -# -#class MyClient(mqtt.Client): -# def __init__(self): -# -# -# -def on_connect(client, userdata, flags, rc): - client.subscribe("rpdzkj-response") - print("Connected with result code "+str(rc)) - client.publish('rpdzkj-request', 33) +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Choose an avaiable port and run autossh.') + 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) + args = parser.parse_args() + id = args.id -def on_message(client, userdata, msg): - print(msg.topic+" "+str(msg.payload)) - if msg.topic == 'rpdzkj-rsponse': - print str(msg.payload) + def on_connect(client, userdata, flags, rc): + client.subscribe(id + "-response") + print("Connected with result code "+str(rc)) + client.publish(id + '-request', 0) + + def on_message(client, userdata, msg): + print(msg.topic+" "+str(msg.payload)) + if msg.topic == id + '-response': + print 'port is', str(msg.payload) -if __name__ == '__main__': -# parser = argparse.ArgumentParser(description='Choose an avaiable port and run autossh.') -# parser.add_argument('-i', '--id', dest='id', help='board unique id, rpdzkj|firefly', required=True) -# args = parser.parse_args() -# id = args.id -# client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message