-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_client.py
35 lines (28 loc) · 970 Bytes
/
test_client.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 os
import time
import numpy as np
from ruamel import yaml
from paho.mqtt.client import Client as MQTTClient
from test_server import test_settings, server, topic
ROOT = os.path.abspath(os.path.dirname(__file__))
def run_client(settings):
def on_connect(*args, **kwargs):
print("connected")
def on_message(*args, **kwargs):
print("message received", args, kwargs)
client = MQTTClient()
client.on_connect = on_connect
client.on_message = on_message
client.connect(server, settings["mqtt_settings"]["port"], 60)
t0 = time.time()
while True:
time.sleep(1)
client.loop()
td = time.time()-t0
f = lambda x: np.log(x/10)*10+50
data = '{"meat_temp": %.1f, "oven_temp": %.1f}' % (f(td), f(td+100))
print("publishing data")
client.publish(topic, data)
if __name__ == "__main__":
settings = yaml.load(test_settings, Loader=yaml.Loader)
run_client(settings)