Skip to main content
Intro to IoT Class Docs
Tech TLH Discord Code and Coffee TLH GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

MQTT Prep

Note
If you skipped MQTT account setup, you can find the page under Getting Started - HiveMQ

Getting Connection Info

You’ll want to place the info collected here in a separate scratch space like Notepad.

The URL and port from the HiveMQ Manage Cluster page is going to come in handy now, and we might as well write them out like we’ll use in code. Here’s an example:

// NOTE: replace with your own server URL!  The port stays the same.
#define MQTT_SERVER "0123456789abcdef.s1.eu.hivemq.cloud"
#define MQTT_PORT 8883

In addition, the ESP32 board needs credentials to uniquely identify itself. To do that:

  1. Click Access Management at the top, under Free #1
  2. To the right of Credentials is a button labeled Edit. Give it a click.
  3. A yellow button labeled Add Credentials will appear. That’s the right direction!
  4. Give some info for the board to connect:
    • Username: myesp32
    • Permission: Publish Only
    • Password/Confirm: (whatever you want)
  5. Click the yellow Save button.

This info needs to be collected in your Notepad scratch doc:

// NOTE: replace with your own server URL!  The port stays the same.
#define MQTT_SERVER "0123456789abcdef.s1.eu.hivemq.cloud"
#define MQTT_PORT 8883

// Replace these with your own as well
#define MQTT_NAME "myesp32"
#define MQTT_PASS "hunter2"

We need one more piece of info: the topic to publish to. I’m using /code/coffee.

// NOTE: replace with your own server URL!  The port stays the same.
#define MQTT_SERVER "0123456789abcdef.s1.eu.hivemq.cloud"
#define MQTT_PORT 8883

// Replace these with your own as well
#define MQTT_NAME "myesp32"
#define MQTT_PASS "password123"
#define MQTT_TOPIC "/code/coffee"

Keep that Notepad doc handy. You’ll want to plug in the values in the next step.

Next Up: Enabling MQTT