Mqtt values formated to 2 digits won't work

241 views
Skip to first unread message

Alex Z99

unread,
Aug 19, 2024, 4:40:46 PM8/19/24
to weewx-user
With this config, the weather values are puplished, but (i guess) due to convert from US (within db) to Metricwx with up to 16 decimal places.
###############
 [[MQTT]]        # Enable/disable this service
        enable = true
        unit_system = METRICWX
        # Hostname/IP of MQTT broker
        host = 192.168.2.22
        # Prefix for topics
        topic = weather
#################
I took one exemple from https://github.com/weewx/weewx/wiki/mqtt to reduce the
decimal places of the published values, but with this config, mqtt stops working.
#################
 [[MQTT]]        # Enable/disable this service
        enable = true
        unit_system = METRICWX
        [[[inputs]]]
            [[[[outTemp]]]]
                format = %.2f                # use two decimal places of precision
                name = outside_temperature    # use label other than inTemp
            [[[[windSpeed]]]]
                units = meter_per_second
                format = %.2f
                name = wind_m_s

        # Hostname/IP of MQTT broker
        host = 192.168.2.22
        topic = weather
#################

What could be wrong in the configuration?
My aim ist to limit all published values to a max. of 2 digits behind the dot
e. g. instead
weather/windSpeed_meter_per_second 0.40000099419637863
is should be:
weather/windSpeed_meter_per_second 0.4

br
Alex

gjr80

unread,
Aug 20, 2024, 5:02:39 AM8/20/24
to weewx-user
Your config stanza format is incorrect; you cannot just insert sub-stanzas in the middle of an existing stanza, the sub-stanzas need to be added to the end. In the case of a WeeWX config file indents don't matter but order does. Try something like:

 [[MQTT]]        # Enable/disable this service
        enable = true
        unit_system = METRICWX
        # Hostname/IP of MQTT broker
        host = 192.168.2.22
        topic = weather
        [[[inputs]]]
            [[[[outTemp]]]]
                format = %.2f                # use two decimal places of precision
                name = outside_temperature    # use label other than inTemp
            [[[[windSpeed]]]]
                units = meter_per_second
                format = %.2f
                name = wind_m_s


The order you had meant the MQTT uploader was never seeing the host and topic config entries.

If that doesn't work post a log extract showing the error.

Gary

Alex Z99

unread,
Aug 20, 2024, 8:19:55 AM8/20/24
to weewx-user
Hi Gary,
thanks for your advice. After the modification of weewx.conf mqtt data is still delivered (so tha's positive), but no change in the number of decimal places.
My config:
#########################
 [[MQTT]]

       enable = true
        unit_system = METRICWX
        # Hostname/IP of MQTT broker
        host = 192.168.2.22
        topic = weather
#        append_units_label = false

        [[[inputs]]]
            [[[[outTemp]]]]
                format = %.2f                # use two decimal places of precision
                name = outside_temperature    # use label other than inTemp
            [[[[windSpeed]]]]
                units = meter_per_second
                format = %.1f
                name = windSpeed_m_s
            [[[[windGust]]]]
                units = meter_per_second
                format = %.1f
                name = gust_m_s
###########################

and the result in the broker:
###########################
weather/inTemp_degree_C 27.29999999999999
weather/inHumidity_percent 67
weather/outTemp_degree_C 24.700000000000003
weather/outHumidity_percent 64
weather/pressure_mbar 1012.8
weather/windSpeed_meter_per_second 0.40000099419637863
weather/windGust_meter_per_second 0.6000014912945679
weather/windDir_degree_compass 112.5
weather/windGustDir_degree_compass 112.5
weather/rainRate_mm_per_hour 0.0
weather/rain_mm (null)
weather/rxCheckPercent_percent 100
weather/windBatteryStatus 0
weather/rainBatteryStatus 0
weather/outTempBatteryStatus 0
weather/inTempBatteryStatus 0
weather/altimeter_mbar 1056.8811153752754
weather/appTemp_degree_C 26.97221024879724
weather/barometer_mbar 1055.5080297221955
weather/cloudbase_meter 1267.4829583543142
weather/dewpoint_degree_C 17.422122081623723
weather/ET_mm (null)
weather/heatindex_degree_C 24.89666666666667
weather/humidex_degree_C 30.293088441750406
weather/inDewpoint_degree_C 20.621737268345424
weather/maxSolarRad_watt_per_meter_squared 813.5477625196611
weather/windchill_degree_C 24.700000000000003
weather/windrun_km (null)
weather/usUnits 17
###########################

Something goes wrong, but I've no idea

br

Alex

gjr80

unread,
Aug 20, 2024, 4:29:48 PM8/20/24
to weewx-user
I suggest you edit weewx.conf, set debug = 2, save weewx.conf and restart WeeWX. Let WeeWX run for at least two archive periods then take a log extract showing the full WeeWX startup through until the two archive periods have elapsed. Post the unaltered log extract here. Also worthwhile posting the output of weectl debug (or wee_debug if using WeeWX v4 or earlier). Check the output for sensitive data (eg passwords, user names, keys etc) before posting, weectl debug should obfuscate these but it is not perfect. 

Gary

Alex Z99

unread,
Aug 25, 2024, 2:05:46 PM8/25/24
to weewx-user
Hi Gary,

I took an exploit from syslog with debug-level 2, see attachment.
As I mentioned, the observation data for wind, gust and outtemp are still transmitted unformated, I also realiezed that rain values ( "weather/rain_mm": 0.0 (mm)" ) have always zero values although the website tells me the correct rain of today  = 2.6 mm, also the rain_hour value isn't okay with mqtt.

br.

Alex
weewx_syslog_202408251944.txt

gjr80

unread,
Aug 25, 2024, 10:05:25 PM8/25/24
to weewx-user
So exactly what MQTT service are you using? Your initial post includes the link https://github.com/weewx/weewx/wiki/mqtt (which in turn links to Matthew's RESTful MQTT uploader) and the instructions on that page are specific to Matthew's uploader. The log extract just provided shows user.mqtt.MqttService being loaded:

2024-08-25T19:43:39.786798+02:00 RPi-Weewx weewxd[3614]: DEBUG weewx.engine: Loading service user.mqtt.MqttService
2024-08-25T19:43:39.862785+02:00 RPi-Weewx weewxd[3614]: DEBUG user.mqtt: Initializing MQTT service
2024-08-25T19:43:39.863826+02:00 RPi-Weewx weewxd[3614]: DEBUG user.mqtt: Creating MQTT client with id "weewx_21680fb1"
2024-08-25T19:43:39.881839+02:00 RPi-Weewx weewxd[3614]: DEBUG user.mqtt: Starting MQTT client
2024-08-25T19:43:39.882861+02:00 RPi-Weewx weewxd[3614]: DEBUG weewx.engine: Finished loading service user.mqtt.MqttService

 but Matthew's uploader has no class named MqttService (it has class MQTT). So it is clear you are not using Matthew's MQTT uploader.

You might want to look up the instructions for use for whatever MQTT service you are using, or post details of the MQTT service you are using and we will see what we can work out.

Gary

Alex Z99

unread,
Aug 26, 2024, 8:09:38 AM8/26/24
to weewx-user
Hi Gary,

I checked your hint regarding MQTT version:

First time, I installed step by step the instruction of the mentioned link
a list in weewx control tells me:
weectl extension list
Using configuration file /etc/weewx/weewx.conf
Extension Name    Version   Description
MQTT              0.2.0     Extension for uploading LOOP data to an MQTT broker
So I checked the installed packages regarding mqtt:
 apt list | grep mqtt

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

golang-github-eclipse-paho.mqtt.golang-dev/stable 1.1.1-1.1 all
kamailio-mqtt-modules/stable 5.6.3-2+rpi1+b1 armhf
libmqtt-client-java/stable 1.16-1 all
libpaho-mqtt-dev/stable 1.3.12-1 armhf
libpaho-mqtt1.3/stable 1.3.12-1 armhf
libpaho-mqttpp-dev/stable 1.2.0-2 armhf
libpaho-mqttpp3-1/stable 1.2.0-2 armhf
node-mqtt-connection/stable 4.1.0-4 all
node-mqtt-packet/stable 8.1.2-2 all
node-mqtt/stable 4.3.7-2 all
paho.mqtt.c-examples/stable 1.3.12-1 armhf
prometheus-mqtt-exporter/stable 0.1.7-1 armhf
python3-asyncio-mqtt/stable 0.16.1-3 all
python3-hbmqtt/stable 0.9.6-1.2 all
python3-paho-mqtt/stable,now 1.6.1-1 all  [installiert]

To repeat the install process, I removed MQTT in weewx and removed paho-mqtt in apt
Reinstall according the instruction:
wget -O weewx-mqtt.zip https://github.com/matthewwall/weewx-mqtt/archive/master.zip
sudo pip install paho-mqtt==1.6.1
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.

    For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

=> This error occured also at primary installation, so I installed the paho-mqtt with apt.
Maybe thats the key, why weewx mapped to a complete other version of mqtt?
Finally the list in apt reveals also other mqtt

So, what to do?

br

Alex

gjr80

unread,
Aug 27, 2024, 12:23:03 AM8/27/24
to weewx-user
A bit of googling suggests that this:

Extension Name    Version   Description
MQTT              0.2.0     Extension for uploading LOOP data to an MQTT broker

refers to the extension in this repo: https://github.com/michael-slx/weewx-mqtt. Looking through the code for this extension it does not support formatting the MQTT output as you wish to. I'm not sure what if any advantages the Michael-six uploader offers over the matthewwall uploader.

As for your re-installlation problem. You appear to be using a package install of WeeWX v5. I know the instructions say to use pip to install paho-mqtt, but I find when you are not using a virtual python environment it is all to easy to end up with a non-functional install when using pip to install some packages. Try using apt to install paho-mqtt:
$ sudo apt update
$ sudo apt-cache policy python3-paho-mqtt

this should show what version of paho-mqtt will be installed, something like:
python3-paho-mqtt:
  Installed: (none)
  Candidate: 1.6.1-1
  Version table:
     1.6.1-1 500
        500 http://deb.debian.org/debian bookworm/main arm64 Packages
        500 http://deb.debian.org/debian bookworm/main armhf Packages


Provided the candidate version is 1.6.1 or lower (ie it is not v2.x.y) install paho-mqtt using:
$ sudo apt install python3-paho-mqtt

You should be able to complete the rest of the uploader install/setup. If it does not work as expected edit weewx.conf, set debug = 2 and restart WeeWX. Post a log extract showing the complete WeeWX startup and the first few MQTT uploads. Also post the output from weectl debug as per instructions in my earlier post.

Whether you previously installed paho-mqtt using pip or apt makes no difference to what WeeWX MQTT uploader was installed/used; somehow you separately installed the Michael-six uploader rather than the matthewwall uploader.

Gary

Alex Z99

unread,
Aug 29, 2024, 5:17:14 PM8/29/24
to weewx-user
Hi Gary,
I repeated the mqtt precedure and
##########################
pi@RPi-Weewx:/etc/weewx $ sudo weectl extension list

Using configuration file /etc/weewx/weewx.conf
Extension Name    Version   Description
mqtt              0.24      Upload weather data to MQTT server.
##########################
That seems to be also not Matthew's version.
The log (see attachment) and a trace in the broker reveals, that my desired behavior is not fullfilled.
So I'm still unhappy.

br.

Alex
weewx_syslog_202408292305.txt

vince

unread,
Aug 29, 2024, 6:42:25 PM8/29/24
to weewx-user
Alex - it is unfortunate you're unfulfilled and still unhappy.

I did a test here on a pip installation and it 'does' work for me with mqtt 0.24 in setting both more and fewer numbers to the right of the decimal point.

I added an input setting things to 5 digits and restarted weewx....

    [[MQTT]]
        client_id = ecowitt
        server_url = mqtt://192.168.1.171:1883/
        topic = ecowitt
        log_success = false
        log_failure = true
        enable = true

        [[[inputs]]]
            [[[[outTemp]]]]
                name = outtemp5
                format = %.5f
                unit = degree_F


pi@pi4:~/weewx-data$ mosquitto_sub -t ecowitt/outtemp5 -h 192.168.1.171
76.10000


I then changed it to outtemp0 and %.0f and restarted weewx again...

    [[MQTT]]
        client_id = ecowitt
        server_url = mqtt://192.168.1.171:1883/
        topic = ecowitt
        log_failure = true
        enable = true

        [[[inputs]]]
            [[[[outTemp]]]]
                name = outtemp0
                format = %.0f
                unit = degree_F

pi@pi4:~/weewx-data$ mosquitto_sub -t ecowitt/outtemp0 -h 192.168.1.171
76

gjr80

unread,
Aug 29, 2024, 7:32:25 PM8/29/24
to weewx-user
Alex, you have the correct uploader installed. Compare your current installed extension list:

pi@RPi-Weewx:/etc/weewx $ sudo weectl extension list
Using configuration file /etc/weewx/weewx.conf
Extension Name    Version   Description
mqtt              0.24      Upload weather data to MQTT server.

to your old list:

weectl extension list
Using configuration file /etc/weewx/weewx.conf
Extension Name    Version   Description
MQTT              0.2.0     Extension for uploading LOOP data to an MQTT broker

Matthew's uploader is at v0.24.

As Vince said the uploader formatting works. The next thing to do is look at your config. Unfortunately the uploader does not log the upload format settings so you will need to provide that manually. I suggest you use weectl debug to generate a debug report and post that report. Check the report output carefully, weectl debug should obfuscate sensitive information but it is not perfect.

Gary

Alex Z99

unread,
Sep 2, 2024, 8:12:35 AM9/2/24
to weewx-user
Hi Gary,
thanks a lot for your help. Everything works now as it should. I adopted the weewx.conf and the mqtt uploader formats the values as desired.
br.

Alex
Reply all
Reply to author
Forward
0 new messages