-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqtt.run.py
35 lines (27 loc) · 1003 Bytes
/
mqtt.run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import src.mqtt_lib as mqtt_lib
import os
import time
import json
import paho.mqtt.client as mqtt
import threading
def pub_to_adawirless(data):
ada_client = mqtt.Client()
ada_client.connect('www.adawireless.com')
ada_client.publish('jt_log',data)
ada_client.disconnect()
with open('config/config.json','r') as f:
config_dict = json.load(f)
if __name__ == '__main__':
time_mark = time.strftime( "%Y.%m.%d_%X", time.localtime() ).replace(":", "")
filename = '%s_mqttlog.txt'%time_mark
logfile = os.path.join(os.getcwd(), 'mqttlog', filename)
host_ip = config_dict['IP']
mqtt_class = mqtt_lib.MQTT_Module(host_ip, logfile = logfile)
mqtt_class.subscribe(1,0)
while True:
if mqtt_class.recv_list != []:
msg = mqtt_class.recv_list
pub_task = threading.Thread(target=pub_to_adawirless, args=(msg[0],))
pub_task.daemon =True
pub_task.start()
mqtt_class.recv_list.clear()