Web Weather > Weather Web Site Help

MQTT Help

(1/1)

TinkerTown:
Hi,

I have been trying to get MQTT working with Weewx and the Belchertown skin for weeks and I am stuck. I thought I had everything working, but I can't get past the page sitting at connecting when trying to update the data. I will try and provide as much data as I can, but I am not a technical writer, so if you need anything to help me get this working just ask!

I believe I know the issue, but I have not been able to figure out how to get it working. My site has a signed SSL certificate and because of that, the connection between the server running Weewx and the MQTT server has to be encrypted, but no matter what I try, I cannot figure out how to get MQTT working with certificates to communicate with the server running Weewx. I am hoping someone can give me instructions on configuring certificates and MQTT to talk to the Weewx server. I have left the information below as a reference. If anyone has or can write instructions to configure the MQTT to work with a certificate would help immensely!

Creating certificates according to some walk throughs, gives me:

1617708378: Error: Unable to load CA certificates. Check cafile "/etc/mosquitto/certs/mosq_serv.key".
1617708378: OpenSSL Error[0]: error:0B084088:x509 certificate routines:X509_load_cert_crl_file:no certificate or crl found



I am running Weewx 4.5.1 on a Raspberry Pi 4. I am using Ubuntu Server 20.04.
I have the Belchertown Skin and running the site on Apache2. I have the webpage running a signed SSL certificate.
I have a virtual server running Ubuntu 20.04 that has the MQTT service running.
Weewx is writing to MySQL on a separate Virtual server.

I followed a guide at https://obrienlabs.net/how-to-setup-your-own-mqtt-broker/ But once I got to the SLSL I couldn't follow because I don't use LetsEncrypt.

System information MQTT Server /etc/mosquitto/conf.d/myconfig.conf:
persistence false
mqtt

listener 1883
protocol mqtt
websockets

listener 9001
protocol websockets

allow_anonymous true
password_file /etc/mosquitto/passwd

acl_file /etc/mosquitto/acl

ACL file:
Allow anonymous access to the sys

topic read $SYS/#
Allow anonymous to read weather

topic read weather/#
weewx readwrite to the loop

user weewxmqttuser
topic weather/#

Netstat results on MQTT server:

sudo netstat -tulpn | grep 1883
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 757/mosquitto
tcp6 0 0 :::1883 :::* LISTEN 757/mosquitto

sudo netstat -tulpn | grep 9001
tcp6 0 0 :::9001 :::* LISTEN 757/mosquitto

UFW Rules:
Status: active

 To                         Action      From
 --                         ------      ----

[ 1] 22/tcp ALLOW IN Anywhere
[ 2] 80/tcp ALLOW IN Anywhere
[ 3] 443/tcp ALLOW IN Anywhere
[ 4] 8883/tcp ALLOW IN Anywhere
[ 5] 9001/tcp ALLOW IN Anywhere
[ 6] 1883 ALLOW IN Anywhere
[ 7] 22/tcp (v6) ALLOW IN Anywhere (v6)
[ 8] 80/tcp (v6) ALLOW IN Anywhere (v6)
[ 9] 443/tcp (v6) ALLOW IN Anywhere (v6)
[10] 8883/tcp (v6) ALLOW IN Anywhere (v6)
[11] 9001/tcp (v6) ALLOW IN Anywhere (v6)
[12] 1883 (v6) ALLOW IN Anywhere (v6)

Firewall Rules from Router:
               WAN    TCP    *    *    WAN address    1883    192.168.1.14    1883    MQTT Protocol    
               WAN    TCP    *    *    WAN address    9001    192.168.1.14    9001    Websocket    
               WAN    TCP    *    *    WAN address    8883    192.168.1.14    8883    MQTT Listener    

sudo tail -f /var/log/mosquitto/mosquitto.log

1617572146: Opening ipv4 listen socket on port 1883.
1617572146: Opening ipv6 listen socket on port 1883.
1617572146: Opening websockets listen socket on port 9001.
1617572291: New connection from 192.168.1.12 on port 1883.
1617572291: New client connected from 192.168.1.12 as weewx_2d392566 (p2, c1, k60, u'weewxmqttuser').
1617572291: Client weewx_2d392566 disconnected.
1617572311: New connection from 192.168.1.12 on port 1883.
1617572311: New client connected from 192.168.1.12 as weewx_a7c2cafa (p2, c1, k60, u'weewxmqttuser').
1617572311: Client weewx_a7c2cafa disconnected.
1617572332: New connection from 192.168.1.12 on port 1883.
1617572332: New client connected from 192.168.1.12 as weewx_2d574dc3 (p2, c1, k60, u'weewxmqttuser').

On the RBPI running weewx I see:
Apr 4 15:16:16 weewx-pi weewx[2455] INFO weewx.restx: MQTT: Published record 2021-04-04 15:16:00 MDT (1617570960)

On the Weewx PI, the config files:

[[MQTT]]
    server_url = mqtt://weewxmqttuser:PASSWORD@192.168.1.14:1883
    topic = weather
    unit_system = US
    binding = archive, loop
    aggregation = aggregate

[[Belchertown]]
    skin = Belchertown
    HTML_ROOT = /var/www/maladomini.net/
    [[[Extras]]]
        earthquake_enabled = 1
        earthquake_server = USGS
        forecast_enabled = 1
        forecast_api_id = REDACTED
        forecast_api_secret = REDACTED
        googleAnalyticsId = REDACTED
    mqtt_websockets_host = "192.168.1.14"
    mqtt_websockets_port = 9001
    mqtt_websockets_enabled = 1
    mqtt_websockets_ssl = 0
    mqtt_websockets_topic = "weather/loop"
    disconnect_live_website_visitor = 1800000

[Engine]

# The following section specifies which services should be run and in what order.
[[Services]]
    prep_services = weewx.engine.StdTimeSynch
    data_services = ,
    process_services = weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate
    xtype_services = weewx.wxxtypes.StdWXXTypes, weewx.wxxtypes.StdPressureCooker, weewx.wxxtypes.StdRainRater, weewx.wxxtypes.StdDelta
    archive_services = weewx.engine.StdArchive

<.restx.StdWOW, weewx.restx.StdAWEKAS, user.mqtt.MQTT, user.owm.OpenWeatherMap, user.wcloud.WeatherCloud
report_services = weewx.engine.StdPrint, weewx.engine.StdReport

Syslog when I restart the Weewx Service:

Apr 4 15:43:25 weewx-pi systemd[1]: Stopping LSB: weewx weather system...
Apr 4 15:43:25 weewx-pi weewx[2840]: * Stopping weewx weather system weewx
Apr 4 15:43:25 weewx-pi weewx[2790] INFO main: Received signal TERM (15).
Apr 4 15:43:25 weewx-pi weewx[2790] INFO weewx.engine: Main loop exiting. Shutting engine down.
Apr 4 15:43:25 weewx-pi weewx[2790] INFO weewx.engine: Shutting down StdReport thread
Apr 4 15:43:26 weewx-pi weewx[2790] INFO user.gw1000: Gw1000Collector thread has been terminated
Apr 4 15:43:26 weewx-pi weewx[2790] INFO main: Terminating weewx version 4.5.1
Apr 4 15:43:30 weewx-pi weewx[2840]: . ...done.
Apr 4 15:43:30 weewx-pi systemd[1]: weewx.service: Succeeded.
Apr 4 15:43:30 weewx-pi systemd[1]: Stopped LSB: weewx weather system.
Apr 4 15:43:30 weewx-pi systemd[1]: Starting LSB: weewx weather system...
Apr 4 15:43:30 weewx-pi weewx[2869]: * Starting weewx weather system weewx
Apr 4 15:43:31 weewx-pi weewx[2880] INFO main: Initializing weewx version 4.5.1
Apr 4 15:43:31 weewx-pi weewx[2880] INFO main: Using Python 3.8.5 (default, Jan 27 2021, 15:41:15) #12[GCC 9.3.0]
Apr 4 15:43:31 weewx-pi weewx[2880] INFO main: Platform Linux-5.4.0-1032-raspi-aarch64-with-glibc2.29
Apr 4 15:43:31 weewx-pi weewx[2880] INFO main: Locale is 'C.UTF-8'
Apr 4 15:43:31 weewx-pi weewx[2880] INFO main: PID file is /var/run/weewx.pid
Apr 4 15:43:31 weewx-pi weewx[2883] INFO main: Using configuration file /home/weewx/weewx.conf
Apr 4 15:43:31 weewx-pi weewx[2883] INFO main: Debug is 0
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: Loading station type GW1000 (user.gw1000)
Apr 4 15:43:31 weewx-pi weewx[2869]: ...done.
Apr 4 15:43:31 weewx-pi systemd[1]: Started LSB: weewx weather system.
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: field map (Cut to reduce Clutter)
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: driver version is 0.3.1
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: GW1000 address is 192.168.1.7:45000
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: poll interval is 20 seconds
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: StdConvert target unit is 0x1
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: Archive will use data binding wx_binding
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: Record generation will be attempted in 'hardware'
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: Using archive interval of 60 seconds (specified in weewx configuration)
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: StationRegistry: Station will be registered.
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: Wunderground-RF: Data for station KNMLOVIN14 will be posted
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: PWSWeather: Data for station PWSLOVNM1 will be posted
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: CWOP: Data for station FW9112 will be posted
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: WOW: Data for station [redacted key] will be posted
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: AWEKAS: Data will be uploaded for user [redacted]
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.mqtt: service version is 0.23
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.mqtt: binding to ['archive', 'loop']
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.mqtt: topic is weather
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.mqtt: desired unit system is US
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.mqtt: data will be uploaded to mqtt://weewxmqttuser:xxx@192.168.1.14:1883
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.owm: service version is 0.9
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.owm: Data will be uploaded for tinkertown
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.wcloud: service version is 0.13
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.wcloud: Data will be uploaded for id=[redacted]
Apr 4 15:43:31 weewx-pi weewx[2883] INFO main: Starting up weewx version 4.5.1
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: Using binding 'wx_binding' to database 'weewx'
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.manager: Starting backfill of daily summaries
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.manager: Daily summaries up to date
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.engine: Starting main packet loop.
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: Using 'rainyear' for rain total
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: skipping rain measurement of 0.0: no last rain
Apr 4 15:43:31 weewx-pi weewx[2883] INFO user.gw1000: Skipping lightning count of 0: no last count
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: MQTT: Published record 2021-04-04 15:43:31 MDT (1617572611)
Apr 4 15:43:31 weewx-pi weewx[2883] INFO weewx.restx: Wunderground-RF: Published record 2021-04-04 15:43:31 MDT (1617572611)

Alas, all I see when I access the website is:

My Station Weather Conditions
(Just a yellow dot) Connecting to weather station real-time data. Last Updated April 4, 2021, 3:50:00 PM

I would appreciate any help you can provide. I am not a master at Linux, but usually, I can follow guides and find the info on the internet somewhere, but I am stumped on getting this working. I know I am missing something, but I just can't figure it out.

Thank you!

I did a connection from a remote tester on port 9001 and it looks like I connect.

1617585978: New client connected from ::ffff:68.233.158.163 as clientId-K4vLZSaW47 (p1, c1, k60, u'weewxmqttuser').

Navigation

[0] Message Index

Go to full version