Witajcie, po niedługiej przerwie wróciłem do Pythona, poprzednio utknąłem w tym samym punkcie co teraz. Dokładnie chodzi o odświeżanie całodobowe parametrów odczytywanych z pliku json. Program ma być częścią większego projektu u mnie w domu. Jedna z maszynek Raspberry odczytuje parametry z innych urządzeń( jak dotej pory z dwóch) i na jednym pokazuje odczytane wyniki. Do tego celu korzystam z tkinter i funkcji after. Wyniki odczytywane są co minutę. Po kilku godzinach (6-7)program zawiesza swoje działanie. Co zrobić, podejrzewam że pewnie zapycha się pamięć i dlatego program się zatrzymuje. Czu ktoś może spotkał się z podobnym problemem?
kod:
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 16 12:40:36 2021
@author: ilodz
"""
import pandas as pd
import json
import requests
import datetime as dt
import tkinter as tk
from time import strftime
class Application:
def __init__(self):
self.window = tk.Tk()
self.temperatura = tk.StringVar()
self.cisnienie = tk.StringVar()
self.temperatura_bojler = tk.StringVar()
self.data_sypialnia = tk.StringVar()
self.godzina_sypialnia = tk.StringVar()
self.temp_sypialnia = tk.StringVar()
self.cisn_sypialnia = tk.StringVar()
self.kolor_temp_sypialnia = tk.StringVar()
self.kolor_bojler = tk.StringVar()
self.window.geometry("800x600+0+0")
self.window.configure(background="black")
self.window.title("Inteligentny dom - stacja bazowa")
self.parametry()
self.rama = tk.LabelFrame(self.window, text="Inteligentny Dom", bg="black", fg="white", padx=5, pady=5)
self.rama.pack(padx=5, pady=5)
self.r1 = tk.LabelFrame(self.rama, padx=5, pady=5)
self.r1.configure(background="black")
self.r1.pack(fill="both", expand="yes")
self.linia0 = tk.Label(self.r1, textvariable=self.data_sypialnia,font=("Arial", 40), fg="green", bg="black")
self.linia0.grid(row=0, column=0)
self.linia0a = tk.Label(self.r1,text = " " ,font=("Arial", 40), fg="green", bg="black")
self.linia0a.grid(row=0, column=1)
self.linia1 = tk.Label(self.r1, textvariable=self.godzina_sypialnia,font=("Arial", 70), fg="silver", bg="black")
self.linia1.grid(row=0, column=2)
self.rama1 = tk.LabelFrame(self.window, text="Parametry", bg="black", fg="white", padx=5, pady=5)
self.rama1.pack(padx=5, pady=5)
self.r2 = tk.LabelFrame(self.rama1, padx=5, pady=5)
self.r2.configure(background="black")
self.r2.pack(fill="both", expand="yes")
self.linia5 = tk.Label(self.r2, text="Temperatura w sypialni: ", font=("Arial", 17), fg="white", bg="black")
self.linia5.grid(row=0, column=0, sticky = "w")
self.linia5a= tk.Label(self.r2, textvariable=self.temp_sypialnia, font=("Arial", 20), fg=self.kolor_temp_sypialnia.get(), bg="black")
self.linia5a.grid(row=0, column=1, sticky = "w")
self.linia5b = tk.Label(self.r2, text=" °C ", font=("Arial", 17), fg="white", bg="black")
self.linia5b.grid(row=0, column=2, sticky = "w")
self.linia6 = tk.Label(self.r2, text="Ciśnienie powietrza: ", font=("Arial", 17), fg="white", bg="black")
self.linia6.grid(row=1,column=0,sticky = "w")
self.linia6a= tk.Label(self.r2, textvariable=self.cisn_sypialnia, font=("Arial", 20), fg="silver", bg="black")
self.linia6a.grid(row=1, column=1, sticky = "w")
self.linia6b = tk.Label(self.r2, text=" hPa ", font=("Arial", 17), fg="white", bg="black")
self.linia6b.grid(row=1, column=2, sticky = "w")
self.r3 = tk.LabelFrame(self.rama1, padx=5, pady=8)
self.r3.configure(background="black")
self.r3.pack(fill="both", expand="yes")
self.linia7 = tk.Label(self.r2, text="Temperatura bojlera: ", font=("Arial", 17), fg="white", bg="black")
self.linia7.grid(row=2,column=0, sticky = "w")
self.linia8 = tk.Label(self.r2, textvariable=self.temperatura_bojler, font=("Arial", 17), fg=self.kolor_bojler.get(), bg="black")
self.linia8.grid(row=2,column=1, sticky = "w")
self.linia9 = tk.Label(self.r2, text=" °C ", font=("Arial", 17), fg="white", bg="black")
self.linia9.grid(row=2, column=2, sticky = "w")
self.window.mainloop()
def parametry(self):
self.readDane2=requests.get("http://192.168.1.80/data_sypialnia.json")
self.task2 = self.readDane2.json()
self.data_sypialnia.set(self.task2["data"])
self.godzina_sypialnia.set(self.task2["godzina"])
self.temp_sypialnia.set(self.task2["temperatura_sypialnia"])
self.cisn_sypialnia.set(self.task2["cisnienie_sypialnia"])
# przekształcanie koloru temperatury w sypialni
x1 = self.temp_sypialnia.get()
x1 = float(x1)
if x1>25:
self.kolor_temp_sypialnia.set("red")
elif x1<21:
self.kolor_temp_sypialnia.set("blue")
else:
self.kolor_temp_sypialnia.set("green")
self.readDane=requests.get("http://192.168.1.81/temp_bojler.json")
self.task = self.readDane.json()
self.temperatura_bojler.set(self.task["temperatura_bojlera_1"])
# przekształcanie koloru temperatury wody w bojlerze
x2 = self.temperatura_bojler.get()
x2 = float(x2)
if x2< 40:
self.kolor_bojler.set("blue")
elif x2 > 40 and x2 < 60:
self.kolor_bojler.set("orange")
elif x2 > 60 and x2 < 80:
self.kolor_bojler.set("red")
else:
self.temperatura_bojler.set("!!!")
self.kolor_bojler.set("red")
self.window.after(60000, self.parametry)
apl = Application()