#!/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
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:
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))