Easy IoT and Device Management for Non-C Coders
You will find learning Lua to be super easy if you have worked with other scripting languages — it's the language for children!
Join the DZone community and get the full member experience.
Join For FreeIf you're interested in using microcontrollers for home monitoring or developing commercial IoT products, but don't have any experience with C programming, then this tutorial is for you! You'll learn how to get your projects up and running quickly and easily using a high-level language called Lua. With this tutorial, you won't need any prior C experience, and you'll be able to install the ready-to-use microcontroller firmware by following a few simple instructions. Plus, you'll be able to learn the basics of programming microcontrollers in a fun and interactive way, which will help you to build your skills and confidence as you progress. So why wait? Start learning today and take the first step towards creating exciting and innovative projects with microcontrollers!
Lua - easy for kids to learn and also powerful enough for developing professional IoT solutions!
The Lua language, which is similar to Python, but easier to learn, is very common in the gaming industry. For example, the Roblox game engine provides a free developer environment allowing anyone to create games in Lua. The gaming industry uses Lua since it is easy to embed the Lua virtual machine into a larger program, and the language makes it easy to program the ever-increasing complexity in the game's state machines.
An experienced C developer could take the stock Lua C code delivery and embed it into a microcontroller. One can also download ready-to-use Lua microcontroller versions such as NodeMCU and eLua. However, neither stock Lua, NodeMCU, or eLua includes any useful IoT capabilities. What we need is an IoT library that includes common IoT protocols such as HTTPS, MQTT, SMTP, etc. For professional products, one also needs a framework with easy-to-use security components such as X.509 certificate management. That's where the Barracuda App Server comes in. It provides a complete IoT solution specifically designed for Lua developers, making it easy for you to build secure and reliable IoT products that meet your needs.
This is a Hands-On video tutorial using the ESP32 microcontroller. The firmware (Lua + IoT library) and example Lua code can be downloaded from GitHub.
We use an ESP32 in the video tutorial, but Lua can run on most embedded systems. You can follow along the video tutorial with your own ESP32 WROVER if you follow the firmware installation instructions at the end of this tutorial.
In this 19-minute video tutorial, you'll learn how using Lua can significantly speed up the interactive development time of an IoT-enabled headless device. A headless device is one that has no onboard graphical user interface. To make the development process even faster, we'll use a web-based Lua IDE (a so-called REPL) and the Barracuda Application Server running on the microcontroller. This will allow us to quickly prototype and test our code as we go. When the development is complete, the web-based IDE will be removed and the final IoT application implemented in Lua will be embedded as a ZIP file inside the firmware image. This is a great way to quickly and easily build and deploy IoT projects, and you'll be able to see for yourself just how powerful and efficient Lua can be.
It's important to note that in the video tutorial above, the web-based development environment was removed from the firmware before creating the final release. This is because the IoT example shown in the tutorial does not require an embedded web server.
However, an embedded web server can be very useful for an IoT-enabled product, as it allows for direct interaction with a device running within an intranet. The following video shows how a servo can be controlled in real time using an HTML app powered by WebSockets. The server-side code that controls the servo and manages the WebSocket communication is all written in Lua. This is just one example of how Lua can be used to build powerful and interactive IoT applications, and you'll find that it is a great language for building a wide range of projects.
The above video also shows one of the really cool features enabling the web server to automatically obtain a trusted X.509 Intranet certificate signed by Let's Encrypt. To learn more about how this works, see my DZone article Certificates for Intranet Servers.
Firmware Installation Instructions
As mentioned above, The Lua REPL consists of two main components: the Barracuda App Server and the LSP Application Manager. To use the Lua REPL, these two C code components must be compiled together with the Espressif IoT Development Framework and some startup code. This will create a firmware image that can be uploaded to your ESP32 microcontroller, allowing you to start developing Lua programs on the ESP32.
There are two options for installing the firmware for the Lua REPL, and which one you choose will depend on your experience with running command-line Linux, such as using the Linux Subsystem for Windows.
If you have command-line experience and want to understand the C code compilation and firmware building process in detail, you can follow the Lua ESP32 IoT Developer Kit command-line tutorial.
Alternatively, you can download the virtual machine-based IDE that lets you use a web-based UI for compiling the necessary C code and uploading the produced firmware to the ESP32. Just keep in mind that the IDE includes many examples designed for C programmers, so you'll want to focus on the example designed for compiling and uploading the LSP Application manager. This will allow you to get up and running with the Lua REPL as quickly and easily as possible, regardless of your experience level.
Here's a Fun Example Project:
The owl in the following video, with its blinking eyes and servo-controlled head, is powered by Lua using the Barracuda App Server. The software runs on an ESP32, which includes a Lua REPL called the LSP Application Manager that is based on the Barracuda App Server. See the video description for additional details.
Opinions expressed by DZone contributors are their own.
Comments