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.
- Overview
- Getting Started
- File System
- Lua Language
- System API
- Graphical Interface
- Network Communication
- Security and Permissions
- Installing Programs
- Debugging and Troubleshooting
- System Integration
- Compatibility and Limitations
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
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.
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, ...).
Programs can be:
- Lua scripts — interpreted by the Lua runtime,
- ELF binaries — executed by the RISC-V emulator,
- shell scripts — implemented in Java.
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
| 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
stringlibrary is reduced: it does not providestring.format,string.rep,string.gsub, orstring.gmatch. The shippedstringrock (require("string")) adds them plus a Lua pattern engine. Use the nativestring.startswith/string.endswithinstead 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.
print("Welcome to OpenTTY!")
local files = io.dirs(".")
for i = 1, #files do
print(i .. ": " .. files[i])
endprint("Uptime ms:", java.midlet.uptime())
os.execute("ps") -- list processes
os.exit(0) -- terminate current processlocal hostname = io.read("/etc/hostname")
io.write("Hello", "/tmp/test.txt")
local listing = io.dirs("/bin")alert— dialog boxform— form with fieldslist— selectable list (implicit/exclusive modes)textbox— text editorscreen/buffer— terminal-style screenscommand— action buttonsimage,gauge,choice— additional field typesgraphics.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).
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)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" }
)-- 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...")- 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 rootSee the User System guide for details.
Programs can be installed in several ways:
- Via package manager —
pkg install <name>/pkg install * - Via file — copy
.luafiles to/bin/ - 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 mirrorSee LUAROCKS.md for the rock format, the catalog and the publishing workflow.
os.request(1, "debug", true)| 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.
graphics.vibrate(500) -- vibrate the device
local vm = java.getName() -- JVM name
print("Java VM:", vm)
os.open("http://opentty.fun") -- open external URL- 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
- 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