Skip to main content

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 with svcset
  • Services are shared by all applications

Contents​

  1. System information service
  2. Network service
  3. Sensor services
  4. Keypad information
  5. Bluetooth data reception
  6. Bilibili/YouTube data
  7. PC performance monitoring
  8. Microphone capture
  9. Button ambient lighting
  10. Weather service
  11. HTTP request service
  12. Key sending service (usbkey)
  13. Bluetooth sending service (ble)
  14. UDP sending service
  15. Extension service (ex)
  16. BIOS application management service (bios)

1. System Information Service​

Query system information with svcget; handle nil return values.

PathDescription
$sys.modelDevice model
$sys.VerVersion
$sys.USBWhether USB is connected (boolean)
$sys.volSpeaker volume
$sys.micvolMicrophone volume
$sys.micgainMicrophone gain
$sys.tzcfgTime zone configuration
$sys.langLanguage (1=English, 2=Chinese)
$sys.blgScreen backlight brightness
$sys.bootWhether to skip the startup wizard
$sys.fsmRemaining filesystem space
local lang = svcget('$sys.lang') or 1
local vol = svcget('$sys.vol')

2. Network Service (wifi)​

PathDescription
$wifi.ssidConnected SSID
$wifi.rssiWiFi signal strength
$wifi.readyWhether WiFi is connected (boolean)
$wifi.macMAC address
$wifi.ipIP address

3. Sensor Services​

Real-time data can be queried after connecting sensors.

PathDescription
$sc.TLocal temperature (℃), floating-point (unsupported by default hardware)
$sc.HLocal humidity (%), floating-point, e.g. 50.0 = 50% (unsupported by default hardware)
$sc.ZLocal illuminance, relative integer value (unsupported by default hardware)
$sc.VInput voltage (V), floating-point

4. Keypad Information​

Query key configuration after configuring the keypad.

PathDescription
$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).

PathDescription
$bleadv.rssiSignal strength
$bleadv.addressSender address
$bleadv.dataAdvertisement 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​

PathDescription
$bilibili.biliBilibili ID
$bilibili.bilitypeFollower growth notification sound (0x80=off, 0x81=on)

YouTube​

PathDescription
$youtube.youtuYouTube ID
$youtube.yoututypeFollower growth notification sound (0x80=off, 0x81=on)

7. PC Performance Monitoring​

Monitoring data sent by PC software, updated in real time.

PathDescription
$MT.CPULCPU load
$MT.CPUTCPU temperature
$MT.CPUFERQCPU frequency
$MT.CPUFANCPU fan
$MT.GPULGPU load
$MT.GPUTGPU temperature
$MT.GPUFERQGPU frequency
$MT.GPUFANGPU fan
$MT.RAMLMemory load
$MT.RAMUMemory used
$MT.RAMFMemory frequency
$MT.NETLNetwork latency
$MT.NETUNetwork upload
$MT.NETDNetwork download
$MT.STORAGEStorage usage

8. Microphone Capture​

After enabling mic capture, real-time audio processing information is available.

PathDescription
$aui.micidxMaximum-frequency-bin index after microphone FFT
$aui.micvalAverage volume across microphone FFT frequency bins
$aui.micmvalVolume of the maximum microphone FFT frequency bin
$aui.micvtabVolume values of microphone FFT bins, length 64×2

9. Button Ambient Lighting​

Current device auxiliary light state.

PathDescription
$lfx.idx1typeLight 1 type
$lfx.idx1valLight 1 value
$lfx.idx2typeLight 2 type
$lfx.idx2valLight 2 value

10. Weather Service​

svcget('$weather.cur')​

Queries the forecast, returning a table containing:

FieldTypeDescription
temperaturenumberCurrent temperature (℃)
humiditynumberCurrent humidity (0~1)
skyconstringWeather condition code
aqinumberAir quality index
pm25numberPM2.5 value
windstringWind direction and speed (e.g. "355.08,15.96")
pressurenumberAir pressure
queryCitytableQueried city information (city, lat, lng, distance)
nextHourstableHourly forecast array (entries include temperature, humidity, skycon, etc.)

skycon weather codes:

CodeDescription
CLEAR_DAYClear daytime
CLEAR_NIGHTClear night
PARTLY_CLOUDY_DAYPartly cloudy daytime
PARTLY_CLOUDY_NIGHTPartly cloudy night
CLOUDYOvercast
LIGHT_HAZELight haze
MODERATE_HAZEModerate haze
HEAVY_HAZEHeavy haze
RAINRain
LIGHT_RAINLight rain
MODERATE_RAINModerate rain
HEAVY_RAINHeavy rain
STORM_RAINTorrential rain
FOGFog
LIGHT_SNOWLight snow
MODERATE_SNOWModerate snow
HEAVY_SNOWHeavy snow
STORM_SNOWSnowstorm
DUSTFloating dust
SANDBlowing sand
WINDStrong 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[...]

NumberTypeData format
1delaymsbyte[1] milliseconds
2delaysecbyte[1] seconds
3keybyte[1] keycode
4keysbyte[1] len + byte[len] keycode
5Modifier keysbyte[1] modifier + byte[1] len + byte[len] key
6push keysbyte[1] modifier + byte[1] len + byte[len] pushed key
7mousebyte[1] button + byte[1] x + byte[1] y + byte[1] wheel + byte[1] AC Pan
8Consumer controlbyte[2] keycode
9push Consumer controlbyte[2] keycode
10push custom keysbyte[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 |
+------+------+---------+---------+--------+--------+--------+
FieldValueDescription
Length0x1eFixed
Frame flag0xffUser-defined data
Special flag0x4C, 0x42, 0x52, 0x43"LBRC"
Address flag0x00 / 0x80No/with destination address
Data type0 / 1 / 2Add 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")
ParameterDescription
idxLight number 1/2
ty0xce(0xcf) / 0xfe(0xff)
val0~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:off depends on firmware version; wifi:onoff is 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

config has more subcommands provided by firmware (backlight/buttons/sleep/watch faces, etc.); consult the firmware documentation. Availability of config: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 through stat(6)); this section describes low-level bios service requests. Do not confuse them.

load — Load / Replace / Unload Cartridges​

svcreq("bios", "load:<filename>[:<slot>]")
ParameterDescription
<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 formResult
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 / expect match the same <filename>, so names passed to jump / expect must match the name used for load.