RalfZim / venus.dbus-fronius-smartmeter

A service for Venus OS, reading smart meter data from a Fronius system and making the values available on dbus.
MIT License
51 stars 30 forks source link

ModuleNotFoundError: No module named 'thread' #5

Closed HenrikB-dev closed 1 year ago

HenrikB-dev commented 2 years ago

Hi there,

I get the following error message

Traceback (most recent call last):
  File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 16, in <module>
    import thread   # for daemon = True
ModuleNotFoundError: No module named 'thread'

That someone already had the problem on a current VenusOS?

System-Info: Python 3.8.11 Firmware: v2.82-large-30

reddog-42 commented 2 years ago

In python 3, thread is renamed to _thread , but that isn't the only issue

RalfZim commented 2 years ago

That someone already had the problem on a current VenusOS?

System-Info: Python 3.8.11 Firmware: v2.82-large-30

My Raspi is running VenusOS v2.66 and the "Online updates" tells me "No newer version available". On my v2.66, only python 2.7.14 is available.

I will have a look how I can change the script in a way that works with both python 2.x and 3.x. I never tried this before -but this seems to be a good time for it.

reddog-42 commented 2 years ago

I am running a modified version of your script on a Cerbo with the new 2.84 firmware, probably not available for Rpi yet.

For python 3 I had to update import _thread replacing thread from gi.repository import GLib replacing gobject (gobject is deprecated but you could import as gobject I think) and adjust their usage in the code.

for path, settings in self._paths.items(): instead of iteritems()

No idea how you can make it work for both python versions

Also I had to change meter ProductId from 16, as it didn't recognize the device as a meter. I set ProductId to 45069 based on an CG ET340 I had connected via usb/modbus.

I also extended the service name from just .grid because the other meter was .grid.cgwacs_ttyUSB0_mb1 but probably doesn't matter if there is only one meter. I also added paths for AllowedRoles '0' and Role 'grid' to match the CG meter. It doesn't appear in settings to allow the role to be selected like the CG meter does.

Hope that is of some help. Regards

kaeferfreund commented 2 years ago

many thanks, I have submitted a pull request #6 for everyone who does not know how to incorporate the mentioned changes :)

RalfZim commented 2 years ago

@kaeferfreund @reddog-42 @HenrikB-dev Can you guys please try this fix:

try:
  import gobject
except:
  from gi.repository import GLib as gobject
try:
  import thread   # for daemon = True
except:
  import _thread as thread   # for daemon = True
RalfZim commented 2 years ago

@kaeferfreund @reddog-42 @HenrikB-dev I just pushed a fix which works under Python 2.7.14 on my RasPi (VenusOS v2.66) as well as under Python 3.8.11 on my CerboGX (VenusOS v2.84). (I had this CerboGX for more than a year now, but did not use it.) Please try that fix with your platforms and report your results here!

reddog-42 commented 2 years ago

Great work Ralf. I am travelling for a few weeks but will try to test on my Cerbo early next month. Rgds Colin

Sent from my iPhone

On 15 Mar 2022, at 02:05, RalfZim @.***> wrote:

 @kaeferfreund @reddog-42 @HenrikB-dev I just pushed a fix which works under Python 2.7.14 on my RasPi (VenusOS v2.66) as well as under Python 3.8.11 on my CerboGX (VenusOS v2.84). (I had this CerboGX for more than a year now, but did not use it.) Please try that fix with your platforms and report your results here!

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

reddog-42 commented 2 years ago

Hi Ralf, I tested your new code on my Cerbo GX ( v2.84 ). I changed my ip address and also meter device id in the fronius api request. My meter is device 1 iso 0 and in consumption path. All good in the Cerbo console.

VRM reports the meter device, but does not include it in the dashboard. I suspect this is because you have a deviceinstance=0 in the dbus setup. Venus sets meters in the 3x range. Mine is 32. IIRC the real meter was 31.

I noted you have wrapped the update meter read in try/except. I have also done this in my version as it was getting hung occasionally. I also added a timeout to the read. I read python has no default timeout. I haven't had any hangs since both changes, but it has only been a few weeks. Not sure if it is required or helps :) "meter_r = requests.get(url = URL, timeout=10)"

I tested with a three phase meter, same as yours. Looking at your code, for a single phase meter, you have an "if" statement to set the phase 2 and 3 values to zero. Shouldn't you have an "else" for the code setting phase 2 and 3 from the meter read ?

Well done on figuring out how to support python 2 and 3 at the same time !

Regards Colin

On Tue, 15 Mar 2022 at 02:05, RalfZim @.***> wrote:

@kaeferfreund https://github.com/kaeferfreund @reddog-42 https://github.com/reddog-42 @HenrikB-dev https://github.com/HenrikB-dev I just pushed a fix which works under Python 2.7.14 on my RasPi (VenusOS v2.66) as well as under Python 3.8.11 on my CerboGX (VenusOS v2.84). (I had this CerboGX for more than a year now, but did not use it.) Please try that fix with your platforms and report your results here!

— Reply to this email directly, view it on GitHub https://github.com/RalfZim/venus.dbus-fronius-smartmeter/issues/5#issuecomment-1066914629, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWVWFELUV2S3BWYNPEXJVIDU75IU3ANCNFSM5PRUOB5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>