Use hostname infor instead of users list
[remote-debug.git] / board / suanzi-support
index eca6e9b..f55b41a 100755 (executable)
@@ -1,12 +1,13 @@
 #!/usr/bin/env python2
 
-from subprocess import call, Popen, PIPE, STDOUT
+from subprocess import call, Popen, PIPE, STDOUT, check_output
 import paho.mqtt.client as mqtt
 import shlex
 import random
 from uuid import getnode as get_mac
 import ast
 import sys
+import re
 
 MQTT_SERVER = 'mqtt.suanzi.ai'
 MQTT_PORT = 1883
@@ -35,7 +36,11 @@ def getAvailablePort(host, ports):
 
 def get_mac_str():
     mac = hex(get_mac())
-    return '{:0>12}'.format(mac[2:-1])
+    m = re.sub('^0x|L$', '', mac)
+    return '{:0>12}'.format(m)
+
+def get_hostname():
+    return check_output("/bin/hostname", shell=True).strip();
 
 def exec_ssh(port):
     if port == None:
@@ -63,7 +68,7 @@ def on_message(client, userdata, msg):
             else:
                 raise Exception ('run ssh failed')
         if payload['command'] == 'list':
-            response = {'from': userdata['id'], 'type':'response', 'command':payload['command'], 'data':'OK'}
+            response = {'from': userdata['id'], 'type':'response', 'command':payload['command'], 'data': get_hostname()}
             client.publish(payload['from'], str(response))