mqtt extension - how to force float for values

51 views
Skip to first unread message

vince

unread,
Dec 23, 2021, 5:08:37 PM12/23/21
to weewx-user
I recently went through a full rebuild of my reasonably complicated weewx setup and noticed from my grafana (over influxdb) dashboard that I wasn't getting any weewx data displayed any more in grafana.

After scratching my head a bit I remembered that waaaay back I had to hack on mqtt to force the data fields to be floats rather than strings in order to have telegraf be able to consume the MQTT JSON data for vp2/loop and save the values into influxdb as floats.

The unaltered topic that is published looks like:

{"dateTime": "1640292000.0", "usUnits": "1.0", "interval": "5.0", "rxCheckPercent": "99.08333333333333", "outTemp": "42.9", "highOutTemp": "43.0", "lowOutTemp": "42.8", "rain": "0.0", "rainRate": "0.0", "barometer": "29.458", "wind_samples": "116.0", "inTemp": "73.0", "inHumidity": "41.0", "outHumidity": "84.0", "windSpeed": "10.0", "windGust": "23.0", "windGustDir": "225.0", "windDir": "225.0", "ET": "0.0", "forecastRule": "192.0", "txBatteryStatus": "0.0", "consBatteryVoltage": "4.6", "pressure": "29.06259143856035", "altimeter": "29.452768103211785", "appTemp": "34.745507363020586", "cloudbase": "1386.797032575108", "dewpoint": "38.404093056669524", "heatindex": "40.838", "humidex": "42.9", "inDewpoint": "47.894926888168385", "maxSolarRad": "234.6516473206998", "windchill": "37.236882231370714", "windrun": "0.8333333333333334", "windSpeed10": "10.0", "stormRain": "0.73", "stormStart": "1640073600.0", "dayRain": "0.15", "monthRain": "3.98", "yearRain": "17.97", "dayET": "0.0", "monthET": "0.0", "yearET": "0.0", "leafWet4": "0.0", "insideAlarm": "0.0", "rainAlarm": "0.0", "outsideAlarm1": "0.0", "outsideAlarm2": "0.0", "extraAlarm1": "0.0", "extraAlarm2": "0.0", "extraAlarm3": "0.0", "extraAlarm4": "0.0", "extraAlarm5": "0.0", "extraAlarm6": "0.0", "extraAlarm7": "0.0", "extraAlarm8": "0.0", "soilLeafAlarm1": "0.0", "soilLeafAlarm2": "0.0", "soilLeafAlarm3": "0.0", "soilLeafAlarm4": "0.0", "forecastIcon": "18.0", "sunrise": "1640274840.0", "sunset": "1640305380.0", "hourRain": "0.0", "rain24": "0.4400000000000003", "extraTemp1": "45.61", "extraTemp2": "46.4"}

Notice the values are strings ?
Shouldn't they be numerical ?

As a workaround/hack fix I changed "data[name] = s" to be "data[name] = float(s)" in mqtt.py which restored everything working end-to-end, but I would love to be able to get all the values for the key/value pairs to be float so hacking on the extension is not needed.

Is there a way to do this in weewx.conf without adding dozens of entries to force each individual item within a MQTT published set of loop data ??
Reply all
Reply to author
Forward
0 new messages