Page 1 of 1

connection error setting up MQTT connection

Posted: Tuesday 25 June 2024 13:29
by JanJaap
Running on latest Beta on a RPi 3 (uodating basically daily), I run into the following issue since June 23rd (currently on 16097). I try to setup a MQTT connection from a python plugin (legacy framework) using the Domoticz Connection object, and Iget now a 'connection refused' status with code 111.

Code to setup the connection:

Code: Select all

        protocol = "MQTTS" if self.port == "8883" else "MQTT"

        self.mqttConn = Domoticz.Connection(Name=(protocol + " to " + self.address), Transport="TCP/IP", Protocol=protocol, Address=self. Address, Port=self. Port)
        self.mqttConn.Connect()
Then the onConnect method has the following log line:

Code: Select all

        Domoticz.Debug("onConnect called: Connection '"+str(Connection)+"', Status: '"+str(Status)+"', Description: '"+Description+"'")
Producing this output:
2024-06-25 11:40:29.485 fan slaapkamer: onConnect called: Connection 'Name: '192.168.86.23', Transport: 'TCP/IP', Protocol: 'MQTT', Address: '192.168.86.23', Port: '1883', Baud: -1, Timeout: 0, Bytes: 0, Connected: False, Last Seen: 1970-01-01 01:00:00, Parent: 'None'', Status: '111', Description: 'Connection refused'

Obviously I checked: the address is reachable from the Pi. Nothing changed on the MQTT server side.

Did anything change on the implementation of the Connection object?

Re: connection error setting up MQTT connection

Posted: Wednesday 26 June 2024 8:24
by gizmocuz
Did this every work?

I always use 'paho mqtt' when I want to work with MQTT

Re: connection error setting up MQTT connection

Posted: Wednesday 26 June 2024 20:04
by JanJaap
Yes, it used to work like a charm for many years (oldest files in the repo already 5 years old). Interesting suggestion. Still question remains for me: did anything change to the Domoticz Connection object?

Also a bit more background info: the MQTT server is running on a remote device, a Dyson fan. So I need to setup and maintain a network connection to this remote device. Does paho do this for me? When checking their docs, they have some looping in there. I guess this is already taken care of by the onHeartbeat callbacks in the plugin framework? But can I just create those callbacks or do I need to do something with these loops? As the callbacks are not Domoticz connection regular callbacks?

Do you have an example implementation of a plugin using paho?

Re: connection error setting up MQTT connection

Posted: Thursday 27 June 2024 0:13
by waltervl
You can check how they done it with the mqtt mapper plugin

https://www.domoticz.com/forum/viewtopic.php?t=39279

Re: connection error setting up MQTT connection

Posted: Thursday 27 June 2024 8:05
by gizmocuz
Could it be that you need a username/password?

The MQTT mapper plugin also uses
self.mqttConn = Domoticz.Connection(Name=self.Address, Transport="TCP/IP", Protocol="MQTT", Address=self.Address, Port=self.Port)
self.mqttConn.Connect()

Re: connection error setting up MQTT connection

Posted: Friday 28 June 2024 12:23
by JanJaap
Yes it does need a password but that is handled via the Parameters list. I remember something about you fixing that for me in the past because I fetch the password for machine access from a connected cloud account and write that into the Parameter object from the plugin. And the Connection object doesn't take user/pwd as input:

Code: Select all

            #the Domoticz connection object takes username and pwd from the Parameters so write them back
            Parameters['Username'] = self.myDevice.serial #take username from account
            Parameters['Password'] = self.myDevice.password #override the default password with the one returned from the cloud
So I guess I'll have to dive into the multithreading topic. Nice challenge ;) I remember trying it in the past when it wasn't supported yet (so it failed).

Question: Do I need to upgrade to the extended framework to get multithreading to work or is that also supported in legacy framework? Or should I just move to extended anyway?

Re: connection error setting up MQTT connection

Posted: Monday 08 July 2024 20:24
by JanJaap
OK, played around a bit with paho client. Still no luck. Tried ultimately with telnet sessions: also no luck. So apparently something wrong on the transport level......

Re: connection error setting up MQTT connection

Posted: Monday 08 July 2024 20:50
by JanJaap
ok, final update: German reset (off course....) solved it :evil: