import system
The system module provides timers, event dispatch, memory information, reboot, serial-event helpers, and Berry script update helpers. It is the common glue for scheduled device behavior.
Quick example
import system
def tick():
print(system.heap())
system.schedule("tick", 1000, 1000, -1, tick)
system.cancel("tick")
system.emit("ready", "ok")
importsystem
System runtime native Berry module.
The system module provides timers, event dispatch, memory information, reboot, serial-event helpers, and Berry script update helpers. It is the common glue for scheduled device behavior.
system.schedule(name: str, interval_ms: int, delay_ms: int, repeats: int, callback: callback, *callback_args: any) -> any
system.schedule(name: str, interval_ms: int, delay_ms: int, repeats: int, callback: callback, *callback_args: any) -> anyCreate a named scheduled action.
The name identifies the action and can be passed to system.cancel(name) to stop future runs. Use repeats=-1 for a recurring action that runs forever.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional or keyword | Yes | Scheduled action name. Use the same name with system.cancel(name). |
interval_ms |
int |
positional or keyword | Yes | Interval between executions in milliseconds. |
delay_ms |
int |
positional or keyword | Yes | Initial delay before the first execution in milliseconds. |
repeats |
int |
positional or keyword | Yes | Number of times to run. Use -1 to run forever. |
callback |
callback |
positional or keyword | Yes | Named global function to run. Pass the function without quotes; the transpiler sends its name string to firmware. |
callback_args |
any |
extra positional | No | Optional positional values passed to the callback. |
any Native scheduling result.
system.once(name: str, delay_ms: int, callback: callback, *callback_args: any) -> any
system.once(name: str, delay_ms: int, callback: callback, *callback_args: any) -> anySchedule a one-shot timer.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional | Yes | Timer name. |
delay_ms |
int |
positional | Yes | Delay before execution in milliseconds. |
callback |
callback |
positional | Yes | Named global function to run. Pass the function without quotes; the transpiler sends its name string to firmware. |
callback_args |
any |
extra positional | No | Optional positional values passed to the callback. |
No keyword arguments are supported for this method. Pass callback_args as extra positional arguments after callback.
any Native scheduling result.
system.subscribe(event: str, callback: callback) -> any
system.subscribe(event: str, callback: callback) -> anySubscribe a callback to a named system event.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
event |
str |
positional or keyword | Yes | Event name. |
callback |
callback |
positional or keyword | Yes | Named global function to run. Pass the function without quotes; the transpiler sends its name string to firmware. |
No keyword arguments are supported for this method.
any Native subscription result.
system.emit(event: str, *event_args: any) -> any
system.emit(event: str, *event_args: any) -> anyEmit a named system event.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
event |
str |
positional or keyword | Yes | Event name. |
event_args |
any |
extra positional | No | Optional positional values passed to event subscribers. |
any Native emit result.
system.cancel(name: str) -> any
system.cancel(name: str) -> anyCancel a named scheduled action.
Pass the same name that was used when creating the action with system.schedule(name, interval_ms, delay_ms, repeats, callback, ...).
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional or keyword | Yes | Scheduled action name to cancel. |
any Native cancel result.
system.heap() -> int
system.heap() -> intReturn free heap memory.
int Free heap size in bytes.
system.mem_free() -> int
system.mem_free() -> intReturn free memory.
int Free memory size in bytes, as reported by firmware.
system.heap_largest() -> bytes
system.heap_largest() -> bytesReturn the largest allocatable heap block.
bytes Largest free heap block in bytes.
system.uptime() -> any
system.uptime() -> anyReturn device uptime.
any Uptime in milliseconds.
system.reboot() -> None
system.reboot() -> NoneReboot the device.
None Does not normally return after firmware resets.
system.serial_event(event_type: str, state: str = None, reason: str = None, message: str = None) -> any
system.serial_event(event_type: str, state: str = None, reason: str = None, message: str = None) -> anyEmit a serial-status style event.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
event_type |
str |
positional or keyword | Yes | Serial event type. |
state |
str |
positional or keyword | No | Optional state string. |
reason |
str |
positional or keyword | No | Optional reason string. |
message |
str |
positional or keyword | No | Optional human-readable message. |
any Native event result.