Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] connect_async problem and advice publish/dedconnect needed

"Bayerlein, Markus (I/AEV-23)" <markus.bayerlein@xxxxxxx> wrote:
> Hi there.
> 
> As already stated in the email subject, I encounter two problems with
> the Mosquitto library and hope for some advice.
> 
> 1.     I can't connect to an MQTT broker using 'connect_async'. The
> return value of the function is '-1' (= MOSQ_ERR_CONN_PENDING). The
> connack string returned is 'Connection Refused: unknown reason.' and the
> error string is 'Operation now in progress ' The broker I try to connect
> to is mosquitto (v1.4.1). Using 'connect' works fine.

I see something like this, but it works when it reconnects.  Are you
using loop_start, or loop() directly?  I haven't dug any further in it
yet.

> 
> 2.     When I publish a message and disconnect immediately thereafter,
> the message sometimes is not sent (actually, it depends on the QoS:
> messages with QoS 0 or 1 are sometimes not sent, Qos 2 messages never) .
> If I do a sleep(1) before the disconnect, all messages are delivered
> correctly. I am sure there is a better solution than waiting for a
> second. How do I ensure that all messages are sent before a disconnect?


loop_stop() is a pretty good way of doing it.  Either that, or you have
to wait for all callbacks to fire as Roger mentions in the other reply

Back to the top