mqtt error under docker

125 views
Skip to first unread message

mjuwx

unread,
May 31, 2023, 7:27:01 AM5/31/23
to weewx-user
I have successfully used mqtt when running weewx on a raspberry pi.  I am now running weewx under docker on a more powerful pi4.  The mqtt settings that worked originally now give the following error.

ValueError: Port could not be cast to integer value as '1883 '  - full error log below

1  There were no errors when paho-mqtt was installed.
2  weewx.conf entries
    [[MQTT]]
        enable = True
        log_success = False
        server_url = //broker.emqx.io:1883 /
        topic = xxxx/yyyyyyy
        unit_system = METRIC
        aggregation = aggregate
        binding = archive, loop

        [[[inputs]]]
            [[[[dayRain]]]]
                units = mm
            [[[[rainRate]]]]
                units = mm_per_hour

3  port 1883 on the container is linked to port 1883 on the host

Can anyone help me to resolve this please?

Thanks

Output from log file

May 31 11:26:43 weewx[18] ERROR weewx.restx: MQTT: Unexpected exception of type <class 'ValueError'>
May 31 11:26:43 weewx[18] ERROR weewx.restx: *** Traceback (most recent call last):
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***   File "/home/weewx/bin/weewx/restx.py", line 382, in run_loop
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***     self.process_record(_record, dbmanager)
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***   File "/home/weewx/bin/user/mqtt.py", line 522, in process_record
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***     self.get_mqtt_client()
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***   File "/home/weewx/bin/user/mqtt.py", line 453, in get_mqtt_client
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***     mc.connect(url.hostname, url.port)
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***   File "/usr/local/lib/python3.10/urllib/parse.py", line 177, in port
May 31 11:26:43 weewx[18] ERROR weewx.restx: ***     raise ValueError(f"Port could not be cast to integer value as {port!r}")
May 31 11:26:43 weewx[18] ERROR weewx.restx: *** ValueError: Port could not be cast to integer value as '1883 '
May 31 11:26:43 weewx[18] CRITICAL weewx.restx: MQTT: Thread terminating. Reason: Port could not be cast to integer value as '1883 '
Exception in thread MQTT:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/home/weewx/bin/weewx/restx.py", line 355, in run
    self.run_loop(_manager)
  File "/home/weewx/bin/weewx/restx.py", line 382, in run_loop
    self.process_record(_record, dbmanager)
  File "/home/weewx/bin/user/mqtt.py", line 522, in process_record
    self.get_mqtt_client()
  File "/home/weewx/bin/user/mqtt.py", line 453, in get_mqtt_client
    mc.connect(url.hostname, url.port)
  File "/usr/local/lib/python3.10/urllib/parse.py", line 177, in port
    raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as '1883 '

Tom Hogland

unread,
May 31, 2023, 10:34:54 AM5/31/23
to weewx-user
From the docs, it looks like the correct config line is:

server_url = mqtt://username:password@localhost:1883/

mjuwx

unread,
May 31, 2023, 11:40:59 AM5/31/23
to weewx-user
Thanks Tom.  I substituted the username and password for a public account and that has solved it.  I guess I was put off by the fact that the original one still works.  In fact they are both working in parallel!
Reply all
Reply to author
Forward
0 new messages