daduke / ventusw820

Bluetooth driver and weewx connector for Ventus W820 weather station
0 stars 2 forks source link

Move to python 3? #3

Open j64bit opened 3 years ago

j64bit commented 3 years ago

Dear daduke/Christian,

great work: runs very smoothly with my Ventus and weewx installation on Raspberry Pi.

weewx now seems to move to python 3 and i think then this driver will not work. Wonder if you have any plans to move it over to python 3?

Many thanks J

daduke commented 3 years ago

getting my driver to work with Python3 requires just cosmetic changes (I have a commit somewhere). The real issue is that I couldn't bluepy to run with P3. I looked at some forks that seem to do the trick but didn't succeed either. Also, my outdoor unit broke (kinda chinsy), so I won't get a lot of values anyway...

j64bit commented 3 years ago

thanks for the quick reply. Too bad. Not sure when you tried last? The bluepy Readme now claims: "The code is tested on Python 2.7 and 3.4; it should also work on 3.3" Worth a try?

I've seen an Issue ticket on 3.7.3. but nothing much else.

daduke commented 3 years ago

thanks for the quick reply. Too bad. Not sure when you tried last? The bluepy Readme now claims: "The code is tested on Python 2.7 and 3.4; it should also work on 3.3"

about 2 months ago?

Worth a try?

sure, give it a shot!

j64bit commented 3 years ago

hi again, last week i moved over to python3 on raspberry. pip3 installs bluepy - no problem. Then as you said, cosmetics is needed on ventus*.py (print() and indentation).

A little harder was to figure out an issue in the bluetooth connection which blocks it from collecting data from W820. The read function in ventus.py needs to get some 'b's before the requests. That's all :-)

def read(w820):
   w820.setDelegate(w820Delegate(''))
   try:
       w820.writeCharacteristic(0x000e, b'\x01\x00', True)           # Turn on notificiations
       w820.writeCharacteristic(0x000b, b'\xb0\x01\x00\x00', True)   # Request data
       w820.waitForNotifications(1)                                 # wait for response
       w820.writeCharacteristic(0x000b, b'\x40\x01\x00\x00', True)   # send ACK for next packet
       w820.waitForNotifications(1)                                 # wait for response
       w820.writeCharacteristic(0x000b, b'\x40\x01\x00\x00', True)   # send ACK for next packet
       w820.waitForNotifications(1)                                 # wait for response

   except:
       e = sys.exc_info()[0]
       print(e)
   finally:
       return sensorData

Hope this helps anyone wanting to move over as well. Cheers

daduke commented 3 years ago

that's great news! My W820 finally gave up the ghost so I have no way of testing. Would you mind providing a PR?

j64bit commented 3 years ago

well, sure. I'm new to git for this, but I'll try&learn.