Practical – creating an MQTT pub and sub communication between an ESP32 and a Raspberry Pi
One of the best ways to see MQTT in action is to create a pub/sub model based on communication between two devices. In this case, we will be using the ESP32 and the Raspberry Pi, where the ESP32 will serve as the publisher and subscriber while the Pi serves as the MQTT broker. Here is a breakdown of the roles of all three in this practical:
- Publisher: The ESP32 publishes messages to the MQTT broker. It sends messages to the
/topic/test1
topic when there is user input from the serial monitor, and it also periodically sendsHello World
messages to the/topic/test3
topic every 15 seconds. - Subscriber: The ESP32 is also a subscriber, as it listens for messages on the
/topic/test1
and/topic/test2
topics. When it receives a message on one of these topics, it processes the message in thecallback
function, which in this case prints the received message to the Serial Monitor. - Broker...