MQTT Prep
NoteIf you skipped MQTT account setup, you can find the page under Getting Started - HiveMQ
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:
- Click Access Management at the top, under Free #1
- To the right of Credentials is a button labeled Edit. Give it a click.
- A yellow button labeled Add Credentials will appear. That’s the right direction!
- Give some info for the board to connect:
- Username: myesp32
- Permission: Publish Only
- Password/Confirm: (whatever you want)
- 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