connection error setting up MQTT connection Topic is solved

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

connection error setting up MQTT connection

Post 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?
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
User avatar
gizmocuz
Posts: 2548
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: connection error setting up MQTT connection

Post by gizmocuz »

Did this every work?

I always use 'paho mqtt' when I want to work with MQTT
Quality outlives Quantity!
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: connection error setting up MQTT connection

Post 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?
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
User avatar
waltervl
Posts: 5855
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: connection error setting up MQTT connection

Post by waltervl »

You can check how they done it with the mqtt mapper plugin

https://www.domoticz.com/forum/viewtopic.php?t=39279
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
gizmocuz
Posts: 2548
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: connection error setting up MQTT connection

Post 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()
Quality outlives Quantity!
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: connection error setting up MQTT connection

Post 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?
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: connection error setting up MQTT connection

Post 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......
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: connection error setting up MQTT connection

Post by JanJaap »

ok, final update: German reset (off course....) solved it :evil:
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest