Install Prerequisites for Belchertown
This is a four part process, they are split up below.
Install mosquitto package
This is where things begin to get a little funky, primarily if you use Let’s Encrypt or any SSL Certificate services. We’ll touch on that in a short while, as we’ll be going back to Nginx for that. We’ll be making Nginx handle the SSL stuff, and making it act as a layer between mosquitto and the client – skipping the need for mosquitto to have SSL certs loaded.
apt install mosquitto mosquitto-clients
nano /etc/mosquitto/mosquitto.conf
Remove all data from mosquitto.conf excluding include_dir /etc/mosquitto/conf.d
– apt updates or system updates can sometimes obliterate the mosquitto.conf config file, which means your additions won’t persist… and hours of ire will ensue.
nano /etc/mosquitto/conf.d/weewx.conf
- Paste the following into the weewx.conf file…
pid_file /var/run/mosquitto.pid persistence true persistence_location /var/lib/mosquitto/ log_type all websockets_log_level 1023 connection_messages true log_dest file /var/log/mosquitto/mosquitto.log allow_anonymous true password_file /etc/mosquitto/passwd acl_file /etc/mosquitto/acl listener 9001 protocol websockets listener 1883 protocol mqtt log_type error log_type warning log_type notice log_type information
- CTRL O
- CTRL X
service mosquitto restart
Now to generate some username and password details for /etc/mosquitto/passwd
and access limits in /etc/mosquitto/acl
!
mosquitto_passwd -c /etc/mosquitto/passwd -c /etc/mosquitto/passwd UserNameHere
– You’re best to keep it simple, and set the usernamehere
segment to weewx
(it’s what I set).
Once completed, we need to generate a quick access control list for both backend and frontend.
nano /etc/mosquitto/acl
Paste the following details into the acl file…
topic read $SYS/# topic read weather/# user weewx topic weather/#
CTRL O and CTRL X to save and exit.
Install Weewx MQTT extension
User Iain MacDonnell
on Github.com has provided the Weewx MQTT extension here. Condensed instructions are below that work on Debian 10…
pip3 install paho-mqtt
pip3 install ujson
(python-cjson is not supported on Python3 currently)wget -O weewx-mqtt.zip https://github.com/matthewwall/weewx-mqtt/archive/master.zip
- In terminal:
/home/weewx/bin/wee_extension --install weewx-mqtt.zip
ORcd /home/weewx/bin
thenwee_extension --install weewx-mqtt.zip
- Modify
/home/weewx/weewx.conf
file, add the following to the[StdRESTful]
section if it is missing:
[[MQTT]] server_url = mqtt://username:password@192.168.1.123:1883/ aggregation = aggregate topic = weather unit_system = US binding = loop,archive
Please note that you will need to replace username:password with the username and password for the mosquitto
package that you installed above. Change the above to something like weewx
for the username, and the password can be anything really (needs to be hard to guess) – just needs to match what you’ve set for mosquitto (in the next segment). The IP address and port of 192.168.1.123:1883
is by pure example. I use statically assigned LAN IP’s on my internal network – and generally do not bind to localhost/127.0.0.1.
- Next, go to nearly the bottom of the
weewx.conf
file and ensure, user.mqtt.MQTT
was included to therestful_services
segment under[Engine] [[Services]]
. - Once all changes have been made, save the changes, and restart weewx.
Now onto Nginx…
Do you mean
ln -s /etc/nginx/sites-available/weewx.conf /etc/nginx/sites-enabled/weewx.conf
?
Do you mean
ln -s /etc/nginx/sites-available/weewx.conf /etc/nginx/sites-enabled/weewx.conf
?
Thanks, it’s working!