Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mosquitto-dev] mosquitto_pub exits on loss of connection to broker

I am using mosquitto with Home Assistant (HA).  I have broker and HA
instance in location A (on the same machine).  Someplace else across the
Internet in location B I have an ESP8266 that reports
temperature/humidity to the broker.

I also have a script running on a computer at B that runs mosquitto_pub
to post "ON" to /sensor/foo/main/online, with a lwt to post "OFF".
(Home Assistant's MQTT binary sensor can be configured for arbitrary
payloads, but OFF and ON are what it expects, so I have aligned my
sensors to that.)  The point is to have a sensor in the HA instance at A
that says if the computer at B is connected to the broker.  Of course,
if that goes to OFF, it could be a number of things, such as power at B,
internet last mile, internet core, bugs in the script, etc.  But when
it's ON, it's a pretty strong indication that everything is ok.

This basically works fine, but mosquitto_pub exits when it loses the
broker connection, either from the broker getting restarted or a
netflake.   I have wrapped it in a while loop, and this works fine.

But, I find this suprrising, as mosquitto_sub appears to reconnnect and
resubscribe.  I realize both are test programs, but the lack of symmetry
is surprising.  Neither man page describes the behavior of the client on
loss of connection the broker.

I am inclined, given enough Copious Spare Time, to write a client in
python using paho to publish the sensor status instead, but for now
"while true; do mosquitto_pub $many_args; sleep 10; done" works fine.

So:

  Clearly it's a man page bug that the behavior is not described, and I
  should file a ticket each for _sub and _pub.

  It's a bug in mosquitto_pub that it doesn't reconnect, like
  mosquitto_sub does, and I should file a ticket about that?


Thoughts?  (The issue tracker is seeming a big unwieldy with lots of
things that are not really mosquitto bugs, but that's another thing.)


Back to the top