Skip to content

Latest commit

 

History

History
318 lines (228 loc) · 8.75 KB

README.md

File metadata and controls

318 lines (228 loc) · 8.75 KB

OpenTTY — User & Developer Guide

OpenTTY is a complete virtual terminal environment for Java ME (J2ME/MIDP) devices. It implements a miniature operating system — virtual filesystem, Lua interpreter, process management, graphical interface, and network APIs — inside a single MIDlet.

This guide covers usage, the Lua API, the graphical interface, networking, installing programs, and troubleshooting.


Table of Contents


Overview

OpenTTY turns a J2ME device into a portable development and automation environment, featuring:

  • a virtual filesystem with /bin, /boot, /etc, /home, /tmp, /mnt, /dev, /proc
  • a Lua 5.x interpreter with adapted standard libraries (os, io, string, table, ...)
  • an interactive terminal with command and script execution
  • a graphics API for building user interfaces (Alert, Form, List, TextBox)
  • network APIs (HTTP, TCP sockets)
  • process management with PIDs and permissions
  • a RISC-V RV32IM ELF emulator for native C and assembly apps

Getting Started

First Startup

On first launch you'll be asked to create a username (cannot be root) and a password (stored as a hash). Credentials are saved in the OpenRMS RecordStore. After restart, OpenTTY auto-logs in that user.

Terminal Interface

After login you have access to:

  • a command line for executing programs,
  • built-in utilities for creating/editing files (nano),
  • Unix-style file navigation (ls, cd, cat, mkdir, rm, ...).

Running Programs

Programs can be:

  • Lua scripts — interpreted by the Lua runtime,
  • ELF binaries — executed by the RISC-V emulator,
  • shell scripts — implemented in Java.

File System

See the dedicated File System guide for a complete reference.

/
├── bin/   # System applications and commands
├── dev/   # Virtual devices (stdin, stdout, null, random, zero, tty)
├── etc/   # Configuration files (fstab, hostname, motd, os-release)
├── home/  # User data (RMS RecordStores)
├── lib/   # Lua libraries and modules
├── mnt/   # Real device file system (JSR-75)
├── proc/  # Virtual process/sysinfo files
├── root/  # Root user's protected home
└── tmp/   # Temporary in-memory storage

Lua Language

Available Libraries

Library Main Functions
os execute, getenv, setenv, exit, date, time, getuid, su, setproc, getproc, request, mkdir, remove
io read, write, open, close, popen, dirs, copy, mount, new, setstdout
string sub, find, match, upper, lower, byte, char, split, hash, startswith, endswith
table insert, remove, sort, concat, move, pack, unpack, decode
socket connect, server, accept, http.get, http.post, http.rget, http.rpost, peer, device
graphics display, new, append, addCommand, handler, title, ticker, render, vibrate, taskmngr, canvas
java class, getName, run, thread, sleep, yield, delete, midlet.*
debug traceback, getinfo, getregistry
base64 encode, decode
push register, unregister, list, pending, setAlarm
audio load, play, pause, volume, duration, time

Important: the native string library is reduced: it does not provide string.format, string.rep, string.gsub, or string.gmatch. The shipped string rock (require("string")) adds them plus a Lua pattern engine. Use the native string.startswith/string.endswith instead of shadowing them.

See the Lua reference for the full function list and examples.

Native applications are documented in the C and RISC-V ELF developer guide.

Example

print("Welcome to OpenTTY!")

local files = io.dirs(".")
for i = 1, #files do
    print(i .. ": " .. files[i])
end

System API

Kernel / Process

print("Uptime ms:", java.midlet.uptime())

os.execute("ps")  -- list processes
os.exit(0)        -- terminate current process

Filesystem Operations

local hostname = io.read("/etc/hostname")
io.write("Hello", "/tmp/test.txt")

local listing = io.dirs("/bin")

Graphical Interface

Available Components

  • alert — dialog box
  • form — form with fields
  • list — selectable list (implicit/exclusive modes)
  • textbox — text editor
  • screen / buffer — terminal-style screens
  • command — action buttons
  • image, gauge, choice — additional field types
  • graphics.canvas — free-form drawing surface (shapes, text, keys, game loop)

See the Canvas guide for the graphics.canvas API and the cterm guide for the Canvas terminal (/bin/cterm).

Example

local form = graphics.new("screen", "Registration")

graphics.append(form, { type = "field", label = "Name:", length = 50 })
graphics.append(form, {
    type = "choice",
    label = "Options:",
    options = { "Option 1", "Option 2", "Option 3" }
})

local save = graphics.new("command", { label = "Save", type = "ok" })
graphics.addCommand(form, save)

graphics.handler(form, { [save] = function()
    print("Data saved!")
end })

graphics.display(form)

Network Communication

HTTP Client

local response, code = socket.http.get("http://api.example.com/data")
print("Code:", code)
print("Response:", response)

local result = socket.http.post(
    "http://api.example.com/post",
    "data=value",
    { ["Content-Type"] = "application/x-www-form-urlencoded" }
)

TCP Sockets

-- Client
local conn, input, output = socket.connect("example.com:80")
io.write("GET / HTTP/1.0\r\n\r\n", output)
local response = io.read(input)
io.close(conn, input, output)

-- Server
local server = socket.server(8080)
print("Server listening on port 8080...")

Security and Permissions

  • Root (UID 0) — full system access
  • User (UID 1000+) — restricted to their own files and processes
  • Guest — read-only access to public areas
su [password]    # become root (asks for password)
sudo <cmd>       # run a command as root
pkg install <p>  # installing packages requires root

See the User System guide for details.


Installing Programs

Programs can be installed in several ways:

  1. Via package manager — pkg install <name> / pkg install *
  2. Via file — copy .lua files to /bin/
  3. Via network — download from an HTTP server with wget/curl

Lua libraries (modules that extend the runtime instead of adding a program) are installed with luarocks into /lib/<name>.lua and loaded with require("<name>"):

luarocks list --available      # what the mirror offers
luarocks install math string   # install rocks (and their dependencies)
luarocks update                # refresh /etc/rocks from the mirror

See LUAROCKS.md for the rock format, the catalog and the publishing workflow.


Debugging and Troubleshooting

Debug Mode

os.request(1, "debug", true)

Common Error Codes

Code Meaning
0 Success
1 General error
2 Invalid argument
5 Read-only storage / operation not permitted
13 Permission denied
101 Network / connection error
127 File or command not found
255 Command failure (false)

When the runtime raises a Java exception it carries no message; OpenTTY appends a Lua-side traceback pointing at the offending source line.


System Integration

graphics.vibrate(500)          -- vibrate the device

local vm = java.getName()      -- JVM name
print("Java VM:", vm)

os.open("http://opentty.fun")  -- open external URL

Compatibility and Limitations

Supported Devices

  • Java phones (J2ME MIDP-2.0 / CLDC-1.0)
  • Emulators (Wireless Toolkit, MicroEmulator, J2ME Loader)
  • Tablets and PDAs (depending on the Java implementation)
  • Not native Android/iOS

Known Limitations

  • Limited heap (typically 1–4 MB)
  • No direct access to specific hardware (camera, GPS)
  • Network subject to carrier restrictions
  • No encryption for network traffic
  • Performance varies by device