System utilities, timers, memory info, and power management
Provides access to ESP32 system functions including heap/PSRAM memory stats, time and date, timers (set_timeout/set_interval), sleep modes, timezone configuration, and garbage collection control. Timer callbacks run in the main Lua context during the scheduler update cycle.
| Parameter | Description |
|---|---|
| timer_id | ID returned by set_timer or set_interval |
local id = ez.system.set_interval(1000, tick)
-- Later...
ez.system.cancel_timer(id) -- Stop the interval
print("Running on:", ez.system.chip_model())
print("CPU:", ez.system.cpu_freq(), "MHz")
| Parameter | Description |
|---|---|
| seconds | Sleep duration (0 = indefinite, wake on GPIO only) |
| Parameter | Description |
|---|---|
| ms | Delay duration in milliseconds (max 60000) |
ez.audio.beep()
ez.system.delay(500) -- Wait half second
ez.audio.beep()
unload_module("large_module")
ez.system.gc() -- Reclaim memory immediately
| Parameter | Description |
|---|---|
| steps | Number of GC steps (default 10) |
ez.system.gc_step(5) -- Do a little GC work
local pct = ez.system.get_battery_percent()
if pct < 20 then
print("Low battery!")
end
local v = ez.system.get_battery_voltage()
print(string.format("Battery: %.2fV", v))
local info = ez.system.get_firmware_info()
print("Partition:", info.partition_label)
print("App size:", info.app_size / 1024, "KB")
local heap = ez.system.get_free_heap()
print(string.format("Free heap: %d KB", heap / 1024))
local psram = ez.system.get_free_psram()
print(string.format("Free PSRAM: %.1f MB", psram / (1024 * 1024)))
local err = ez.system.get_last_error()
if err then print("Last error:", err) end
print("Loop delay:", ez.system.get_loop_delay(), "ms")
print("Lua using:", ez.system.get_lua_memory() / 1024, "KB")
local t = ez.system.get_time()
if t then print(t.hour .. ":" .. t.minute) end
local ts = ez.system.get_time_unix()
if ts > 0 then
print("Current timestamp:", ts)
end
local offset = ez.system.get_timezone()
print("Timezone: UTC" .. (offset >= 0 and "+" or "") .. offset)
local total = ez.system.get_total_heap()
local free = ez.system.get_free_heap()
print(string.format("Heap: %d%% used", 100 - (free * 100 / total)))
print("Total PSRAM:", ez.system.get_total_psram() / (1024*1024), "MB")
if ez.system.is_low_memory() then
ez.system.gc()
print("Warning: Low memory")
end
if not ez.system.is_sd_available() then
print("Please insert SD card")
end
if ez.system.is_usb_msc_active() then
print("USB mode - SD not available to Lua")
end
| Parameter | Description |
|---|---|
| seconds | Sleep duration (0 = indefinite, wake on GPIO only) |
local start = ez.system.millis()
-- do some work
local elapsed = ez.system.millis() - start
print("Took", elapsed, "ms")
if ez.system.reload_scripts() then
print("Scripts reloaded")
end
print("Restarting in 3 seconds...")
ez.system.delay(3000)
ez.system.restart()
| Parameter | Description |
|---|---|
| ms | Interval between calls (minimum 10ms) |
| callback | Function to call repeatedly |
local id = ez.system.set_interval(1000, function() print("tick") end)
| Parameter | Description |
|---|---|
| ms | Delay in milliseconds (0-100, default 0) |
ez.system.set_loop_delay(10) -- ~100 FPS max
| Parameter | Description |
|---|---|
| year | Full year (e.g., 2024) |
| month | Month (1-12) |
| day | Day of month (1-31) |
| hour | Hour (0-23) |
| minute | Minute (0-59) |
| second | Second (0-59) |
| Parameter | Description |
|---|---|
| timestamp | Unix timestamp (seconds since 1970-01-01) |
| Parameter | Description |
|---|---|
| ms | Delay before callback fires |
| callback | Function to call |
ez.system.set_timer(1000, function() print("Done!") end)
| Parameter | Description |
|---|---|
| tz_string | POSIX timezone string (e.g., "CET-1CEST,M3.5.0,M10.5.0/3") |
ez.system.set_timezone("CET-1CEST,M3.5.0,M10.5.0/3") -- Amsterdam/Berlin
ez.system.set_timezone("EST5EDT,M3.2.0,M11.1.0") -- New York
ez.system.set_timezone("GMT0BST,M3.5.0/1,M10.5.0") -- London
if ez.system.start_usb_msc() then
print("SD card now accessible from PC")
end
ez.system.stop_usb_msc()
print("SD card returned to ezOS")
local up = ez.system.uptime()
print(string.format("Uptime: %d:%02d:%02d",
up / 3600, (up % 3600) / 60, up % 60))
| Parameter | Description |
|---|---|
| ms | Optional sleep time in milliseconds (default 1, max 100) |
while game_running do
update_game()
render_game()
ez.system.yield(10) -- Give background tasks time to run
end
string Screen title that was removedez.bus.subscribe("screen/popped", function(title)
print("Left screen: " .. title)
end)
string Screen titleez.bus.subscribe("screen/pushed", function(title)
print("Navigated to: " .. title)
end)
string Format: "old_title>new_title"ez.bus.subscribe("screen/replaced", function(data)
local old, new = data:match("(.+)>(.+)")
print("Replaced " .. old .. " with " .. new)
end)
string Format: "setting_name=value"ez.bus.subscribe("settings/changed", function(data)
local name, value = data:match("(.+)=(.+)")
if name == "brightness" then
print("Brightness changed to: " .. value)
end
end)