From 5dc7ee083d67ce0321f8632ad9f9abaa57378d63 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Thu, 30 Nov 2023 17:40:49 +0100 Subject: [PATCH] initial --- liveplot.gnu | 9 +++++++++ mqtt.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 liveplot.gnu create mode 100644 mqtt.py diff --git a/liveplot.gnu b/liveplot.gnu new file mode 100644 index 0000000..db081c0 --- /dev/null +++ b/liveplot.gnu @@ -0,0 +1,9 @@ +#set xrange [0:1000] +set yrange [30:420] +set grid y +#plot "temps.txt" with lines +#plot 'temps.txt' using 0:1 with lines, '' using 0:2 with lines +set key outside +plot for [col=1:5] 'temps.txt' using 0:col with lines +pause 1 +reread diff --git a/mqtt.py b/mqtt.py new file mode 100644 index 0000000..30c3a30 --- /dev/null +++ b/mqtt.py @@ -0,0 +1,50 @@ +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() + +