ESP32MatrixVM: A Reconfigurable State-Matrix Virtual Machine for Deterministic, Low-Latency Web Programming of ESP32 Sensor Nodes
Web-based programming of ESP32 microcontrollers is usually implemented either with interpreted languages such as MicroPython or with cloud-mediated dashboards that require a gateway or a full firmware recompilation for every code change. Both approaches introduce interpreter overhead, non-deterministic garbage-collection pauses, and network round-trips that limit achievable control-loop rates. This paper presents ESP32MatrixVM, a firmware that compiles a C-like script into a linear state matrix of 128 to 4096 cells of 12 bytes and executes it on a dedicated core through a single O(1) dispatch switch. The compiler, the Wi-Fi stack, and a binary WebSocket server run on Core 0, while Core 1 executes only matrix indexing; there is no parser, no abstract syntax tree, and no heap allocation inside the execution engine. Arithmetic uses Q16.16 fixed point and a 65-entry sine lookup table, and sensor protocols are issued as queued bus transactions so that the execution core never blocks on I²C or UART. A binary WebSocket channel transmits variable names once and then only changed values at 25 Hz, and a JSON-described widget layout binds buttons, sliders, gauges, and joysticks directly to the variable table used by the matrix, without page reloads. The same table can be shared across ESP-NOW nodes, allowing several ESP32 devices to be programmed and observed as one logical machine. On a 240 MHz ESP32-WROOM-32 testbed, the matrix engine sustained 7.1 Mops/s, approximately 148× the throughput of MicroPython and 1.22× that of compiled Arduino C++ for the same mixed workload, while end-to-end WebSocket control latency remained below 15 ms at the median and 28 ms at p99. The results show that moving language complexity from run time to compile time, and moving network work away from the execution core, provides deterministic sub-30 ms control without sacrificing the convenience of browser-based programming. The complete firmware and web interface are publicly available at https://github.com/houslast3/esp32-web-plc.
Authors
- Lucas Lucas Lima Freitag (ORCID: https://orcid.org/0009-0006-8849-5619)
Institutions
- Universidade Federal do Rio Grande do Norte (BR)
Publication Details
- Journal
- Research Square
- Published
- 2026-11-30
- DOI
- https://doi.org/10.21203/rs.3.rs-11920133/v1
- Primary Topic
- Arduino and IoT Applications
- Type
- preprint