|
@@ -1,136 +1,136 @@
|
|
|
-import pymysql
|
|
|
-import paho.mqtt.client as mqtt
|
|
|
-import json
|
|
|
-import threading
|
|
|
-from time import sleep as sl
|
|
|
-from datetime import datetime as dt
|
|
|
-from concurrent.futures import ThreadPoolExecutor
|
|
|
-
|
|
|
-
|
|
|
-class MQTT(object):
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- def __init__(self):
|
|
|
- self.res = 0
|
|
|
-
|
|
|
- def on_connect(client, userdata, flags, rc):
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- client.subscribe('AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e/Log')
|
|
|
-
|
|
|
-
|
|
|
- def on_message(client, userdata, msg):
|
|
|
- msg = msg
|
|
|
-
|
|
|
- payload = json.loads(msg.payload.decode('utf-8'))
|
|
|
- self.res = payload
|
|
|
- print('self.res = payload :', payload)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- self.client = mqtt.Client()
|
|
|
-
|
|
|
- self.command = {'tank-number':'', 'command':'coffee_mqtt_restart', 'value':''}
|
|
|
-
|
|
|
- def thread_job(self):
|
|
|
-
|
|
|
- self.client.on_connect = on_connect
|
|
|
-
|
|
|
- self.client.on_message = on_message
|
|
|
-
|
|
|
- self.client.username_pw_set("aisky-client", "aiskyc")
|
|
|
-
|
|
|
-
|
|
|
- self.client.connect("60.250.156.234", 1883, 60)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- self.client.loop_forever()
|
|
|
-
|
|
|
- mqtt_subscribe_thread = threading.Thread(target=thread_job, args=(self,))
|
|
|
- mqtt_subscribe_thread.daemon = True
|
|
|
- mqtt_subscribe_thread.start()
|
|
|
-
|
|
|
- sl(1)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- def mqttPublish(self, topic, command):
|
|
|
- self.client.publish(topic, json.dumps(command))
|
|
|
- print('json.dumps(command):', json.dumps(command))
|
|
|
-
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- mqtt = MQTT()
|
|
|
- try:
|
|
|
-
|
|
|
- mqtt.mqttPublish('AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e', mqtt.command)
|
|
|
- print('mqttPublish_test')
|
|
|
- while True:
|
|
|
- pass
|
|
|
- except KeyboardInterrupt:
|
|
|
- mqtt.pool.shutdown(wait=True)
|
|
|
- mqtt.cursor.close()
|
|
|
+import pymysql
|
|
|
+import paho.mqtt.client as mqtt
|
|
|
+import json
|
|
|
+import threading
|
|
|
+from time import sleep as sl
|
|
|
+from datetime import datetime as dt
|
|
|
+from concurrent.futures import ThreadPoolExecutor
|
|
|
+
|
|
|
+
|
|
|
+class MQTT(object):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.res = 0
|
|
|
+
|
|
|
+ def on_connect(client, userdata, flags, rc):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ client.subscribe('AISKY/Coffee/MK-G/b8:27:eb:7e:24:78/Log')
|
|
|
+
|
|
|
+
|
|
|
+ def on_message(client, userdata, msg):
|
|
|
+ msg = msg
|
|
|
+
|
|
|
+ payload = json.loads(msg.payload.decode('utf-8'))
|
|
|
+ self.res = payload
|
|
|
+ print('self.res = payload :', payload)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.client = mqtt.Client()
|
|
|
+
|
|
|
+ self.command = {'tank-number':'', 'command':'coffee_mqtt_restart', 'value':''}
|
|
|
+
|
|
|
+ def thread_job(self):
|
|
|
+
|
|
|
+ self.client.on_connect = on_connect
|
|
|
+
|
|
|
+ self.client.on_message = on_message
|
|
|
+
|
|
|
+ self.client.username_pw_set("aisky-client", "aiskyc")
|
|
|
+
|
|
|
+
|
|
|
+ self.client.connect("60.250.156.234", 1883, 60)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.client.loop_forever()
|
|
|
+
|
|
|
+ mqtt_subscribe_thread = threading.Thread(target=thread_job, args=(self,))
|
|
|
+ mqtt_subscribe_thread.daemon = True
|
|
|
+ mqtt_subscribe_thread.start()
|
|
|
+
|
|
|
+ sl(1)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def mqttPublish(self, topic, command):
|
|
|
+ self.client.publish(topic, json.dumps(command))
|
|
|
+ print('json.dumps(command):', json.dumps(command))
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ mqtt = MQTT()
|
|
|
+ try:
|
|
|
+
|
|
|
+ mqtt.mqttPublish('AISKY/Coffee/MK-G/b8:27:eb:7e:24:78', mqtt.command)
|
|
|
+ print('mqttPublish_test')
|
|
|
+ while True:
|
|
|
+ pass
|
|
|
+ except KeyboardInterrupt:
|
|
|
+ mqtt.pool.shutdown(wait=True)
|
|
|
+ mqtt.cursor.close()
|
|
|
mqtt.db.close()
|