Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with coding #39

Open
Minoslo opened this issue Feb 12, 2024 · 5 comments
Open

Help with coding #39

Minoslo opened this issue Feb 12, 2024 · 5 comments

Comments

@Minoslo
Copy link

Minoslo commented Feb 12, 2024

Is there any chance to help me to implement this code for a GUI?
What I exactly need is to run few commands to get SoC and temperature values. I'm new on this topic and any help would be appreciated. I have been reading the protocol and I think I understand how it works but I don't know how to send a command using a python script.

@Frankkkkk
Copy link
Owner

Hi,
A simple "hello" is always welcome :-)
Basically, the library implements most of the commands. There are some examples here.

Once you choose a GUI lib (tkinter for example), you just have to interface with this library and it should work :-)

Maybe I'll write an example if I have the time, but I don't guarantee it.
Cheers

@Minoslo
Copy link
Author

Minoslo commented Feb 12, 2024

Oh man...I'm so sorry, for real. My comment was rude (english is not my native language so I was stupdly focus trying to explain myself), I apologize. Let me start over.
Hello mate ,
Your lib is really awesome and it had helped me so much on my project. I was able to use most of the commands except "p.get.values()".
I found your project meanwhile I was trying to use the pylon protocol myself but I don't have enough knowledge to do it. I will try to do what you told me. I'm currently using "pysimplegui" to make my GUI. Any example would be appreciated if you have time.
Thank you very much for the fast answer tho.
Cheers.

@Frankkkkk
Copy link
Owner

Frankkkkk commented Feb 12, 2024

No problem ;-)
Something like that should do the job:
image

import tkinter as tk
from time import time
from pylontech import Pylontech

p = Pylontech()

def update():
    vals = p.get_values()
    bv = vals.Module[0].Voltage
    bi = vals.Module[0].Current
    tot_power = vals.TotalPower
    batv_v.config(text=f"{bv} V")
    bati_v.config(text=f"{bi} A")
    batp_v.config(text=f"{tot_power} W")
    root.after(5000, update)

# Create the main window
root = tk.Tk()
root.title("Pylontech Display")

# Create a label widget for displaying the time
batv_l = tk.Label(root, text="Battery Voltage")
batv_l.grid(column=0, row=0)
batv_v = tk.Label(root, text="xx V")
batv_v.grid(column=1, row=0)

bati_l = tk.Label(root, text="Battery Current")
bati_l.grid(column=0, row=1)
bati_v = tk.Label(root, text="xx A")
bati_v.grid(column=1, row=1)

batp_l = tk.Label(root, text="Battery Power")
batp_l.grid(column=0, row=2)
batp_v = tk.Label(root, text="xx W")
batp_v.grid(column=1, row=2)

time_label2 = tk.Label(root, font=('Helvetica', 48), pady=20)
#time_label2.pack()

# Initialize the time display
update()

# Start the Tkinter event loop
root.mainloop()

Warning: it's horrible code straight out of gpt, but it kinda works

Cheers

@Frankkkkk
Copy link
Owner

PS: If you create a nice UI, it'd be great if you could do an MR someday so we can add it to the repo !

@Minoslo
Copy link
Author

Minoslo commented Feb 13, 2024

Hello mate 😊,
Thank you a lot! That's the example that I need it to know how the info was grouped within the response.
When I finish the GUI, you can be sure I will do an MR and if you like the GUI enough, it would be awesome to add it here and help another people.
Thank you one more time for being so quick to answer.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants