SolarOS

SolarOS 4.17.7 manual · api

Python board, apps, jobs, and identity API

API overview · Lua board, apps, jobs, and identity

solaros.board

info() returns a new dictionary with the configured board information:

FieldValue
idStable board ID, such as solar_term.
nameHuman-readable board name.
moduleModule name, or an empty string when unspecified.
capabilitiesList of capability names, such as wifi, gpio, and psram.
psram_bytesDeclared PSRAM capacity in bytes; 0 on boards without PSRAM.

These are build-time board properties, not a hardware probe or a list of installed firmware packages. Optional service bindings still depend on the firmware flavor. PSRAM capacity is not the current free heap. The board API is available whenever Python is included, including headless script runners.

import solaros

board = solaros.board.info()
print(board["id"], board["name"])
if "wifi" in board["capabilities"] and hasattr(solaros, "wifi"):
    print(solaros.wifi.status())

solaros.identity

Identity functions read the SolarOS user and hostname service.

Existing /.solar/user and /.solar/hostname files are imported once when their corresponding NVS keys are absent.

Example:

import solaros

print(solaros.identity.format())

solaros.jobs

Job functions control SolarOS background jobs.

Status dictionaries include tick_interval_ms, tick_deadline_ms, tick_last_us, tick_max_us, and tick_deadline_misses in addition to the job state and tick count. worker_stack_bytes is the declared launch-admission requirement and worker_stack_external identifies its memory region. These fields expose the effective cooperative scheduling policy, memory admission, and measured handler execution time.

Example:

import solaros

solaros.jobs.start("ntp-sync", ["60", "pool.ntp.org"])
print(solaros.jobs.status("ntp-sync"))
solaros.jobs.stop("ntp-sync")

solaros.sessions

Session functions create and close foreground shell/app sessions.

Manual port shell sessions created from scripts do not run /.shell/startup.

Example:

import solaros

try:
    solaros.jobs.stop("slip")
except OSError:
    pass

sid = solaros.sessions.create_shell(
    "uart0", term="ansi", cols=80, rows=25, charset="ascii"
)
# later:
solaros.sessions.close(sid)
solaros.jobs.start("slip", ["uart0", "115200"])

solaros.apps

Application functions inspect the foreground app registry and hand control to another app.

When the launched app exits, the completed interpreter session closes and control returns to the shell.

Example:

import solaros

for app in solaros.apps.list():
    print(app["name"], app["kind"], "-", app["summary"])

if solaros.apps.can_open("/books/guide.epub"):
    solaros.apps.open("/books/guide.epub")

open() selects Web for http:// and https:// URLs and uses the native file association registry for local paths. For example, EPUB and Markdown reading targets select Reader when it is part of the current firmware. Unknown schemes and file types are not opened implicitly.

Longer Example: Status Snapshot

import solaros

solaros.write("SolarOS {}\n".format(solaros.version()))
solaros.write("{}\n".format(solaros.identity.format()))
solaros.write("uptime {}\n".format(solaros.time.uptime()))

battery = solaros.battery.status()
solaros.write("battery {}% {} mV\n".format(battery["percent"], battery["voltage_mv"]))

env = solaros.sensors.environment()
solaros.write("env {:.1f} C {:.1f}%\n".format(env["temperature_c"], env["humidity_percent"]))

wifi = solaros.wifi.status()
solaros.write("wifi {} {}\n".format(wifi["state"], wifi["ip"]))

Quick reference

Use solaros.identity, solaros.jobs, solaros.sessions, solaros.apps for apps, jobs, and identity. See man python for runtime conventions and service availability.