-
Notifications
You must be signed in to change notification settings - Fork 33
MQTT setup
For having live data shown in the charts and gauges, you need:
- One or more data sources (in most cases this your weather station, but it is not limited to this unique source)
- One or more MQTT Brokers for publishing data from the source and subscribing to the topics you publish
- Enabling the data source to emit data using MQTT. With weewx, install https://github.com/matthewwall/weewx-mqtt and get it running by following the instructions there
- The extension will enable an MQTT client to publish your weather data. Configure the extension and set binding to loop packets, for having data available on the live page more or less instantly.
[StdRestful]
[[MQTT]]
server_url = mqtt://broker.hivemq.com:1883/
topic = weather_{any_distinctive_string_that_is_valid_for_topics}
unit_system = METRIC # or whatever you prefer, but note, this will have an impact on the "payload_key" for charts and gauges
binding = loop
The MQTT Broker must be publicly available for viewing live data over the internet, to make it easy for now, the assumption is, you use a public MQTT without needing any credentials. If you decide to use HiveMQ, as in the examples, some limitations may apply. In any case, make sure you define your own, unique topic to avoid interference with other users of the service.
You need to set up the MQTT client for the front end, this client is subscribing to the topic the MQTT client in the backend ist publishing to. You can do this in the skin's config file or in weewx.conf. The preferred way is to do this in weewx.conf
in the [StdReport][[Defaults]]
section, so your config will be available to any installation instance of the skin. In skin.conf
:
[JSONGenerator]
...
[[MQTT]]
[[[connections]]]
[[[[public_mqtt]]]]
broker_connection = ws://broker.hivemq.com:8000/mqtt
[[[[[topics]]]]]
[[[[[[weather_{any_distinctive_string_that_is_valid_for_topics}/loop]]]]]]
type = JSON
In weewx.conf
:
[StdReport]
...
[[Defaults]]
...
[[[JSONGenerator]]]
[[[[MQTT]]]]
[[[[[connections]]]]]
[[[[[[public_mqtt]]]]]]
broker_connection = ws://broker.hivemq.com:8000/mqtt
[[[[[[[topics]]]]]]]
[[[[[[[[weather_{any_distinctive_string_that_is_valid_for_topics}/loop]]]]]]]]
Note: if your site is using https://
, you need to set up an encrypted broker connection also (wss://
and probably a different port) or it won't work in most browsers, they won't accept such a mix of encrypted/unencrypted connections. http://
with wss://
, on the other hand, should work.
Next step, configure payload_key
of each gauge/chart and reading:
The payload_key
is depending on the data source. If you set up everything as described above, for showing "outTemp" it will be outTemp_F. If you use METRIC or METRICWX it will be outTemp_C:
From skin.conf
:
[LiveGauges]
[[outTemp]]
payload_key = outTemp_F # outTemp_C if target_unit 'METRICWX', or 'METRIC' (refer to the setting in weewx.conf)
minvalue = 0
maxvalue = 100
splitnumber = 10 # choose a splitnumber fitting minvalue and maxvalue: e.g.: 0/100: 10, for -20/40: 6
lineColor = '#428bca', '#b44242' # colors are RGBa
lineColorUntil = 32, maxvalue # color from start of gauge to value, change color of gauge ring to show important marks: 32 is freezing point
decimals = 1 # decimals for current value in gauge
#heatMapEnabled = false # disabled heatmap for gauge, default true
#animation = False # default true
...
[LiveCharts]
show_daynight = true
# when transition from light to dark background starts and ends (height of sun in degrees):
transition_angle = 8
[[outTemp]] # choose freely
#animation = False # default true
[[[outTemp]]] #choose weewx field name
payload_key = outTemp_C
showMaxMarkPoint = true
showMinMarkPoint = true
showAvgMarkLine = true
lineColor = '#428bca'
decimals = 1
Since the payload_key is tied to the set unit_system in the MQTT section, you have to override it for every Gauge/Chart which uses a unit which is not the same in every unit_system. You can limit this configuration to the payload_key, if the other settings fit your needs. Do this in weewx.conf
[StdReport]Defaults, as the payload_key is not depending on the presented unit system for a translation.
[StdReport]
[[Defaults]]
...
[[[LiveGauges]]]
[[[[outTemp]]]]
payload_key = outTemp_C
[[[[barometer]]]]
payload_key = barometer_mbar
[[[[windSpeed]]]]
payload_key = windSpeed_mps
[[[[windGust]]]]
payload_key = windGust_mps
[[[LiveCharts]]]
[[[[outTemp]]]]
[[[[[outTemp]]]]]
payload_key = outTemp_C
[[[[[dewpoint]]]]]
payload_key = dewpoint_C
[[[[barometer]]]]
[[[[[barometer]]]]]
payload_key = barometer_mbar
[[[[rain]]]]
[[[[[rain]]]]]
payload_key = rain_mm
[[[[wind]]]]
[[[[[windSpeed]]]]]
payload_key = windSpeed_mps
[[[[[windGust]]]]]
payload_key = windGust_mps
A description for a more advanced MQTT setup may be available in the future, in the meantime see skin.conf
for some examples using multiple, or encrypted brokers.