Tomcat42 / pylontech-python

Functions to communicate to Pylontech Batteries using RS-485 serial communication
MIT License
11 stars 7 forks source link

Work with PI? #7

Closed reviscan closed 1 year ago

reviscan commented 1 year ago

Hi,

wanted to use this software under PI ( PI4...) but get stuck during installation. Did you test it on windows?

run 'python3 ./setup.py install' I done sudo python3 ./setup.py install output was fine.

But when start to start ( example)

pi@pi4:~/git/pylontech-python $ examples/getStackedBatteriesInfos/main.py Traceback (most recent call last): File "/home/pi/git/pylontech-python/examples/getStackedBatteriesInfos/main.py", line 2, in from pylontech import PylontechStack ImportError: cannot import name 'PylontechStack' from 'pylontech' (/usr/local/lib/python3.9/dist-packages/python_pylontech-0.2.1-py3.9.egg/pylontech/init.py)

Any idears? I'm just a python user... not programmer -:) python --version Python 3.9.2

Thanx for help

BR

Andreas

Tomcat42 commented 1 year ago

oh sorry - looks like i have to fix the description.

Windows... - not for me - sorry (but it may work ... (thinking about replace /sev/ttyUSB0 to COMx in your case)

with a raspberry start here: (i use a Raspi 4 and a cheap - 4€ -  RS485 converter)

@.***:~ $ pip install pylontec            # this installs the python module from pypi.org Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting pylontech Downloading https://www.piwheels.org/simple/pylontech/pylontech-0.1.2-py3-none-any.whl (10.0 kB) Requirement already satisfied: pyserial in /home/bernd/.local/lib/python3.9/site-packages (from pylontech) (3.5) Installing collected packages: pylontech Successfully installed pylontech-0.1.2

@.***:~ $ python3 ~/workbench/pylontech- python/examples/getStackedBatteriesInfos/main.py evaluating the stack of batteries (0..n batteries) b'20024xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20034xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ('Timeout waiting for an answer.',) number of batteries found: 2 received data: {'SerialNumbers': ['xxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxx'], 'Calculated': {}} b'20024600xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20024600xxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20024600xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx'

could you try it?

Best Regards Bernd.

On Fri, 2022-12-30 at 02:42 -0800, reviscan wrote:

Hi, wanted to use this software under PI ( PI4...) but get stuck during installation. Did you test it on windows?

run 'python3 ./setup.py install' I done sudo python3 ./setup.py install output was fine. But when start to start ( example) @.:~/git/pylontech-python $ examples/getStackedBatteriesInfos/main.py Traceback (most recent call last): File "/home/pi/git/pylontech- python/examples/getStackedBatteriesInfos/main.py", line 2, in from pylontech import PylontechStack ImportError: cannot import name 'PylontechStack' from 'pylontech' (/usr/local/lib/python3.9/dist-packages/python_pylontech-0.2.1- py3.9.egg/pylontech/init.py) Any idears? I'm just a python user... not programmer -:) python --version Python 3.9.2 Thanx for help BR Andreas — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>

reviscan commented 1 year ago

Hi, Thanx so far... I'm testing only under linux -:) PI4...1GB..new image.rashpian

pip install pylontec -> TYPO!

must be:

sudo pip install pylontech

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: pylontech in /usr/local/lib/python3.9/dist-packages/pylontech-0.1.2-py3.9.egg (0.1.2) Requirement already satisfied: pyserial in /usr/lib/python3/dist-packages (from pylontech) (3.5b0

But same result... python3 examples/getStackedBatteriesInfos/main.py Traceback (most recent call last): File "/home/pi/git/pylontech-python/examples/getStackedBatteriesInfos/main.py", line 2, in from pylontech import PylontechStack ImportError: cannot import name 'PylontechStack' from 'pylontech' (/usr/local/lib/python3.9/dist-packages/python_pylontech-0.2.1-py3.9.egg/pylontech/init.py)

Python broken? Version? python --version Python 3.9.2

or how can I remove the old one?

BR

reviscan commented 1 year ago

Hi, uninstall worked..

sudo pip uninstall pylontech

then

sudo pip install pylontech Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting pylontech Downloading https://www.piwheels.org/simple/pylontech/pylontech-0.1.2-py3-none-any.whl (10.0 kB) Requirement already satisfied: pyserial in /usr/lib/python3/dist-packages (from pylontech) (3.5b0) I nstalling collected packages: pylontech Successfully installed pylontech-0.1.2

Now it works... but shows only 3 insted of 6 packs?!

python3 examples/getStackedBatteriesInfos/main.py evaluating the stack of batteries (0..n batteries) b'20024600C0220250505442483032323039363132353230F6D6' b'20034600C0220350505442483032323039363132333734F6CD' b'20044600C0220450505442483032323039363132333635F6CB' number of batteries found: 3 received data: {'SerialNumbers': ['PPTBH02209612520', 'PPTBH02209612374', 'PPTBH02209612365'], 'Calculated': {}} b'20024600C06E00020F0CC60CC50CC80CC50CC80CC90CC60CC60CC80CC90CC90CC90CC30CC60CC3050BA50B870B870B910B910006BFA42CEC02C350017DE4CE' b'20024600B01402D002B79800FAFF06C0F92D' b'20024600C04000020F000000000000000000000000000000050000000000000000000E800000F161' b'20034600C06E00030F0CC50CC20CC40CC60CC70CC40CC70CC50CC40CC50CC60CC90CC70CC90CC7050BAF0B910B910B9B0B9B0006BF972AF802C3500160E4D6' b'20034600B01403D002B79800FAFF06C0F92B' b'20034600C04000030F000000000000000000000000000000050000000000000000000E800000F15F'

Tomcat42 commented 1 year ago

search for "manualBattcountLimit=3) and replace it as you wish:

x = PylontechStack("/dev/ttyUSB0", baud=115200, manualBattcountLimit=3) => x = PylontechStack("/dev/ttyUSB0", baud=115200, manualBattcountLimit=6)

reviscan commented 1 year ago

Yes now it works with my 6 US2000B Parts. Thanx. Do you know if it also works with US2000C devices? Will check this week. I wrote a example for emoncms to upload the batteries percntage there. -> shall we add to example?

Tomcat42 commented 1 year ago

On Sun, 2023-01-01 at 07:31 -0800, reviscan wrote:

Yes now it works with my 6 US2000B Parts. Thanx. Do you know if it also works with US2000C devices? Will check this week. I wrote a example for emoncms to upload the batteries percntage there. -> shall we add to example? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***> Adding an example would be fine.

Describing the use and the setup would also help.

On an approach to an existing project i often i have trouble to understand, which things are needed and what do they do. To me would be helpful how your script feeds emoncms and how is it part of an system: which are the communicating partners. Just sketch it as introduction in your script (e.g. 2 sentences about emoncms and the expected OS/HW), this would be fine.

I like also to add an MQTT example - next time...

Gboyegs commented 1 year ago

On Sun, 2023-01-01 at 07:31 -0800, reviscan wrote: Yes now it works with my 6 US2000B Parts. Thanx. Do you know if it also works with US2000C devices? Will check this week. I wrote a example for emoncms to upload the batteries percntage there. -> shall we add to example?

Hi, nice job and thanks for sharing! I'm trying to use this with 6xUS5000 Pylontech Batteries and a Raspberry Pi4B but I'm running into problems, hope you can help me out..

pi@xxxxxxxxxx:~/.local/lib/python3.7/site-packages/pylontech $ python3 pylontech_stack.py b'20024xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20034xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20044xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20054xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20064xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20074xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20024xxxxxxxxxxxxx' Traceback (most recent call last): File "pylontech_stack.py", line 120, in stackResult = pylon.update() File "pylontech_stack.py", line 76, in update raws = self.pylon.receive() File "/home/pi/.local/lib/python3.7/site-packages/pylontech/pylontech_base.py", line 154, in receive data = self.rs485.receive_frame(end_time=end_time, start=start_byte, end=end_byte) File "/home/pi/.local/lib/python3.7/site-packages/pylontech/pylontech_base.py", line 108, in receive_frame self.verbose_print("\r <- " + frame.decode()) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 15: invalid start byte

I tried it a few times... similar results, one on position 0xfe 6, another time 0xff position 13;

and once a very different error

pi@xxxxxxxxxx:~/.local/lib/python3.7/site-packages/pylontech $ python3 pylontech_stack.py b'20024xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20034xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20044xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20054xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20064xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20074xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20024xxxxxxxxxxxxx' Traceback (most recent call last): File "pylontech_stack.py", line 120, in stackResult = pylon.update() File "pylontech_stack.py", line 78, in update decoded = self.decode.decodeAnalogValue() File "/home/pi/.local/lib/python3.7/site-packages/pylontech/pylontech_decode.py", line 158, in decodeAnalogValue self.data['CommandValue'] = int(payload[i:i + 2], 16) ValueError: invalid literal for int() with base 16: b''

Hope you can help! thanks....

reviscan commented 1 year ago

Hi,

from my side I had also a couple of hardware problems. First of all with the RS232 ( console) it does not worked for me at all. US2000B yes. US2000C not. With RS485 and my laptop all worked fine... but with the PI sometime yes / sometimes not. Mostly after a reboot I had to replug the adapter. After change to a isolated adapter. e.g. DSD TECH SH-U11F isolated USB-zu-RS485-RS422-Konverter works fine. Plug in the Term-TX ( short) connect A and B ... and all works like a charm. I'm only using the RS485 with 9600 or 115200 baud. Depends on the DIP of the Pylon. RS485 the termination is allays a mess... but now an isolated mess. BR

Andreas

Gboyegs commented 1 year ago

I try running the program on my computer instead of the Pi.... I'm using the DSD TECH SH-U20A RS485 adapter with 9600baud, my inverter communicates with the batteries at 9600 so I have to stick with that..... unless it is possible to poll the info from one of the slave batteries, which I've not been able to do.. is that something you've tried? does it work?

reviscan commented 1 year ago

the "SD TECH SH-U20A RS485" is not isolated.... I recommend isolated. and you need a RS485 BUS termination and symmetry. This should be done by one device... ( the BMS does not do this... because we can have multiple) like: https://de.m.wikipedia.org/wiki/Datei:Rs485-bias-termination.svg You are connected to the RS485 Port? Only use 2 wires? the other have other stuff on it ( do not short!)

Gboyegs commented 1 year ago

I'm connected to the upper RS485 Port, 3 wires, ground + A&B.... other wires cut short The Inverter (Phocos Any-Grid) is connected to the lower RS485 port not sure how the RS485 BUS termination and symmetry works... there's only one device connected to the port I'll order the DSD TECH SH-U11F isolated

Tomcat42 commented 1 year ago

On Tue, 2023-02-07 at 08:25 -0800, Gboyegs wrote:

I'm connected to the upper RS485 Port, 3 wires, ground + A&B.... other wires cut short The Inverter (Phocos Any-Grid) is connected to the lower RS485 port not sure how the RS485 BUS termination and symmetry works... there's only one device connected to the port Is sounds strange. On My US2000c the upper Port is CAN, below of it is the RS-485. on the right from them are the link ports, Master has the upper link port empty.

Note: Be sure - always use the newest US2000 (newest firmware) as master.

Do not use the RS-485 for the inverter and your computer with this library. This library does not care about your inverter. Your inverter and the library may send as they like and this would produce garbage on the line.

just check - it should be ~120 Ohm if you disconnect, switch off and measure between A and B. (e.g. look at https://know.innon.com/bias-termination-rs485-network) RS-485 should have only 2 ends (and them terminated) some adapters include the termination resistors

If the RS-485 is occupied by the inverter, i recommend the CAN connector instead. But i had no time to get into it.

Gboyegs commented 1 year ago

Hi, I took your advice and temporarily disconnected the Inverter... more info came through this time..

pi@xxxxxxxxxx:~/.local/lib/python3.7/site-packages/pylontech $ python3 pylontech_stack.py b'20024xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20034xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20044xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20054xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20064xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' b'20074xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ('Timeout waiting for an answer.',) b'20024600F07A00020F0D170D140D150D150D180D170D140D150D150D180D170D140D150D150D18050C0B0BEF0BF00BED0C0B00C9C447FFFF04FFFF00120172B90186A0E2D1' b'20024600B01402D002AFC800C8FE0CC0F915' b'20024600A04200020F000000000000000000000000000000050000000000000000000E80000000F101' b'20034600F07A00030F0D140D120D120D120D140D140D120D120D120D140D140D130D130D130D14050BFD0BEF0BF10BED0BFE00BFC41DFFFF04FFFF00110172B90186A0E2B4' b'20034600B01403D002AFC800C8FE0CC0F913' b'20034600A04200030F000000000000000000000000000000050000000000000000000E80000000F0FF' b'20044600F07A00040F0D180D150D160D140D180D180D150D160D140D180D190D150D160D150D18050BFB0BEE0BED0BE90BF800BDC44FFFFF04FFFF00B2016CC90186A0E263' b'20044600B01404D002AFC800C8FE0CC0F911' b'20044600A04200040F000000000000000000000000000000050000000000000000000E80000000F0FD' b'20054600F07A00050F0D140D120D120D120D150D140D120D120D120D140D150D120D130D120D14050BF90BE80BE90BE40BF600C1C41DFFFF04FFFF00B5016C6A0186A0E2D4' b'20054600B01405D002AFC800C8FE0CC0F90F' b'20054600A04200050F000000000000000000000000000000050000000000000000000E80000000F0FB' b'20064600F07A00060F0D170D130D140D130D140D160D140D140D130D150D170D140D140D140D15050C010BF00BF10BEE0BFC00CBC433FFFF04FFFF00120172B90186A0E2E7' b'20064600B01406D002AFC800C8FE0CC0F90D' b'20064600A04200060F000000000000000000000000000000050000000000000000000E80000000F0F9' {'ChargePower_kW': 4.90726, 'DischargePower_kW': 0, 'Power_kW': 4.90726, 'RemainCapacity_Ah': 471.39, 'Remain_Percent': 94.0, 'TotalCapacity_Ah': 500.0}

It seems to be missing one battery as I've got 6x100AH units (Pylontech UP5000)

So it seems the interference was the problem... shame, because I have to keep the inverter connected to communicate with the battery BMS...

The upper and lower ports of the newer Pylontechs are labels A/CAN -- B/RS485 respectively, but apparently both are identical...
pylontech-frontal-US2000C

Tomcat42 commented 1 year ago

ok. Fine for the Inverter vs. your Computer fight ;-)

Tomcat42 commented 1 year ago

On Tue, 2023-02-07 at 15:23 -0800, Gboyegs wrote:

It seems to be missing one battery as I've got 6x100AH units (Pylontech UP5000) So it seems the interference was the problem... shame, because I have to keep the inverter connected to communicate with the battery BMS... Fine for the Inverter vs. your Computer fight - clarified... ;-)

The upper and lower ports of the newer Pylontechs are labels A/CAN -- B/RS485 respectively, but apparently both are identical... the connector is identical, but the labeling and the manual state the different interface type.

I like to close this thread, as we are off topic from "Work with Pi". (Sorry, i should mention this earlier as some people like to use this thread to find useful information about the topic - at best straight to the solution.)

== Your topic my be previously "communication failure" and now like "Request: support CAN communication" or "work parallel to inverter also connected to RS-485 (some kind of sniffing mode)"

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Tomcat42 commented 1 year ago

closing this issue as issue from requestor (working with Pi) solved.

your welcome to open Issue on a different topic ;-)