You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
from time import perf_counter
|
|
import threading
|
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
|
import paho.mqtt.client as mqtt
|
|
|
|
# The callback for when the client receives a CONNACK response from the server.
|
|
def on_connect(client, userdata, flags, rc):
|
|
print("Connected with result code "+str(rc))
|
|
# client.subscribe("/Filamentanlage/01_Extruder/kraft")
|
|
client.subscribe("/Filamentanlage/01_Extruder/state/temp1")
|
|
|
|
def on_message(client, userdata, msg):
|
|
print(msg.topic+" "+str(msg.payload))
|
|
update1(msg.payload)
|
|
|
|
win = pg.GraphicsLayoutWidget(show=True)
|
|
win.setWindowTitle('pyqtgraph example: Scrolling Plots')
|
|
|
|
p1 = win.addPlot()
|
|
data1 = np.zeros(5000)
|
|
curve1 = p1.plot(data1)
|
|
ptr1 = 0
|
|
def update1(val):
|
|
global data1, ptr1
|
|
data1[:-1] = data1[1:] # shift data in the array one sample left
|
|
# (see also: np.roll)
|
|
data1[-1] = val
|
|
curve1.setData(data1)
|
|
|
|
ptr1 += 1
|
|
|
|
|
|
client = mqtt.Client()
|
|
client.on_connect = on_connect
|
|
client.on_message = on_message
|
|
client.connect("192.168.5.2", 1883, 60)
|
|
|
|
thread = threading.Thread(target=client.loop_forever)
|
|
thread.setDaemon(True)
|
|
thread.start()
|
|
|
|
timer = pg.QtCore.QTimer()
|
|
timer.start(50)
|
|
|
|
pg.exec()
|
|
|
|
|