bakerkj / weewx-purpleair

WeeWx Extension to pull data from the local interface of a Purple Air air quality sensor
GNU General Public License v2.0
17 stars 11 forks source link

Ported to Python 3 and WeeWX V4.x #17

Closed tkeffer closed 3 years ago

tkeffer commented 3 years ago

Hi, Ken

I ported your extension to Python 3 and WeeWX V4.x. I've only tested it by running the extension driver directly, not as part of WeeWX.

One note: your extension does a poll of the PA sensor in the main thread. This is generally not a good idea, as it will kill weewxd if the HTTP request fails. Better to set it up in a separate thread, and monitor a queue.

See the wiki article multi-threaded service for a general idea of how to do this.

Let me know if you have any questions.

bakerkj commented 3 years ago

Hi @tkeffer , thanks for the pull request. I am running the following environment:

weewx[4446] INFO __main__: Initializing weewx version 4.5.1
weewx[4446] INFO __main__: Using Python 2.7.12 (default, Mar  1 2021, 11:38:31) #012[GCC 5.4.0 20160609]
weewx[4446] INFO __main__: Platform Linux-4.4.0-201-generic-x86_64-with-Ubuntu-16.04-xenial
weewx[4446] INFO __main__: Locale is 'en_US.UTF-8'
weewx[4446] INFO __main__: Using configuration file /etc/weewx/weewx.conf
weewx[4446] INFO __main__: Debug is 1

I get the following tracebacks with your changes:

weewx[4446] ERROR weewx.cheetahgenerator: Generate failed with exception '<type 'exceptions.IndexError'>'
weewx[4446] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/exfoliation-kjb/live.html.tmpl
weewx[4446] ERROR weewx.cheetahgenerator: **** Reason: tuple index out of range
weewx[4446] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 326, in generate
weewx[4446] ERROR weewx.cheetahgenerator: ****      unicode_string = compiled_template.respond()
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "_etc_weewx_skins_exfoliation_kjb_live_html_tmpl.py", line 1118, in respond
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 691, in filter
weewx[4446] ERROR weewx.cheetahgenerator: ****      filtered = six.text_type(val)
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 1169, in __unicode__
weewx[4446] ERROR weewx.cheetahgenerator: ****      return self.toString()
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 1159, in toString
weewx[4446] ERROR weewx.cheetahgenerator: ****      localize=localize)
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 840, in toString
weewx[4446] ERROR weewx.cheetahgenerator: ****      s = self._to_string(val_t, context, addLabel, useThisFormat, None_string, localize)
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 905, in _to_string
weewx[4446] ERROR weewx.cheetahgenerator: ****      label = self.get_label_string(val_t[1], plural=(not val_t[0]==1))
weewx[4446] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 804, in get_label_string
weewx[4446] ERROR weewx.cheetahgenerator: ****      return label[1] if plural else label[0]
weewx[4446] ERROR weewx.cheetahgenerator: ****  IndexError: tuple index out of range
weewx[4446] INFO weewx.cheetahgenerator: Generated 8 files for report Exfoliationkjb in 0.56 seconds
weewx[4446] ERROR weewx.reportengine: Caught unrecoverable exception in generator 'weewx.imagegenerator.ImageGenerator'
weewx[4446] ERROR weewx.reportengine:         ****  tuple index out of range
weewx[4446] ERROR weewx.reportengine:         ****  Traceback (most recent call last):
weewx[4446] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/reportengine.py", line 196, in run
weewx[4446] ERROR weewx.reportengine:         ****      obj.start()
weewx[4446] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/reportengine.py", line 281, in start
weewx[4446] ERROR weewx.reportengine:         ****      self.run()
weewx[4446] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/imagegenerator.py", line 41, in run
weewx[4446] ERROR weewx.reportengine:         ****      self.genImages(self.gen_ts)
weewx[4446] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/imagegenerator.py", line 200, in genImages
weewx[4446] ERROR weewx.reportengine:         ****      unit_label = line_options.get('y_label', self.formatter.get_label_string(new_data_vec_t[1]))
weewx[4446] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/units.py", line 804, in get_label_string
weewx[4446] ERROR weewx.reportengine:         ****      return label[1] if plural else label[0]
weewx[4446] ERROR weewx.reportengine:         ****  IndexError: tuple index out of range
weewx[4446] ERROR weewx.reportengine:         ****  Generator terminated
weewx[4446] INFO weewx.reportengine: Copied 0 files to /var/www/exfoliation-kjb

If you have any suggestions they would be much appreciated. Otherwise I'll have to dig further.

This plugin was modeled after Matthew's weewx-cmon plugin which doesn't have the same issues with http failures. I will have a look at improving the multi threading as you suggest.

Thanks!

tkeffer commented 3 years ago

One measly comma messed things up. Try again.

bakerkj commented 3 years ago

Ah missed that. Thanks!

Merged.

bakerkj commented 3 years ago

One note: your extension does a poll of the PA sensor in the main thread. This is generally not a good idea, as it will kill weewxd if the HTTP request fails. Better to set it up in a separate thread, and monitor a queue.

Tom, Could you have a look at this branch?

https://github.com/bakerkj/weewx-purpleair/tree/multithreaded-service

-- Ken

tkeffer commented 3 years ago

I usually use a queue, but your approach is simpler. Don't see why it wouldn't work.