Adding/Removing Values to MQTT extension

217 views
Skip to first unread message

jmltech

unread,
Oct 30, 2016, 8:41:57 PM10/30/16
to weewx-user
I'm using Matthew Wall's nice MQTT extension for weewx.  Where can I specify which weewx variables to add to the MQTT stream, and remove some others that are not needed for my purpose?  I thought it would be a skin, but didn't find anything.
Thanks
Joe

mwall

unread,
Oct 31, 2016, 12:02:22 AM10/31/16
to weewx-user

hi joe,

use the inputs stanza.  for example, this will upload all observations, with overrides to outTemp and windSpeed:

[StdRestful]
    [[MQTT]]                                                                   
        ...                                                                    
        unit_system = METRIC # default to metric                               
        [[[inputs]]]                                                           
            [[[[outTemp]]]]                                                    
                name = inside_temperature  # use a label other than outTemp    
                format = %.2f              # two decimal places of precision   
                units = degree_F           # convert outTemp to F, others in C 
            [[[[windSpeed]]]]                                                  
                units = knot  # convert the wind speed to knots                

by default, every observation will be uploaded.  use obs_to_upload to default to uploading NO observations, then add in the ones you want.  for example, this will upload *only* outTemp and inTemp using the default units and formatting:

[StdReport]
    [[MQTT]]
        obs_to_upload = none
        [[[inputs]]]
            [[[[outTemp]]]]
            [[[[inTemp]]]]

fwiw, this is a pattern found in may uploaders, including emoncms and influx.

m

jmltech

unread,
Nov 4, 2016, 3:06:32 PM11/4/16
to weewx-user
Thanks Matt for the replay and example.  I tried this by editing the config file, and adding these lines under [StdReport], but the report engine started throwing errors:


    [[MQTT]]
        obs_to_upload = none
        [[[inputs]]]
            [[[[outTemp]]]]
            [[[[inTemp]]]]

On the next archive loop, mqtt received the normal all observations, and this was recorded in the log:

 
reportengine: Caught unrecoverable exception in generator weewx.cheetahgenerator.CheetahGenerator
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  'skin'
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  Traceback (most recent call last):
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/reportengine.py", line 140, in run
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      obj.start()
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/reportengine.py", line 170, in start
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      self.run()
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/cheetahgenerator.py", line 143, in run
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      ngen = self.generate(gen_dict[option_section_name], self.gen_ts)
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/cheetahgenerator.py", line 206, in generate
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      ngen += self.generate(section[subsection], gen_ts)
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/cheetahgenerator.py", line 206, in generate
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      ngen += self.generate(section[subsection], gen_ts)
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/cheetahgenerator.py", line 221, in generate
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      self.skin_dict['skin']))
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/usr/lib/python2.7/dist-packages/configobj.py", line 554, in __getitem__
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      val = dict.__getitem__(self, key)
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  KeyError: 'skin'
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  Generator terminated...
Nov  4 14:30:28 knoxville1 weewx[1043]: genimages: Generated 12 images for MQTT in 0.17 seconds
Nov  4 14:30:28 knoxville1 weewx[1043]: reportengine: Caught unrecoverable exception in generator weewx.reportengine.CopyGenerator
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  'skin'
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  Traceback (most recent call last):
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/reportengine.py", line 140, in run
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      obj.start()
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/reportengine.py", line 170, in start
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      self.run()
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/home/weewx/bin/weewx/reportengine.py", line 303, in run
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      self.skin_dict['skin']))
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****    File "/usr/lib/python2.7/dist-packages/configobj.py", line 554, in __getitem__
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****      val = dict.__getitem__(self, key)
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  KeyError: 'skin'
Nov  4 14:30:28 knoxville1 weewx[1043]:         ****  Generator terminated...

I then moved obs_to_upload = none  to be under:
[StdRESTful]
    [[MQTT]]

so that it is with other other MQTT options, under server_url, topic, etc.

On the next weewx archive loop, it appears the same error was thrown for the reportengine, however, for the mqtt, no variables were sent.
For the MQTT topic, an empty JSON string was received.

any other suggestions?
Thanks,
Joe






mwall

unread,
Nov 4, 2016, 3:09:26 PM11/4/16
to weewx-user
On Friday, November 4, 2016 at 3:06:32 PM UTC-4, jmltech wrote:
Thanks Matt for the replay and example.  I tried this by editing the config file, and adding these lines under [StdReport], but the report engine started throwing errors:


it looks like your configuration is mangled.  please post your weewx configuration file - remove any passwords or other sensitive information first.

m

jmltech

unread,
Nov 4, 2016, 3:19:37 PM11/4/16
to weewx-user
Conf file attached.


weewx.conf

mwall

unread,
Nov 4, 2016, 4:00:17 PM11/4/16
to weewx-user
joseph,

the MQTT stanza belongs only in the [StdRESTful] section - you should remove MQTT from [StdReport].  my apologies for the misleading typo in my previous posting.  you're getting the skin error because the weewx report generator treats the MQTT stanza in [StdReport] as another skin, and it does not define a skin configuration.

the MQTT stanza in [StdRESTful] looks ok.  that configuration should upload *all* observations every archive interval in a single json payload with unit labels appended to the observation names under the topic weewx.

the next step is to look at the log file.  set debug=2 and you'll see exactly what payload the MQTT extension is preparing to send to the broker.

be sure to restart weewx after any change to weewx.conf

m

jmltech

unread,
Nov 4, 2016, 4:55:06 PM11/4/16
to weewx-user
Thanks Matthew.  That did work.
Putting the options all under [StdRESTful], setting obs_to_upload = none, and listing the individual observations that you wanted published worked as expected.
For those interested in the final solution, here is my test MQTT section:

[StdRESTful]

[[MQTT]]
        server_url
= mqtt://192.168.168.17:1883
        topic
= weewx
        append_units_label
= true
        binding
= archive
        aggregation
= aggregate
        retain
= true

        obs_to_upload
= none
       
[[[inputs]]]
           
[[[[outTemp]]]]
           
[[[[inTemp]]]]



One final question... can the aggregation types be included as well?  For example, when I included this:

[[[[day.outTemp.max]]]]




the MQTT didn't include it.  Looking at the log file with debug = 2, it didn't even acknowledge that the variable existed (no mention of it)

Thanks for your help!
Joe



jmltech

unread,
Nov 11, 2016, 4:40:22 PM11/11/16
to weewx-user
Hi Mattew,
Probably missed my other question... can aggragation values like day.outTemp.max be added? What other values can be added?

mwall

unread,
Nov 11, 2016, 5:04:30 PM11/11/16
to weewx-user
On Friday, November 11, 2016 at 4:40:22 PM UTC-5, jmltech wrote:
Hi Mattew,
Probably missed my other question... can aggragation values like day.outTemp.max be added?  What other values can be added?

only direct observations (from LOOP packets) or database fields (from archive records)


Reply all
Reply to author
Forward
0 new messages