Frankkkkk / python-pylontech

Python lib to talk to pylontech lithium batteries 🔋 (US2000, US3000, ...) using RS485
MIT License
67 stars 32 forks source link

servere connectivity problems with us5000 #35

Closed ceisserer closed 1 year ago

ceisserer commented 1 year ago

I guess this is not an actual bug with the library but with my setup, yet since I didn't find forum to ask related questions, please be kind. I really don't know what else I could try / how to debug this issue further.

When reading the values of my US5000 with an RPI3 it sometimes works (first it failed, with a shorter cable it worked fine for a day and now I am back at the error state) and sometimes I only get:

I already tried:

I am really out of options. Could it be some parasitic voltage caused by the switching power supply of the Raspberry? Any ideas what to try next?

Frankkkkk commented 1 year ago

hi @ceisserer , can you add some pictures of your setup please ? Cheers

ceisserer commented 1 year ago

Hi @Frankkkkk:

Thanks a lot for taking a look. Currently the setup is rather simple (normally turned on of course ;) ), just the two PINS (7&8 from the cable) connected to A and B of the RS485 module. The other cables are un-insulated from former tests, also I tried a 120 Ohm termination resistor between A and B which didn't help:

grafik

With the following Code: p = pylontech.Pylontech('/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0', 9600) print(p.get_values())

I get the following output:

[root@localhost tech]# python pylon_nomqtt.py Traceback (most recent call last): File "/home/ce/Privat/Haus/Akku/tech/pylon_nomqtt.py", line 9, in print(p.get_values()) ^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pylontech/pylontech.py", line 270, in get_values f = self.read_frame() ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pylontech/pylontech.py", line 200, in read_frame f = self._decode_hw_frame(raw_frame=raw_frame) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pylontech/pylontech.py", line 181, in _decode_hw_frame assert got_frame_checksum == int(frame_chksum, 16)

So again it seems like communication problems - even at 9600 baud :/ Also it doesn't seem to be caused by parasitic/capacitic currents, I gave it a try with my notebook which was running on battery - same result.

also I have to appologize - I initially used another (more complex) library ('PylontechStack') and the error messages in the first post were from the former library, but I have to admit I like this one more because of its simplicity :)

Frankkkkk commented 1 year ago

Hi @ceisserer , Thanks for the info. From what I can see on the picture, your DIP1 is off, which (unless I'm mistaken) means that the RS485 baudrate is 115200. Thus:

If it still doesn't work:

Cheers

ceisserer commented 1 year ago

The problem was so simple and stupid, it never crossed my mind it could actually be such an easy-to-fix problem. The source for all the issues observed was a systemd unit file I had created a few weeks before and had forgotten. so when i manually started the script to work on it again after that break one instance was already running and both were reading/writing to the serial device file. i always disliked windows' file locking, but I have to admit in this case it would have saved a lot of time and RJ45 cables I cut open and soldered ;)

Sorry for the noise and thanks a lot for all your help, time and suggestions.

Frankkkkk commented 1 year ago

Hi @ceisserer thanks for the follow up. I've released v0.3.3 which asks for exclusive access to the serial port so that the issue doesn't arise :-) Cheers

ceisserer commented 1 year ago

Awesome, thanks a lot!