Configuring MyMQTT and Subscribing to Topics

Last modified by Microchip on 2023/11/09 09:03

Setting up an AVR IoT WG development board as an MQTT client involves configuring the device to communicate with an MQTT broker and publish or subscribe to MQTT topics.

For this section, your phone will need to be connected to the same Wi-Fi® as your computer. Connecting your computer to the phone’s hotspot is also an option.  

On your phone, download the MyMQTT app from the Play Store. Open it. On Host, write the IP of the computer with Mosquitto running. How to know your IP address will be explained in the next section.

Procedure

Know your Host's IP

On your computer, open a Command Prompt, and execute the following line to get information about your computer:

ipconfig

Look where it says IPv4 Address, this is the computer's IP address related to the Wi-Fi.

Be careful, that number will change if you change your Wi-Fi in your computer, or sometimes may change for any other unknown reason.

IPv4 Address shown in Command Line

Back to top


Configuring MyMQTT

Here is a short explanation of how to configure each part of the configuration of MyMQTT:
•    Host: your IP address
•    Port: for simple connections, keep 1883
•    Don’t tick SSL box, unless you know what it implies
•    Keep MQTT V5 selected
•    Username: insert the username for your connection. Leave it empty if you are unsure
•    Password: insert the username for your connection. Leave it empty if you are unsure

Now you are ready to publish and subscribe to any topic from your phone to the broker! You can also use your phone and your “localhost” to publish and subscribe, as seen in the “Testing Mosquitto” section.

You should see something like this in the command prompt whenever you publish from your phone:
Recieved Publish from mymqtt in Command Line

Back to top


Subscribing

For later, you will need to subscribe to some topics to see the messages. Click Subscribe, then write your topic. In this tutorial, the first topic that we are going to use is mchp/iot/events. Click Subscribe button and go to the Dashboard section if you want to see the received messages.

Subscribe Events shown in App

Back to top