PubSubClient is still the de facto standard for setting up MQTT on ESP32. Connecting to MQTT comes after you connect to WiFi. But the connection processes for each are different, so let's step through and get you familiar with MQTT connection so that you can do it the right way.
PubSubClient hasn't been updated in five years, it has a lot of blocking code, but... it's effective, and I don't know if there is a faster way to get you going on MQTT.
For more on "All Things IoT" — 🔔 Subscribe
🛠️ What You'll Learn In This Video:
How to connect to an MQTT broker (Mosquitto, in this case)
How to handle the synchronous nature of the connection logic in the library
🖥️ Code Examples:
Ending Code: https://github.com/OhioIoT-MQTT-Examp...
🔗 Resources:
PubSubClient library: https://github.com/knolleary/pubsubcl...
🎬 Video Links:
"WiFi: Next-Level Library": • ESP32 WiFi - Your Next-Level Library
OhioIoT is an IoT platform designed and built for small-scale IoT projects (https://www.ohioiot.com).