MQTT error connection with Bekchertown skin

609 views
Skip to first unread message

Carlo

unread,
Mar 16, 2021, 1:56:06 PM3/16/21
to weewx-user
Hi everyone. I have a problem with the MQTT Broker on my localhost server.
My website (meteopievedicampo.ddns.net) work good, but i wanto to enable MQTT.
I open on my firewall the 9001 port.

I have this error in mosquitto log:
-------------------------------------------------------------------------------------------
1615760009: New connection from 127.0.0.1 on port 1883.
1615760009: Client <unknown> disconnected due to protocol error.
1615760060: New client connected from ::ffff:192.168.1.2 as website557173374 (p2, c1, k60).
1615760060: New connection from 127.0.0.1 on port 1883.
1615760060: Client <unknown> disconnected due to protocol error
---------------------------------------------------------------------------------------------

and this is syslog:
---------------------------------------------------------------------------------------------
DEBUG user.mqtt: Failed upload attempt 3: [Errno 104] Connessione interrotta dal corrispondente
ERROR weewx.restx: MQTT: Failed to publish record 2021-03-14 23:18:23 CET (1615760303): Failed upload after 3 tries
---------------------------------------------------------------------------------------------

This is my weewx.conf:

---------------------------------------------------------------------------------------------
[[MQTT]]
        server_url = mqtt://carlo:XXXXXXXXX@localhost:1883/
        topic = weather/loop
        unit_system = METRIC
        binding = archive, loop
        aggregation = aggregate
         [[[tls]]]
            tls_version = tlsv12
            ca_certs = /etc/mosquitto/certs/chain.pem

 # MQTT Websockets defaults
            mqtt_websockets_enabled = 1
            mqtt_websockets_host = meteopievedicampo.ddns.net
            mqtt_websockets_port = 9001
            mqtt_websockets_ssl = 1
            mqtt_websockets_topic = weather/loop
            disconnect_live_website_visitor = 1800000

[MQTTSubscribeService]
    enable = true
    host = localhost
    port = 1883
    keepalive = 60
    username = carlo
    password = XXXXXXXXXX
    binding = loop
    [[message_callback]]
        type = json
    [[topics]]
        unit_system = METRIC
-------------------------------------------------------------------------------------------

And this is my mosquitto.conf:

------------------------------------------------------------------------------------------
persistence false
allow_anonymous true
password_file /etc/mosquitto/passwd
acl_file /etc/mosquitto/acl
# Insecure mqtt to localhost only, and secure mqtt
listener 1883 localhost
listener 8883
certfile /etc/mosquitto/certs/cert.pem
cafile /etc/mosquitto/certs/chain.pem
keyfile /etc/mosquitto/certs/privkey.pem
protocol mqtt
# websockets
listener 9001
certfile /etc/mosquitto/certs/cert.pem
cafile /etc/mosquitto/certs/chain.pem
keyfile /etc/mosquitto/certs/privkey.pem
protocol websockets
------------------------------------------------------------------------------------------------------

Thanks everyone help me!
Carlo

Les Niles

unread,
Mar 17, 2021, 12:11:00 AM3/17/21
to weewx-user
I’ll make a wild guess and hypothesize that the problem is that the weewx MQTT module is trying to speak TLS to the broker on port 1883 rather than 8883.  I would start by getting MQTT working without TLS — just remove the “[[[tls]]]” section from weewx.conf.  Once that is working you can add TLS back, but usually there’s no advantage to encrypting network traffic to localhost.   

  -Les


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/bd2362e9-95fd-4d0b-9aa8-eb0abea25350n%40googlegroups.com.

Carlo

unread,
Mar 17, 2021, 5:36:23 AM3/17/21
to weewx-user
I revome the “[[[tls]]]” section from weewx.conf and now the error disappear:

------------------------------------------------------------------------
INFO weewx.restx: MQTT: Published record 2021-03-17 10:29:15 CET (1615973355)
------------------------------------------------------------------------

but it doesn't work, always in "waiting data from the sation"

this is the log of mosquitto.conf
---------------------------------------------------------------------------
1615973513: mosquitto version 1.6.9 starting
1615973513: Config loaded from /etc/mosquitto/mosquitto.conf.
1615973513: Opening ipv4 listen socket on port 1883.
1615973513: Opening ipv4 listen socket on port 8883.
1615973513: Opening ipv6 listen socket on port 8883.
1615973513: Opening websockets listen socket on port 9001.
1615973518: New connection from 127.0.0.1 on port 1883.
1615973518: New client connected from 127.0.0.1 as MQTTSubscribe-5787 (p2, c1, k60, u'carlo').
1615973536: New client connected from ::ffff:X.X.X.X as website502959092 (p2, c1, k60).
1615973539: New connection from 127.0.0.1 on port 1883.
1615973539: New client connected from 127.0.0.1 as weewx_1f2ccce3 (p2, c1, k60, u'carlo').
1615973539: Client weewx_1f2ccce3 disconnected.
1615973558: Socket error on client website502959092, disconnecting.
------------------------------------------------------------------------------

Thanks
Carlo

Les Niles

unread,
Mar 18, 2021, 5:40:27 AM3/18/21
to weewx-user
Comparing your configuration to mine, I think you should be publishing to “weather” rather than “weather/loop”  That is, in the [[MQTT]] section, set “topic = weather” instead of “topic = weather/loop".  Leave the "mqtt_websockets_topic = weather/loop” in [[Belchertown]][[[Extras]]] as-is. 

By the way, I found mosquitto_pub and mosquitto_sub (from the mosquitto-clients package) to be very useful for debugging MQTT issues. 

  -Les



Carlo

unread,
Mar 18, 2021, 2:53:28 PM3/18/21
to weewx-user
Thanks, thanks, thanks.
Finally i resolve.
I remove /loop and ... now it works and my station refresh every 16 seconds.
Thanks again.
Carlo
Reply all
Reply to author
Forward
0 new messages