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 Aug 7 at 7:08
  • the mosquitto.org documentation – jsotola Aug 7 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 Aug 7 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 Aug 8 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 Aug 8 at 11:59

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.