-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainloop.py
33 lines (23 loc) · 874 Bytes
/
mainloop.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
import json
import threading
import utils.mqttconnection as mqttconn
from timeloop import Timeloop
from datetime import timedelta
from datetime import datetime
tl = Timeloop()
mqttc = None
@tl.job(interval=timedelta(seconds=1))
def sample_job():
print("ts: %d\r\n" %( datetime.timestamp(datetime.now()) ))
mqttc.publish("topic/test", "ts: %d\r\n" %( datetime.timestamp(datetime.now()) ), qos=0, retain=False)
if __name__ == "__main__":
with open('./config/config.json') as json_data_config:
config_data = json.load(json_data_config)
host=config_data["host"]
port=config_data["port"]
username=config_data["username"]
password=config_data["password"]
#open mqtt connection using username and password
mqtt = mqttconn.MqttConnection(host, port, username, password)
mqttc = mqtt.getClient()
tl.start(block=True)