ColoPLAY Service Extensions
ColoPLAY provides extensive system service interfaces, accessed through svcget/svcset/svcreq.
Notes:
- The b2d module is not supported
- Manage resource usage to avoid insufficient performance and memory
- Service paths starting with
$are read-only and cannot be written withsvcset- Services are shared by all applications
Contents
- System information service
- Network service
- Sensor services
- Keypad information
- Bluetooth data reception
- Bilibili/YouTube data
- PC performance monitoring
- Microphone capture
- Button ambient lighting
- Weather service
- HTTP request service
- Key sending service (usbkey)
- Bluetooth sending service (ble)
- UDP sending service
- Extension service (ex)
- BIOS application management service (bios)
1. System Information Service
Query system information with svcget; handle nil return values.
| Path | Description |
|---|---|
$sys.model | Device model |
$sys.Ver | Version |
$sys.USB | Whether USB is connected (boolean) |
$sys.vol | Speaker volume |
$sys.micvol | Microphone volume |
$sys.micgain | Microphone gain |
$sys.tzcfg | Time zone configuration |
$sys.lang | Language (1=English, 2=Chinese) |
$sys.blg | Screen backlight brightness |
$sys.boot | Whether to skip the startup wizard |
$sys.fsm | Remaining filesystem space |
local lang = svcget('$sys.lang') or 1
local vol = svcget('$sys.vol')
2. Network Service (wifi)
| Path | Description |
|---|---|
$wifi.ssid | Connected SSID |
$wifi.rssi | WiFi signal strength |
$wifi.ready | Whether WiFi is connected (boolean) |
$wifi.mac | MAC address |
$wifi.ip | IP address |
3. Sensor Services
Real-time data can be queried after connecting sensors.
| Path | Description |
|---|---|
$sc.T | Local temperature (℃), floating-point (unsupported by default hardware) |
$sc.H | Local humidity (%), floating-point, e.g. 50.0 = 50% (unsupported by default hardware) |
$sc.Z | Local illuminance, relative integer value (unsupported by default hardware) |
$sc.V | Input voltage (V), floating-point |
4. Keypad Information
Query key configuration after configuring the keypad.
| Path | Description |
|---|---|
$key.KEY[x][y] | x=keypad configuration page (0..3), y=key index (0..6) |
local k1 = svcget('$key.KEY01')
5. Bluetooth Data Reception
Receives Bluetooth advertisements (e.g. from Bluetooth scales).
| Path | Description |
|---|---|
$bleadv.rssi | Signal strength |
$bleadv.address | Sender address |
$bleadv.data | Advertisement data (up to 31+31 bytes) |
local bleadv, vid, ttl = svcget('$bleadv')
pcall(function()
if bleadv.rssi and bleadv.address and bleadv.rssi ~= 0 and bleadv.address ~= '' then
local mac_str = ''
for i = 1, 6 do
mac_str = mac_str .. tostring(string.byte(bleadv.address:sub(i, i)), 16)
end
print("address: " .. mac_str, 55, 80, 7, 0, 16)
print("rssi: " .. bleadv.rssi, 95, 110, 7, 0, 16)
end
end)
6. Bilibili/YouTube Data
Data can be read after configuring the corresponding account.
Bilibili
| Path | Description |
|---|---|
$bilibili.bili | Bilibili ID |
$bilibili.bilitype | Follower growth notification sound (0x80=off, 0x81=on) |
YouTube
| Path | Description |
|---|---|
$youtube.youtu | YouTube ID |
$youtube.yoututype | Follower growth notification sound (0x80=off, 0x81=on) |
7. PC Performance Monitoring
Monitoring data sent by PC software, updated in real time.
| Path | Description |
|---|---|
$MT.CPUL | CPU load |
$MT.CPUT | CPU temperature |
$MT.CPUFERQ | CPU frequency |
$MT.CPUFAN | CPU fan |
$MT.GPUL | GPU load |
$MT.GPUT | GPU temperature |
$MT.GPUFERQ | GPU frequency |
$MT.GPUFAN | GPU fan |
$MT.RAML | Memory load |
$MT.RAMU | Memory used |
$MT.RAMF | Memory frequency |
$MT.NETL | Network latency |
$MT.NETU | Network upload |
$MT.NETD | Network download |
$MT.STORAGE | Storage usage |
8. Microphone Capture
After enabling mic capture, real-time audio processing information is available.
| Path | Description |
|---|---|
$aui.micidx | Maximum-frequency-bin index after microphone FFT |
$aui.micval | Average volume across microphone FFT frequency bins |
$aui.micmval | Volume of the maximum microphone FFT frequency bin |
$aui.micvtab | Volume values of microphone FFT bins, length 64×2 |
9. Button Ambient Lighting
Current device auxiliary light state.
| Path | Description |
|---|---|
$lfx.idx1type | Light 1 type |
$lfx.idx1val | Light 1 value |
$lfx.idx2type | Light 2 type |
$lfx.idx2val | Light 2 value |
10. Weather Service
svcget('$weather.cur')
Queries the forecast, returning a table containing:
| Field | Type | Description |
|---|---|---|
temperature | number | Current temperature (℃) |
humidity | number | Current humidity (0~1) |
skycon | string | Weather condition code |
aqi | number | Air quality index |
pm25 | number | PM2.5 value |
wind | string | Wind direction and speed (e.g. "355.08,15.96") |
pressure | number | Air pressure |
queryCity | table | Queried city information (city, lat, lng, distance) |
nextHours | table | Hourly forecast array (entries include temperature, humidity, skycon, etc.) |
skycon weather codes:
| Code | Description |
|---|---|
CLEAR_DAY | Clear daytime |
CLEAR_NIGHT | Clear night |
PARTLY_CLOUDY_DAY | Partly cloudy daytime |
PARTLY_CLOUDY_NIGHT | Partly cloudy night |
CLOUDY | Overcast |
LIGHT_HAZE | Light haze |
MODERATE_HAZE | Moderate haze |
HEAVY_HAZE | Heavy haze |
RAIN | Rain |
LIGHT_RAIN | Light rain |
MODERATE_RAIN | Moderate rain |
HEAVY_RAIN | Heavy rain |
STORM_RAIN | Torrential rain |
FOG | Fog |
LIGHT_SNOW | Light snow |
MODERATE_SNOW | Moderate snow |
HEAVY_SNOW | Heavy snow |
STORM_SNOW | Snowstorm |
DUST | Floating dust |
SAND | Blowing sand |
WIND | Strong wind |
11. HTTP Request Service
Make an HTTP request with svcreq("http", datapoint).
Data Point Format
{
stat = 0, -- Status: 0=initial, 1=queued, 3=complete; errors have stat=3 and ret<0 (whether running status appears depends on firmware)
sn = 1, -- Sequence number
conntm = 0, -- Connection timeout (ms), 0=default
timeout = 0, -- Operation timeout (ms), 0=default
url = "https://...", -- Request URL
method = 0, -- 0=GET, 1=POST, 2=save file (firmware also supports 3=read / 4=write / 5=delete file)
reqdata = "...", -- POST data
filename = "a.lua", -- File name to save (method=2)
filemode = "a", -- File operation mode
filerl = 512, -- Read length (method=3, default 512)
limitlen = 262144, -- Saved-file size limit (default 256KB)
ret = 0, -- Return code (after completion)
rdata = "", -- Returned data (after completion)
}
Example
-- Start the request
local req = {
sn = 1, stat = 0,
url = "https://api.bilibili.com/x/relation/stat?vmid=327467823"
}
svcset('testsvc', 'baidu1', req)
svcreq("http", "testsvc.baidu1")
-- Check the result
local sc = svcget('testsvc.baidu1.stat')
if sc == 3 then
local data = svcget('testsvc.baidu1')
print(data.ret)
print(data.rdata)
local tbl = cjson_safe.decode(data.rdata)
if tbl and tbl.data then
for k, v in pairs(tbl.data) do
print(string.format("%s=%s", k, v))
end
end
end
12. Key Sending Service (usbkey)
Sends keyboard input through USB keyboard emulation.
svcreq('usbkey', datapoint)
Data point format:
{
stat = 0, -- Status
sn = 1, -- Sequence number
seq = "...", -- Transmission sequence (binary string)
}
seq Sending Sequence Definition
Format: cgy[1byte] + data[...]
| Number | Type | Data format |
|---|---|---|
| 1 | delayms | byte[1] milliseconds |
| 2 | delaysec | byte[1] seconds |
| 3 | key | byte[1] keycode |
| 4 | keys | byte[1] len + byte[len] keycode |
| 5 | Modifier keys | byte[1] modifier + byte[1] len + byte[len] key |
| 6 | push keys | byte[1] modifier + byte[1] len + byte[len] pushed key |
| 7 | mouse | byte[1] button + byte[1] x + byte[1] y + byte[1] wheel + byte[1] AC Pan |
| 8 | Consumer control | byte[2] keycode |
| 9 | push Consumer control | byte[2] keycode |
| 10 | push custom keys | byte[1] len + (byte[1] key type + key[2]) × len |
-- Example: send a Consumer Control key
local req = {sn = 1, stat = 0, seq = string.char(9, 0, 0xea)}
svcset('testsvc', 'usbkey_seq1', req)
svcreq("usbkey", "testsvc.usbkey_seq1")
13. Bluetooth Sending Service (ble)
Sends BLE advertisements to control devices such as quantum lights.
svcreq('ble', datapoint)
Data point format:
{
stat = 0, -- Status
sn = 1, -- Sequence number
reqdata = "...", -- Transmitted data (binary string)
}
Quantum Light Protocol
+------+------+---------+---------+--------+--------+--------+
| Length | Frame flags | Special flags | Address flags | Data type | Address | Data |
+------+------+---------+---------+--------+--------+--------+
| 1 | 1 | 4 | 1 | 1 | 0/6 | n |
+------+------+---------+---------+--------+--------+--------+
| Field | Value | Description |
|---|---|---|
| Length | 0x1e | Fixed |
| Frame flag | 0xff | User-defined data |
| Special flag | 0x4C, 0x42, 0x52, 0x43 | "LBRC" |
| Address flag | 0x00 / 0x80 | No/with destination address |
| Data type | 0 / 1 / 2 | Add remote/delete remote/control |
-- Example: control quantum lights
local req = {
sn = 1, stat = 0,
reqdata = string.char(0x1e, 0xff, 0x4C, 0x42, 0x52, 0x43, 0, 2, 2, 0xff, 0x00, 0xff, 0xff, 0x00)
}
svcset('testsvc', 'ble_seq1', req)
svcreq("ble", "testsvc.ble_seq1")
14. UDP Sending Service
Sends data over UDP, including remotely waking devices.
svcreq('udp', datapoint)
Data point format:
{
stat = 0, -- Status
sn = 1, -- Sequence number
ip = '192.168.33.110', -- Destination IP
port = 80, -- Destination port
reqmac = "...", -- MAC address (for remote wake-up)
reqdata = "...", -- Transmitted data
ret = 0, -- Return code
}
Wake-on-LAN
local req = {
sn = 1, stat = 0,
reqmac = string.char(0x2C, 0x60, 0x0C, 0x63, 0x0A, 0xA1),
port = 7
}
svcset('testsvc', 'udp_seq', req)
svcreq("udp", "testsvc.udp_seq")
15. Extension Service (ex)
Provides access to various general-purpose functions.
svcreq("ex", "type[:cmd_data1][:cmd_data2]...")
LED Control
Controls button lighting.
svcreq("ex", "led:idx:ty:val")
| Parameter | Description |
|---|---|
idx | Light number 1/2 |
ty | 0xce(0xcf) / 0xfe(0xff) |
val | 0~0xff / 0~0xffffffff |
Bluetooth Lighting
Controls button lighting through Bluetooth advertisements; parameters match LED.
WiFi Configuration
svcreq("ex", "wifi:onoff") -- Toggle WiFi
Support for
wifi:on/wifi:offdepends on firmware version;wifi:onoffis the general form.
USB Serial Port
svcreq("ex", "usb:tx:HelloWorld!") -- Send data
Audio Input
svcreq("ex", "aui:mstart") -- Start audio capture
svcreq("ex", "aui:mget") -- Get audio data
svcreq("ex", "aui:mstop") -- Stop capture
After acquiring data, read it through the service path:
svcreq("ex", "aui:mget")
local idx = svcget('$aui.micidx') -- FFT bin with the greatest magnitude
local val = svcget('$aui.micmval') -- Maximum FFT-bin magnitude
local vtab = svcget('$aui.micvtab') -- Magnitudes of all FFT bins
System Configuration
svcreq("ex", "config:vol:50") -- Set speaker volume
svcreq("ex", "config:scanwifi") -- Scan WiFi networks (listen through _svcind)
svcreq("ex", "config:wificon:SSID:PASS") -- Configure and connect to WiFi
svcreq("ex", "config:tzcfg:CST-8") -- Set the time zone
svcreq("ex", "config:lang:2") -- Set language (1=English, 2=Chinese)
svcreq("ex", "config:blg:128") -- Set backlight brightness
svcreq("ex", "config:restore") -- Restore factory settings
confighas more subcommands provided by firmware (backlight/buttons/sleep/watch faces, etc.); consult the firmware documentation. Availability ofconfig:micgain/config:micvol/config:erasefs, etc. also depends on firmware version.
16. BIOS Application Management Service (bios)
Use svcreq("bios", ...) to load, switch, and unload other cartridges at runtime (available on multi-VM platforms such as ColoPLAY). Internal cartridges such as startup screens and menus launch other cartridges through it; normal cartridges can also launch cartridges this way.
Distinction from
load()in system.md:load()is a higher-level Lua API (its string parameter is passed to the new cartridge throughstat(6)); this section describes low-levelbiosservice requests. Do not confuse them.
load — Load / Replace / Unload Cartridges
svcreq("bios", "load:<filename>[:<slot>]")
| Parameter | Description |
|---|---|
<filename> | Target cartridge filename; nil unloads by slot |
<slot> | Integer slot number (>0), chosen by the caller to identify the instance for later replacement/unloading. Optional |
Behavior:
| Call form | Result |
|---|---|
load:<filename> | Load a new cartridge instance (without a slot identifier) |
load:<filename>:<slot> | Empty slot → create; occupied slot → replace its contents with the new cartridge |
load:nil:<slot> | Unload the cartridge in the specified slot |
Returns true on success, nil on failure. BIOS brings the newly loaded cartridge to the foreground in a subsequent lifecycle transition; use jump below for immediate switching.
-- Load into slot 10
svcreq("bios", "load:" .. rom .. ":10")
-- Unload slot i
svcreq("bios", "load:nil:" .. i)
jump — Switch to a Loaded Cartridge
svcreq("bios", "jump:<filename>")
Brings the loaded cartridge named <filename> to the foreground. Succeeds only if the target is already loaded, so it can determine whether load is needed first:
-- Switch directly if loaded; otherwise load first
if not svcreq("bios", "jump:" .. rom) then
svcreq("bios", "load:" .. rom .. ":1")
end
expect — Mark an Expected Cartridge
svcreq("bios", "expect:<filename>[:<slot>]")
Marks the loaded cartridge named <filename> as the "expected / previous" cartridge for BIOS navigation/back logic. Succeeds only when the target is already loaded.
svcreq("bios", "expect:" .. rom)
load/jump/expectmatch the same<filename>, so names passed tojump/expectmust match the name used forload.