MQTT
To publish your MQTT server with ngrok:
- Start an MQTT server.
mosquitto
- Launch ngrok.
ngrok tcp 1883
- Configure MQTT Explorer with your ngrok URL.
Step 1: Start an MQTT server
For this tutorial, we'll use the Eclipse Mosquitto quickstart available on GitHub.
After downloading the Mosquitto binary for your operating system, start the server by running this command in your terminal:
mosquitto
The server runs by default on port 1883. Your output should look like this:
1734408888: mosquitto version 2.0.20 starting
1734408888: Using default config.
1734408888: Starting in local only mode. Connections will only be possible from clients running on this machine.
1734408888: Create a configuration file which defines a listener to allow remote access.
1734408888: For more details see https://mosquitto.org/documentation/authentication-methods/
1734408888: Opening ipv4 listen socket on port 1883.
1734408888: Opening ipv6 listen socket on port 1883.
1734408888: mosquitto version 2.0.20 running
Step 2: Launch ngrok
Once your app is running successfully on localhost, let's get it on the internet securely using ngrok!
-
If you're not an ngrok user yet, just sign up for ngrok for free.
-
Go to the ngrok dashboard and copy your auth token.
-
Start ngrok by running the following command:
ngrok tcp 1883
-
ngrok will display a URL where your localhost application is exposed to the internet (copy this URL for use with MQTT Explorer).
Step 3: Integrate MQTT Explorer
-
Open MQTT Explorer and click the plus sign to create a new MQTT connection. Enter the TCP address from the last step and click "Connect":
-
You should see a few new lines in your MQTT server logs:
1734410153: New connection on port 1883.
1734410153: New client connected as mqtt-explorer-ba9b56f9 (p2, c1, k60).
- The client, MQTT Explorer, is now connected to your server over the public internet! But you need to subscribe to a topic to get messages from the client. In your terminal, open a new tab and enter:
mosquitto_sub -t 'example/topic' -v
-
Back in MQTT Explorer, publish a message to
example/topic
: -
You'll see the message in the terminal tab where you subscribed to the topic:
example/topic hello world