rellit / resol-vbus-python

Python Script to read RESOL VBUS Data over LAN
MIT License
14 stars 12 forks source link

pyhon3 #5

Closed clemefr closed 1 year ago

clemefr commented 5 years ago

I try to convert your code to python 3 like this:

Receive 1024 bytes from stream

def recv(): dat = sock.recv(1024).decode() return dat

Sends given bytes over the stram. Adds debug

def send(dat): sock.send(dat.encode())

and got the following error: File "resol.py", line 72, in recv dat = sock.recv(1024).decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaa in position 0: invalid start byte

Any help ?

hmueller01 commented 3 years ago

Converting this script to Python3 is not that easy. It makes use of 'binary' strings, which are incompatible with Python3.

Strings From a developer’s point of view, the largest change in Python 3 is the handling of strings. In Python 2, the str type was used for two different kinds of values – text and bytes, whereas in Python 3, these are separate and incompatible types.

from here

I have ported the script to Python3 and it needed lots of changes. In my point of view it makes no sense to make one script for both Python versions (and to be still a kind of readable).

Now my question to @rellit: Do you like resol-vbus to be Python3 compatible? If yes, do you like to add a new script e.g. resol3.py or do you like to make a release of the current resol.py and switch to a single new Python3 resol.py and not maintaining the Python2 any more as Python2 is EOL since beginning of 2020 ...

I am willing to contribute my work.

hmueller01 commented 3 years ago

Ok, no one interested?

I pushed the Python3 code for testing in my repositories python3 branch here.

I can not test the LAN connection, as I use tty / serial. Hope someone can confirm that it works.

hmueller01 commented 3 years ago

Could someone please test the LAN connection. I would prefer the resol3.py solution as it might still make sense to support Python2. As soon as the LAN connection is confirmed I will do a pull request.

maxstefaniv commented 3 years ago

Hi, Python3 works with KM2 to Ethernet. Only had to change some encoding did it on python 3.8 Hope it helps.

juergen852 commented 2 years ago

Tried https://github.com/hmueller01/resol-vbus-python/tree/python3 on python 3.10.4 with the following result:

python resol.py Traceback (most recent call last): File "/home/jmueller/Scripte/resol-vbus-python-python3/resol.py", line 261, in load_data() File "/home/jmueller/Scripte/resol-vbus-python-python3/resol.py", line 49, in load_data send("DATA\n") File "/home/jmueller/Scripte/resol-vbus-python-python3/resol.py", line 87, in send sock.send(dat) TypeError: a bytes-like object is required, not 'str'

df8oe commented 1 year ago

Exactly the same here (except: I have created the specfile for MX). DeltaSolMX connected via LAN - messages as following: Traceback (most recent call last): File "/usr/local/bin/resol.py", line 261, in <module> load_data() File "/usr/local/bin/resol.py", line 49, in load_data send("DATA\n") File "/usr/local/bin/resol.py", line 87, in send sock.send(dat) TypeError: a bytes-like object is required, not 'str' I think there are more type errors. I tried send("DATA\n".encode()) but no success. It would be nice if the script runs on python3.

juergen852 commented 1 year ago

@df8oe Have you tried https://github.com/hmueller01/resol-vbus-python/tree/python3 ?

df8oe commented 1 year ago

Yes - that is the version my report is related to. Sadly there is no issue report possible.

df8oe commented 1 year ago

I investigated more (but I am not a Python specialist at all): There are alredy strings which are send via LAN. Especially the login process uses strings. I have added some prints to look what happens and after the login line send("PASS %s\n" % config.vbus_pass) Resol answers with ERROR: Not authorized to start data mode

I tried also send("PASS vbus\n".encode('ascii')) but Resol rejects me.

df8oe commented 1 year ago

I worked it out: https://github.com/hmueller01/resol-vbus-python/pull/1

df8oe commented 1 year ago

It is working now via LAN stable - PR is nor merged yet...

hmueller01 commented 1 year ago

Tx @df8oe. I just created PR #13.