A 'listener' console was setup:

mosquitto_sub -h test.mosquitto.org -t "myTopic" -v

mosquitto_pub returns an error:

pi@raspberrypi:~ $ mosquitto_pub -h test.mosquitto.org  -t 'myTopic' -m 'hello world'
**Error: The connection was lost.**

What steps, from the command line, can be taken to diagnose if there is a syntax problem?


Replacing the MQTT server with iot.eclipse.org does not suffer the error and returns payloads as expected.

Listener console setup:

mosquitto_sub -h iot.eclipse.org -t "myTopic" -v

Send payload:

mosquitto_pub -h iot.eclipse.org -t 'myTopic' -m 'hello world'

mosquitto_pub returns:

pi@raspberrypi:~ $ mosquitto_sub -h iot.eclipse.org -t "myTopic" -v
myTopic hello world

Publish a payload:

pi@raspberrypi:~ $ mosquitto_pub -h test.mosquitto.org  -t 'myTopic' -m 'hello world'

Changing the MQTT broker demonstrates there is not a syntax error, however, the question remains why there is an error returned in the original testing

  • 1
    @jsotola This comment is not helpful. For starters, what documentation are you referring to?
    – Murphy
    Commented Aug 7, 2019 at 7:08
  • the mosquitto.org documentation
    – jsotola
    Commented Aug 7, 2019 at 7:19
  • @jsotola Comments issued in the imperative (as opposed to the interrogative or declarative) may be construed as disrespectful, especially if they are deemed not helpful.
    – gatorback
    Commented Aug 7, 2019 at 17:12
  • @gatorback, you wanted to know how to determine if there is a syntax error ... the place to start is to find out what the server expects to receive from your device
    – jsotola
    Commented Aug 8, 2019 at 2:17
  • @jsotola If you have solution, I suggest posting a response with code examples as an answer below. I am looking forward to constructive solution to the question: enter the bonus round if you can nail down root cause of the error returned.
    – gatorback
    Commented Aug 8, 2019 at 11:59

2 Answers 2


From the webpage:

This means that it will often be running unreleased or experimental code and may not be as stable as you might hope.

I experience the same problem, but was able to use iot.eclipse.org successfully. There's much traffic there, so better use a specific topic instead of #. For your tests, just pick one from the public brokers list that doesn't require signup.


I found that adding the --insecure option solved this error for me.

mosquitto_pub -t mqtt-topic -m "sample-msg-1" --insecure

My mqtt server is all internal with the port all within docker so, the --insecure option doesn't really add any additional exposure for my case. I'm not sure why that worked for me since I think it should be using mqqt (unencrypted) as opposed to mqqts (encrypted)

  • Can you explain what the --insecure option does? … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Commented Jun 26, 2022 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .