Every time you subscribe in MQTT, you need to write a message handler. And, every time you write a message handler, you need to remember how to convert the payload to a string. Let's do it once, and abstract that transformation away into your library, so you can focus on handling topic/message strings instead.
PubSubClient is still the de facto standard for setting up MQTT on ESP32. It 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 inject a message handler into your MQTT library from the outside
- How to abstract away the burden of transforming the PubSubClient payload into something you can use
🖥️ *Code Examples:*
- Starting Code:
https://github.com/OhioIoT-MQTT-Examples/ESP32-Subscribe.git- Ending Code:
https://github.com/OhioIoT-MQTT-Examples/ESP32-Handle-Messages.git🔗 *Resources:*
- PubSubClient library:
https://github.com/knolleary/pubsubclient🎬 *Video Links:*
"Previous Video":
https://youtu.be/ahzX8AzNy48OhioIoT is an IoT platform designed and built for small-scale IoT projects (
https://www.ohioiot.com).