An IoT Tutorial Using HiveMQ MQTT Cluster, ESP32, Lua, and Xedge32
In this beginner-friendly tutorial, featuring two comprehensive videos, you will learn how to send and receive messages to the HiveMQ MQTT cluster on the ESP32 microcontroller using the Lua programming language powered by the Xedge32 firmware. We'll also demonstrate how simple it is to securely use MQTT with a TLS connection and showcase tools that enable you to create production-grade MQTT applications.
What is Xedge32?
Xedge32 is a platform designed for the low-cost ESP32 microcontroller, renowned for its versatility in Internet of Things (IoT) projects. The ESP32 offers built-in WiFi and Bluetooth, dual-core processing, and numerous input/output (GPIO) options, making it a robust choice for various IoT applications. Xedge32 uses Lua, a powerful yet beginner-friendly, high-level language ideal for embedded programming.
The Xedge32 Development Environment is an integral platform that includes many IoT protocols. This comprehensive suite is tailored for industrial edge devices, integrating advanced protocols such as MQTT, MQTT Sparkplug, OPC UA, Modbus, HTTPS, and WebSockets.
With Xedge32, programming embedded systems become accessible to everyone, not just embedded C/C++ experts. It simplifies the development of robust, commercial IoT products, making advanced programming more approachable and affordable.
Why Lua?
Lua's compact size, impressive speed, and engineering excellence make it unique. It is also the fastest non-JIT high-level language. Lua was not designed to be a standalone language; it was crafted to be an embeddable extension language from the ground up. This makes Lua an excellent choice for embedding and integrating with software like Xedge32, which extends the standard Lua APIs for IoT, web, and ESP32 GPIO programming. Lua is known for its simplicity and ease of use.
If you're not familiar with Lua yet, you can get a quick start by checking out an online interactive Lua tutorial.
Xedge32: Perfect for Hardware Engineers
For hardware engineers, Xedge32 offers an ideal platform to bridge the gap between hardware and software development. Learning Lua is straightforward, making it accessible for hardware engineers without extensive IoT security, system design, and programming backgrounds. Unlike traditional development requiring complex C coding, IoT security considerations, and device driver design, Xedge32 simplifies the process with an easy-to-use ESP32 GPIO API and many IoT APIs. This allows hardware designers to use the ESP32 as the main controller in new designs or to easily IoT-enable existing designs using the ESP32 as a coprocessor. This flexibility significantly reduces development time and complexity.
Getting Started
In the first video tutorial, you will be guided through installing the ready-to-run Xedge32 firmware. The installation is straightforward and is performed using your browser.
Watch the Xedge32 installation video tutorial
Configuring Your HiveMQ MQTT Cluster and Connecting Xedge32
Once you are familiar with the web-based Xedge32 source code IDE, it's time to set up your HiveMQ Cluster and connect your Xedge32-powered ESP32 to it.
Watch the HiveMQ cluster video tutorial
Ready to Run MQTT Lua Code
The following ready-to-run MQTT Lua program is similar to the one presented in the video. You can copy this Lua code, create an xlua file using the Xedge32 IDE, and paste the content into this file. Before running the code, make sure to set the following three variables: broker, username, and password. You can find these details in your HiveMQ Cloud console. See the MQTT Lua reference manual for more information on the APIs used.
Conclusion
By following this MQTT beginner tutorial, you'll gain the skills needed to leverage MQTT with HiveMQ and Xedge32, creating efficient and secure IoT applications easily and confidently. For additional details on Xedge32 and how to select a suitable ESP32 development board, see the Xedge32 introduction page.