User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0
If I remember correctly receiving a
disconnect() callback isn't guaranteed but a connect() is.
Steve
On 4/8/2022 12:47 PM, Dougie Lawson
wrote:
Hi Steve,
This one's an odd program, it connects to two brokers one
as a subscriber (glowmqtt) one as a publisher (running on my
local Raspberry). I grab a lump of JSON from the inbound
message, strip the six bits of data I want out of the 20+
SMETS2 items that come in and republish that (as simpler
JSON).
I'll look at doing the subscribe in the subscriber's
connect callback.
This one I think I can actually help with. Like you I
previously thought I should catch the disconnect callback
and reconnect and found that to be unreliable.
I then discovered that by default mosquitto will handle
the reconnect part for you so there is no need to do
that. I also found out that once I did reconnect that all
my subscriptions were gone and needed to be recreated.
The better approach is to catch the connect callback and
set up your subscriptions there and let the default
behavior handle the reconnects. I have been stable ever
since.
Steve Prior
On 4/8/2022 10:33 AM, Dougie Lawson wrote:
Hi Roger,
I have a bit of code (that fetches my gas &
electricity meter data from glowmqtt.energyhive.com).
In the last couple of weeks that server has been having
connection problems (which the owner tells me they've
solved). But, I found that this piece of code in my C
program is unreliable.
voidglow_disconnect(struct mosquitto *mosq, void *obj, int rc)
It would frequently drive the disconnect
callback with RC=19 (MOSQ_ERR_KEEPALIVE) and fail
to reconnect.
So last night I removed the
mosquitto_loop_forever() and replaced it with
modq_start_loop() and turned all that TLS stuff
into a new function in my code.
I've run that for twelve hours now and haven't
had a failure during reconnection. I'm not sure
whether mosq_loop_forever() is handling the TLS
stuff correctly
Is this an opportunity for you to improve how
mosq_loop_forever() handles a disconnection from a
TLS server? Or was my original code just a pile of
junk?