Open VasyaKodovich opened 4 years ago
Hi! I wonder why you don't use a client ID for de mosquitto_new() function? I'm new in mqtt protocol, and I have to create a C client with any C library, and at the time I'm guiding myself with this video: https://www.youtube.com/watch?v=K6Q1Sd9edCw&list=LL&index=1 and here an integer ID is used in mosquitto_new() (and it works)
@FacundoNieto There's often no need to specify a client id. If you're using persistent clients you must provide a client id, but otherwise usually not.
Hello! I was looking to make my mosquitto client be able to switch between different brokers in runtime. The idea is that the address is given, as well as username and password and user connects to a different broker in runtime if need be. I am using broker run on a local machine and a remote one in the network to switch between them. What I stumbled upon is that when I try to connect to a different broker in runtime, client falls into a reconnection loop (which was similar to duplicate ID, but my IDs are always random). Remote broker always refuses connections (CONNACK 5) when local doesn't. Client also apparently sends out CONNECT message twice.
I am not using SSL/TLS and connect through 1883, which remote broker accepts connections from.
I built a minimal example that reproduces the problem. I figured out through removing lines which set parameters to mosquitto instance, is that mosquitto_username_pw_set() invokes refusal from broker - CONNACK(5). When this function is removed, connectoin is accepted CONNACK(0), but CONNECT is still going off twice.
The question is why removing this particular function allows connection to go well and why CONNECT is sent twice at all?
Here's what I've checked and tried:
The only thing that keeps happening is that mosquitto_username_pw_set() invokes CONNACK(5) on remote broker no matter what is put there, and when I remove mosquitto_username_pw_set() from the code entirely, the client connects just fine (CONNACK(0)), but CONNECT is still going off twice, with no CONNACK(5).
I'm not sure why this behavior occurs. Maybe there has to be a specific kind of procedure that is required to reconnect to another broker in runtime?
I'm open to any feedback and clarification requests!
Here's my minimal example: I am building on kubuntu 17.04 (using mosquitto 1.6.7) For network loop I just use mosquitto_loop_start().