How to Send and Receive Data Using Raspberry Pi Pico W and MQTT
MQTT ( Message Query Telemetry Transport) is one of those protocols that are taken for granted. It just works, with minimal effort, and it has been with us in various forms since 1999. MQTT is bandwidth efficient, lightweight and it can be used on devices with very little resources, including the new $6 Raspberry Pi Pico W. With just 264KB of SRAM, the Pico W relies on clever coding and lightweight protocols, and this is where MQTT comes in.
We’ve already covered how to control a Raspberry Pi Pico W via web services such as Anvil and sent live sensor data to Twitter via IFTTT. But with MQTT we can effortlessly send and receive data with a Raspberry Pi Pico W, and use it with multiple devices across the globe.
MQTT has two basic functions: publish and subscribe. Devices can publish information to MQTT via a broker, using topics to filter messages of a certain type. Subscribers are those interested in receiving the data from the publishing device. They can be another Raspberry Pi Pico W, a laptop, or a data center processing scientific data. An analogy would be YouTube, which acts as a broker for creators publishing their content, and subscribers watching.
In this how-to, we will learn how to publish and subscribe to MQTT data feeds using the Raspberry Pi Pico W and a free public MQTT broker service from HiveMQ. We will publish live data from a PIR sensor, and then control an LED using messages sent to a Pico W.
Read more: How to Send and Receive Data Using Raspberry Pi Pico W and MQTT