MQTT driver for ESP32 target

MQTT blockset for Waijung 2 (ESP32 target) contains three blocks for connecting, subscribing and publishing with MQTT broker.
Updated 9 Apr 2022

View License

MQTT blockset for Waijung 2 contains three blocks for connecting, subscribing and publishing with MQTT brokers. To use this blockset, user must first download and install Waijung 2 ( as Embedded Coder for ESP32 target. This blockset wraps the C API of ESP-MQTT libray using MATLAB System Object.
The preparation steps are as follows:
1. extract 7z file using 7zip application, avoid to use path with space and special characters.
2. run MATLAB and change working folder to Waijung 2.
3. run install_waijung2.m to install and set path.
4. create a Simulink model, then add Waijung 2 Target Setup block.
5. configure board (flash memory size and COM port)
6. select Embedded Coder app to show C CODE tab.
7. click Build to build application.
To use this blockset, the model should follow the following guideline.
1. Use WiFi Setup block from Waijung 2 blockset to connect with available a WiFi network.
2. Use the output port of WiFi Setup block to trigger the <MQTT connect> block.
3. Put <MQTT subscribe> and <MQTT publish>blocks inside Enabled Subsystem block to be enabled by <MQTT connect> block.
At version 0.1x, only MQTT over TCP and WebSocket is supported. Future improvement is to support other secure connections.

Cite As

Supachai Vorapojpisut (2024). MQTT driver for ESP32 target (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022a
Compatible with R2019b to R2022a
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Update code to Waijung 2 version 22.2c


Rename title, add preview image for the example model, and fix some explanation.


Add example to show how to echo subscribed messages.