clover/app/python-app/python-app.py
2023-12-13 17:46:13 +01:00

41 lines
920 B
Python

import tkinter as tk
from tkinter import PhotoImage
import requests
import json
url = "http://192.168.218.110/" # Clover node url
root = tk.Tk()
root.title("Clover monitor")
def update_display():
try:
response = requests.get(url)
data = json.loads(response.text)
moisture_status = data["plant_management"]["soil_moisture"]
if moisture_status == "moist":
icon_path = "assets/moist.png"
elif moisture_status == "dry":
icon_path = "assets/dry.png"
elif moisture_status == "wet":
icon_path = "assets/wet.png"
icon = PhotoImage(file=icon_path)
label.config(image=icon)
label.image = icon
root.after(2000, update_display)
except Exception as e:
print("Error:", e)
root.after(2000, update_display)
label = tk.Label(root)
label.pack()
update_display()
root.mainloop()