ich habe hier ein Programm, was die Temperatur und die Feuchte von einem Sensor
über eine Socketverbindung empfängt. (Idle, auf einem PC)
Bei der Darstellung durch Matplotlib werden die Limits aber ignoriert. Das Programm läuft
fast identisch schon sein Jahren auf einem Raspberry Zero ohne Probleme, von da
wurde es auch übernommen.
Ich muß noch dazu sagen, das die Darstellung über Matplotlib durch meine Tochter
programmiert wurde, die kann sich das aber auch nicht erklären und hat nicht viel Zeit.
Ich hatte die Frage schon im Forum "forum-raspberrypi.de" gestellt, sicher ist sie hier aber
besser aufgehoben.
Kann da jemand helfen?
Gruß Reinhard
Code: Alles auswählen
import time
from socket import *
import matplotlib.pyplot as plt
import matplotlib.animation as animation
ECHO_PORT = 50007
BUFSIZE = 1024
s = socket(AF_INET, SOCK_STREAM) # Socket erstellen und an Port binden
s.bind(('', ECHO_PORT))
s.listen( 1 )
print ("Server gestartet")
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
temp = []
hum = []
global conn
conn, (remotehost, remoteport) = s.accept() # Warte auf eine Verbindung zum Server
print ('Verbunden mit %s:%s' % (remotehost, remoteport))
def get_data(conn):
data = conn.recv(BUFSIZE) # Empfange daten vom Client
print (data)
try:
data = data.decode()
print('decoded')
except (UnicodeDecodeError, AttributeError):
pass
data = data.split(";")
return data
def animate(i, temp, hum):
d = get_data(conn)
print(d)
temp.append(d[0])
hum.append(d[1])
ax1.clear()
ax1.plot(temp, 'r')
ax1.tick_params(axis='y', labelcolor='r')
ax1.set_ylim([0, 70])
ax2.clear()
ax2.plot(hum, 'b')
ax2.tick_params(axis='y', labelcolor='b')
ax2.set_ylim([0, 70])
i = 5000
ani=animation.FuncAnimation(fig, animate, fargs=(temp, hum), interval=i)
plt.show()