Need some assistance in setting up Mosquitto for IoT core


Hello all,

I have been attempting to setup a mosquitto server in order to publish data about my IoT devices to the IoT core service. This would then be picked up by Alexa so that someone can say "What is my battery voltage?" and Alexa will reply correctly.

Anyways, I followed this guide:

Since I am hosting the Mostquitto on a RPI (I updated to the latest version of mosquitto), I skipped the part about the EC2 server. Everything was able to install fine without issues. When I get to the step on testing the setup, this is were the "error" occurs.

Per the guide, In my MQTT test client on the IoT core, I subscribe to the localgateway_to_awsiot. When I run this command from my RPI: mosquitto_pub -h localhost -p 1883 -q 1 -d -t localgateway_to_awsiot -i localClientID -m "{\"message\": \"helloFromLocalGateway\"}"

I do not see the output on the Test MQTT Client. However, the output of the command is as follows:

Client localClientID sending CONNECT
Client localClientID received CONNACK (0)
Client localClientID sending PUBLISH (d0, q1, r0, m1, 'localgateway_to_awsiot', ... (36 bytes))
Client localClientID received PUBACK (Mid: 1, RC:0)
Client localClientID sending DISCONNECT

From the messages it appears that the message was sent, but why did it not appear on my MQTT test client?

asked 2 years ago1034 views
1 Answer

The output of your mosquitto_pub command only confirms that the message was successfully published to your local mqtt broker, to verify that your RPI can connect to AWS IoT and publish messages, run the following command to directly connect to AWS IoT Core using the credentials and keys your generated by following your guide:

mosquitto_pub -h xxxxxxxxxxxxxxx-ats.iot.<region> -p 8883 --key /etc/mosquitto/certs/private.key --cert /etc/mosquitto/certs/cert.crt --cafile /etc/mosquitto/certs/rootCA.pem -t mytopic -m '{"hello" : "test"}' -i myclientid -d

If you succeed to publish a message with this command, your problem is probably related to a configuration issues with mosquitto server, check your mosquitto server log files.

If this command fails:

  1. Activate CloudWatch Logs in Debug level to diagnose connection attempts
  2. Follow the Diagnosing connectivity issues guide to troubleshoot your connectivity issue.

Hope that helps

profile pictureAWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions