Using Lua in building automation : architecture, benefits, and comparison with other scripting languages
Guo, Yajun (2025)
Guo, Yajun
2025
All rights reserved. This publication is copyrighted. You may download, display and print it for Your own personal use. Commercial use is prohibited.
Julkaisun pysyvä osoite on
https://urn.fi/URN:NBN:fi:amk-2025052716706
https://urn.fi/URN:NBN:fi:amk-2025052716706
Tiivistelmä
Modern building automation systems (BAS) must juggle heating, ventilation, airconditioning (HVAC) and wider building management (BMS) tasks on controllers that have only a few megabytes of memory and tight real-time deadlines. Adding a lightweight scripting layer to the embedded Linux firmware of a programmable logic controller (PLC) is one way to keep these devices adaptable without constant recompilation. This thesis examines Lua, whose interpreter occupies roughly 120–250 kB, and asks whether its small footprint and hot-reload capability make it the most practical choice for field-level logic at Bithouse Oy.
The study begins with a technical review of Lua’s runtime and C-API, then documents how Bithouse Oy uses Lua scripts to switch temperature modes, apply heating curves, and expose remote-procedure calls. A representative heating control programme—comprising a hysteresis thermostat and a piece-wise-linear output curve—is implemented in Lua, CPython, MicroPython and JavaScript/Node.js. Each version is exercised for 100 simulated control cycles in a PC testbed configured to mimic PLC constraints. Logged metrics show that Lua completes the loop in ≈ 0.019 ms while consuming ≈ 2.6 MB RSS, CPython is faster (≈ 0.015 ms) but ten times larger, MicroPython is smallest (≈ 40 kB RAM; ≈ 0.04 ms) yet sacrifices some speed, and Node.js is quickest (≈ 0.010 ms) but heaviest (≈ 44 MB RSS).
The results confirm Lua as the best trade-off for DIN-rail PLCs: fast enough for 100 ms control windows, reloadable without downtime, and small enough to coexist with logging and networking tasks. MicroPython approaches Lua’s footprint and suits ultra-small sensor nodes, whereas CPython and Node.js are better reserved for edge computers and dashboards. The thesis closes with practical guidelines for mixing these languages across the BAS stack and outlines future work on LuaJIT trials, IoT integration and richer remote-control schemes—advancing both Bithouse Oy’s client projects and the wider smart building field.
The study begins with a technical review of Lua’s runtime and C-API, then documents how Bithouse Oy uses Lua scripts to switch temperature modes, apply heating curves, and expose remote-procedure calls. A representative heating control programme—comprising a hysteresis thermostat and a piece-wise-linear output curve—is implemented in Lua, CPython, MicroPython and JavaScript/Node.js. Each version is exercised for 100 simulated control cycles in a PC testbed configured to mimic PLC constraints. Logged metrics show that Lua completes the loop in ≈ 0.019 ms while consuming ≈ 2.6 MB RSS, CPython is faster (≈ 0.015 ms) but ten times larger, MicroPython is smallest (≈ 40 kB RAM; ≈ 0.04 ms) yet sacrifices some speed, and Node.js is quickest (≈ 0.010 ms) but heaviest (≈ 44 MB RSS).
The results confirm Lua as the best trade-off for DIN-rail PLCs: fast enough for 100 ms control windows, reloadable without downtime, and small enough to coexist with logging and networking tasks. MicroPython approaches Lua’s footprint and suits ultra-small sensor nodes, whereas CPython and Node.js are better reserved for edge computers and dashboards. The thesis closes with practical guidelines for mixing these languages across the BAS stack and outlines future work on LuaJIT trials, IoT integration and richer remote-control schemes—advancing both Bithouse Oy’s client projects and the wider smart building field.