Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This walkthrough uses Xedge32, a Lua development environment and firmware for ESP32, with HiveMQ Cloud as the example MQTT broker. You’ll prepare a compatible board, connect it to Wi-Fi and the broker, then send and receive MQTT messages. Xedge32 is not the only Lua option for ESP32; NodeMCU’s ESP32-specific branch is a separate route with different APIs.

What you need before starting

A compatible ESP32 board

Check the exact board revision and memory before installing firmware. Xedge32’s precompiled-firmware requirements list standard ESP32 boards with PSRAM, such as ESP32 WROVER, with at least 4 MB of flash and 4 MB of RAM. For ESP32-S3, the listed minimum is 8 MB of flash and 8 MB of RAM. RealTimeLogic recommends an ESP32-S3 N16R8-style board as one example; that recommendation is not a guarantee that every board sold under a similar name is compatible. Confirm the listing and board revision against the Xedge32 download page and its getting-started documentation.

Other prerequisites

  • A computer and USB connection suitable for your board. USB connector, driver and boot-mode details can vary by board.
  • Access to a Wi-Fi network the ESP32 can join.
  • A HiveMQ Cloud account or another MQTT broker. The example below is framed around HiveMQ Cloud; check its console for current account options and terms.
  • A second MQTT client or the broker’s console, so you can subscribe to the example topics and observe messages.

Install Xedge32 and open its IDE

Xedge32 provides direct Lua access to ESP32 hardware and networking APIs. Its getting-started documentation describes a web installer as the easiest first-install route. Follow the installer’s current prompts for your board rather than assuming one USB or boot procedure applies to every ESP32.

  1. Open the Xedge32 getting-started page and review the firmware requirements for your specific chip and memory configuration.
  2. Connect the board to the computer, then use the web installer linked from the documentation to select and install the appropriate firmware. Follow any board-specific instructions shown by the installer.
  3. After installation, open the Xedge32 browser IDE as directed by the documentation. Confirm that the board is running and that you can create or edit a Lua file before moving on.

Get the broker endpoint and credentials

Create or open your HiveMQ Cloud cluster, then use its console to find the broker hostname and the username and password for a client connection. Keep the hostname, port and TLS settings consistent with the connection details shown for your cluster. The HiveMQ tutorial describes a TLS connection; do not assume that a plain, unencrypted connection is interchangeable with that setup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (3PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • ESP32 is a safe, reliable, and scalable to a variety of applications

Use placeholders in any code you share publicly. A broker username and password are credentials: do not paste real values into a public repository, screenshot, forum post or article. If a credential has been exposed, replace it in the broker console.

Create the Lua MQTT program

The HiveMQ walkthrough published on August 9, 2024 uses Xedge32 and demonstrates publishing temperature strings to sensors/1/temperature and sensors/2/temperature on a timer after connection setup. Its workflow is to fill in broker, username and password from the HiveMQ Cloud console, save the code as an Xedge32 Lua file and run it. Refer to the HiveMQ tutorial for the implementation and check its API calls against the Xedge32 documentation available for your installed firmware.

Rank #2
ELEGOO 3PCS ESP-32 Dev Boards, ESP-WROOM-32, USB-C, WiFi Bluetooth 4.2
  • Dual-Core Performance Up to 240 MHz: Run sensor processing, wireless communication, automation logic and connected-device tasks on a 32-bit dual-core ESP32 platform designed for responsive embedded and IoT projects
  • Built-in Wi-Fi and Bluetooth 4.2: Connect to 2.4 GHz Wi-Fi networks or use Bluetooth Classic and BLE for wireless sensors, smart devices, remote controls, home automation and other connected projects
  • Flexible Power-Saving Modes: ESP32 power-management features support dynamic clock scaling and low-power operating modes, helping developers reduce energy use in compatible sensing, monitoring and connected-device applications, suitable for battery-powered Internet of Things (IoT) devices.
  • USB-C Programming with CP2102: Connect through USB-C for power, sketch uploads and serial monitoring, while GPIO, UART, SPI and I2C interfaces support sensors, displays, motor drivers and other modules (USB-C cable not included)
  • Over-the-Air Update Support: Configure OTA functionality through a compatible ESP-32 software framework to update deployed firmware over Wi-Fi without reconnecting the board by USB for every revision

The key pieces of the program are the connection configuration, the MQTT connection lifecycle, message handling and the timer that triggers publishing. MQTT is event-driven: a client must connect and authenticate successfully before it can exchange messages. A timer should start publishing only after the successful-connection path, not merely because the Lua file started.

1. Set the broker configuration

In the example, replace the placeholder values for broker, username and password with the values from your broker console. Confirm whether the API expects a hostname alone or a hostname plus port, and supply TLS configuration as required by the broker and Xedge32 version. Avoid copying connection settings from NodeMCU examples into an Xedge32 program.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
ELEGOO ESP-32 Super Starter Kit with Tutorial Compatible with Arduino IDE
  • Powerful ESP-32 Board: Unlock the world of Internet of Things (IoT) and advanced electronics with the heart of this kit: the ESP-32 board. It features a powerful dual-core processor, integrated Wi-Fi and Bluetooth 4.2, making it perfect for building connected, smart devices that communicate with your phone or the cloud. It's fully compatible with the Arduino IDE for easy programming.
  • Super Starter Kit: This kit contains over 35 different modules and electronic components, including sensors, displays, motors, and input devices. From LEDs and buttons to an OLED screen, servo motor, and keypad, you have everything needed to explore a vast range of projects in one box.
  • Step by Step Online Tutorial: Jump right in with our detailed, beginner-friendly tutorial. Access 30+ projects with complete code, clear circuit diagrams, and step-by-step instructions. Learn the fundamentals of electronics, coding, and how to utilize the ESP-32's unique capabilities without any prior experience.
  • Hands-on Learning for All Skill Levels: Perfect for students, makers, engineers, and hobbyists. Start with basic circuits and coding, then progress to intermediate and advanced IoT applications. Build practical projects like weather stations, smart home controllers, remote-controlled devices, and interactive gadgets. The skills you learn are the foundation for real-world innovation.
  • Quality & Great Support: Elegoo is committed to quality. We provide a clear, detailed tutorial guide, refined code, and a well-organized component kit. All modules are carefully selected for reliability and ease of use. Our dedicated technical support team and active online community are ready to help you succeed in your learning journey.

2. Handle connection success and failure

Use the Xedge32 connection workflow shown in the HiveMQ example to establish the broker session. Treat the successful connection callback or status as the point at which publishing and subscriptions can proceed. Keep a failure path visible in the IDE’s output or logs so a hostname, network or authentication problem does not look like a successful but silent program.

3. Subscribe and receive messages

For bidirectional communication, the ESP32 must subscribe to a topic and handle incoming messages as well as publish outgoing ones. Add a subscription using the Xedge32 API and callback pattern documented for the firmware you installed; the HiveMQ walkthrough’s two temperature topics illustrate publishing, not by themselves a complete receive example. Choose a distinct test topic, and make the message callback report the topic and payload in the IDE so you can tell a received message from a locally generated one.

Rank #4
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (1 PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos;ESP32 is a safe, reliable, and scalable to a variety of applications
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • 1PCS 30Pin ESP32 Development Board 2.4GHz WiFi Dual Cores Microcontroller Integrated with Antenna RF Low Noise Amplifiers Filters

4. Publish on a timer

Once connected, use the timer pattern from the Xedge32 example to publish a text payload to sensors/1/temperature and sensors/2/temperature. The tutorial’s values are demonstration strings, not sensor readings. If you later attach hardware, verify the board’s GPIO mapping before wiring: Xedge32 documentation notes that pin suitability depends on the board and some pins can conflict with board functions.

5. Stop cleanly when the program unloads

If your program starts a repeating timer, stop or cancel it when the Lua application unloads, using the cleanup mechanism supported by your Xedge32 version. Otherwise, repeated runs or reloads can leave duplicate timers or clients and make the message stream appear duplicated. Follow the lifecycle and API names in the Xedge32 example and current documentation rather than substituting another firmware’s cleanup calls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Ultra-Low power consumption, works perfectly with the Arduino IDE
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • ESP32 is a safe, reliable, and scalable to a variety of applications
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify that sending and receiving work

  1. In a second MQTT client or the broker console, connect to the same broker using the appropriate credentials and TLS settings.
  2. Subscribe to sensors/1/temperature and sensors/2/temperature.
  3. Run the Lua file in Xedge32. Wait for its broker connection to succeed, then check whether the example’s timer-generated payloads appear under the corresponding topics.
  4. To test reception, publish a short message from the second client to the topic your ESP32 subscribed to. Confirm that the ESP32’s message handler reports the topic and payload.

This is a practical verification procedure, not a claim that every board, broker configuration or firmware build has been tested. If the broker console offers a client identifier or connection status, use it to distinguish a connected ESP32 client from the separate test client.

Troubleshoot common connection and message problems

  • The board does not appear in the installer or IDE: recheck the USB connection, any required computer driver, board boot mode and the installer’s board support. Confirm that the selected firmware matches the exact chip and memory configuration.
  • The program cannot reach the broker: verify that the ESP32 joined Wi-Fi, then compare the broker hostname and port character for character with the cluster console. Check TLS settings against the broker’s connection details.
  • The connection is rejected: re-enter the correct broker username and password, and confirm they are client credentials accepted by the cluster rather than unrelated account sign-in details.
  • The client connects but no messages appear: check the exact topic spelling, ensure the publishing timer begins only after connection, and confirm the second client subscribed to the same topic on the same broker.
  • Messages arrive more than once: look for multiple program runs, duplicate timers, or more than one client publishing to the topic. Ensure your unload path stops the previous timer before restarting.
  • Publishing works but receiving does not: confirm that the ESP32 subscribed successfully and that the test message was sent to that subscription topic. Verify the installed Xedge32 API’s callback signature and subscription behavior in its documentation.

NodeMCU is a separate ESP32 Lua option

NodeMCU is not the firmware used in the Xedge32 walkthrough. The standard NodeMCU release and its dev branches target ESP8266; the dev-esp32 branch targets ESP32. Its documentation describes an MQTT module with mqtt.Client, connection callbacks, publish and subscribe operations, and TLS options. Use the ESP32-specific NodeMCU documentation and its MQTT module reference if you choose that route. Do not mix its client creation or callback code with Xedge32 APIs.

For readers using ESP-IDF rather than Lua, Espressif’s separate ESP-MQTT component is a C-based alternative; its repository documents MQTT 3.1.1 and 5.0 support. It is context for a different development stack, not a Lua API.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.