Skip to main content

ColoPLAY Service Extension

Provide functional services on ColoPLAY

Notice:

  • The use of extended services requires attention to resource utilization to avoid insufficient performance and memory.
  • If the service path starts with $, svcset cannot be used.
  • Service is shared by all applications.

System Information Service

Through svcget, you can query system information, pay attention to the processing when the return value is nil.

  • $sys.model device model
  • $sys.Ver version number
  • $sys.USB whether usb is connected, Boolean value
  • $sys.vol speaker volume
  • $sys.micvol microphone volume
  • $sys.micgain microphone gain
  • $sys.tzcfg time zone
  • $sys.lang Language 1-English 2-Chinese
  • $sys.blg screen backlight brightness
  • $sys.boot whether to skip the boot wizard
  • $sys.fsm file system remaining

The following example obtains the configuration:

local lang=svcget('$sys.lang') or 1

Network Service-WIFI

Can query wifi status

  • $wifi.ssid - the ssid of the connection
  • $wifi.rssi - wifi signal strength
  • $wifi.ready - whether wifi is connected, boolean value
  • $wifi.mac - mac address
  • $wifi.ip - ip address

Sensor Service

If the device is connected to the sensor, real-time data can be queried.

  • $sc.T Local temperature, unit Celsius, floating point number (default hardware does not support)
  • $sc.H local humidity, unit %, floating point number: 50.0 means 50% (default hardware does not support)
  • $sc.Z Local illuminance, integer (relative value, reflecting the brightness level)
  • $sc.V Access voltage, unit V, floating point number

Small Keypad Information

If a small keyboard is configured, you can query the relevant configuration through the following data points.

  • $key.KEY[x][y] - x:keyboard configuration page 0..3 ; y:key index [0..6]
    local k1=svcget('$key.KEY01')

Bluetooth Data Reception

The device can receive Bluetooth broadcast information, so that it can connect to devices such as Bluetooth weight scales that use Bluetooth broadcast to publish data in real time.

  • $bleadv.rssi signal strength
  • $bleadv.address sender address
  • $bleadv.data Received broadcast data, len--31【Advertising data】+31【Scan response data】
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)

B Station Data

If the B station account is configured, then the data can be read from the following data points.

  • $bilibili.bili B station ID
  • $bilibili.bilitype Follower growth prompt sound 0x80-off 0x81-on

YOUTUBE Data

If a youtube account is configured, then the data can be read from the following data points.

  • $youtube.youtu youtube ID
  • $youtube.yoututype Follower growth prompt sound 0x80-off 0x81-on

PC Performance Monitoring

The PC-side software will send monitoring data, and you can read real-time updated data from the next data point.

  • $MT.CPUL
  • $MT.CPUT
  • $MT.CPUFERQ
  • $MT.CPUFAN
  • $MT.GPUL
  • $MT.GPUT
  • $MT.GPUFERQ
  • $MT.GPUFAN
  • $MT.RAML
  • $MT.RAMU
  • $MT.RAMF
  • $MT.NETL
  • $MT.NETU
  • $MT.NETD
  • $MT.STORAGE

aui Microphone Pickup Data

After turning on the mic pickup function, you can get real-time audio processing information from the following location.

  • $aui.micidx The maximum frequency point after the microphone picks up fft
  • $aui.micval The average volume of each frequency point after the microphone picks up fft
  • $aui.micmval Microphone pickup fft maximum frequency point volume value
  • $aui.micvtab The volume value of each frequency point after the microphone picks up fft Length 64*2

lfx Button backlight

Current state of the device auxiliary light

  • $lfx.idx1type
  • $lfx.idx1val
  • $lfx.idx2type
  • $lfx.idx2val

One key Boot Data

Configured PC mac address

  • $powerup.powerMac

Get Weather Forecast

svcget('$weather.cur') query the weather forecast

The content format of the weather forecast data example is as follows:

+"wind" ["355.08,15.96"]
+"pressure" [101348.367]
+"pm25" [9]
+"nextHours"(table: 0x0b4d0680)
| +1(table: 0x0b4d06a8)
| +"wind" ["355.35,15.39"]
| +"pressure" [101303.365]
| +"pm25" [8]
| +"skycon" ["CLOUDY"]
| +"hourFullStr" ["2023-04-25T16:00+08:00"]
| +"hourTs" [1682409600]
| +"temperature" [19.67]
| +"humidity" [0.68]
| +"aqi" [33]
+"queryCity"(table: 0x0b4cf290)
| +"distance" [12779.155401337]
| +"lat" [23.021548]
| +"city" ["广东省佛山市"]
| +"lng" [113.121416]
+"skycon" ["CLOUDY"]
+"queryHourTs" [1682406000]
+"queryHourFullStr" ["2023-04-25T15:00+08:00"]
+"temperature" [19.5]
+"humidity" [0.71]
+"aqi" [30]

Possible values of skycon:

local skycon_namemap={
CLEAR_DAY='clear day';
CLEAR_NIGHT='clear Night';
PARTLY_CLOUDY_DAY='partly cloudy day';
PARTLY_CLOUDY_NIGHT='partly cloudy night';
CLOUDY='cloudy';
LIGHT_HAZE='light';
MODERATE_HAZE='moderate haze';
HEAVY_HAZE='heavy haze';
RAIN='rain';
LIGHT_RAIN='light rain';
MODERATE_RAIN='moderate rain';
HEAVY_RAIN='heavy rain';
STORM_RAIN='storm rain';
FOG='fog';
LIGHT_SNOW='light snow';
MODERATE_SNOW='moderate snow';
HEAVY_SNOW='heavy snow';
STORM_SNOW='storm snow';
DUST='dust';
SAND='sand';
WIND='wind';
}

HTTP Request

{
stat=(int); --0:inti, 1:que, 2: run, 3: end, -1:err
sn=(int);
conntm=(int); --connect timeout. 0 for default
timeout=(int); --op timeout. 0 for default
url="http://123.12.123.12/893";
[method]=0; -- 0:get 1:post 2:save file 3:read file 4:write file 5:remove file
[filename]="a.lua"; -- save file name
[filemode]="a"; -- File operation mode
[filerl]=1024; -- read file len 512 for default
[limitlen]=10240; -- save file limit length 20480 for default
[reqdata]="dddd"; -- post data
ret=(int);
rdata="";
}
--example:
if not doreq then
local req={sn=1,stat=0,url="https://api.bilibili.com/x/relation/stat?vmid=327467823"}
svcset('testsvc','baidu1',req)
svcreq("http","testsvc.baidu1")
doreq=true
end

-- check result
local sc,vid,ttl=svcget('testsvc.baidu1.stat')
if sc ==3 then
local sc,vid,ttl=svcget('testsvc.baidu1')
print(sc.ret)
print(sc.rdata)
local tbl=cjson_safe.decode(sc.rdata)
if tbl and tbl.data then
for k,v in pairs(tbl.data) do
print(string.format("%s=%s",k,v))
end
end
--svcset('testsvc.baidu1','stat',4)
else
print(tostring(sc))
end

key To Send Service

svcreq('usbkey',datapoint)

  • Simulate keyboard via usb, service name usbkey
  • datapoint is a data point, providing parameters and operation results, the data format is as follows
{
stat=(int); --0:inti, 1:que, 2: run, 3: end, -1:err
sn=(int);
seq=""; -- send que
}

Send Sequence Seq Definition

cgy[1byte]+data[...]

  • [1]delayms: byte[1] ms
  • [2]delaysec: byte[1] sec
  • [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] modifer, 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 (key values can be viewed in hid.h):

    local req={sn=1,stat=0,seq=string.char(9,0,0xea)}
svcset('testsvc','usbkey_seq1',req)
svcreq("usbkey","testsvc.usbkey_seq1")

Bluetooth Send Service

svcreq('ble',datapoint)

  • Send ble broadcast data, service name ble
  • datapoint is a data point, providing parameters and operation results, the data format is as follows
{
stat=(int); --0:inti, 1:que, 2: run, 3: end, -1:err
sn=(int);
reqdata=""; -- send data que
}

Control Quantum Light Reqdata Definition

protocol
+--------+------------+--------------+--------------+-----------+-----------+---------+
| length | frame flag | special flag | address flag | data type | address | data |
+--------+------------+--------------+--------------+-----------+-----------+---------+
| 1 | 1 | 4 | 1 | 1 | 0/6 | n |
+--------+------------+--------------+--------------+-----------+-----------+---------+
  • length

    Fixed to 0x1e
  • frame flag

    Fixed to 0xff -- user-defined data
  • special flag

    Fixed to 0x4C, 0x42, 0x52, 0x43 -- LBRC
  • address flag

    0    No target address, that is, the address data length is 0
    0x80 Has the target address, that is, the address data length is 6
  • data type

    0  Add remote control data n=0
    1 Delete remote control data n=0
    2 Control data idx(1) + type(1) + val(4) + ef_mode(1) + ef_idx(1)

Example:

    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")

UDP Send Service

svcreq('udp',datapoint)

  • send udp data, service name udp
  • datapoint is a data point, providing parameters and operation results, the data format is as follows
{
stat=(int); --0:inti, 1:que, 2: run, 3: end, -1:err
sn=(int);
ip='192.168.33.110'
port=80
[reqmac]="2C:60:0C:63:0A:A1"; -- post data
[reqdata]="dddd"; -- post data
ret=(int)
}

Remote Boot

Example:

    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")

Extended Service

The extension service provides access to various general functions, the service name is ex, and the data point is directly the parameter of the request.

Access can be requested directly using svcreq.

svcreq("ex","type[:cmd_data1][:cmd_data2]...")

{
type -- led、bles、wifi、usb、mic、config
[cmd_data1]\[cmd_data2] -- service parameter
}

led

Control key light

  • service parameter idx:ty:val

    idx 1\2
    ty 0xce(0xcf)\0xfe(0xff)
    val 0~0xff \ 0~0xffffffff

bles

Send Bluetooth broadcast packets to control button lights

  • service parameter idx:ty:val

    idx 1\2
    ty 0xce(0xcf)\0xfe(0xff)
    val 0~0xff \ 0~0xffffffff

wifi

wifi configuration

  • service parameter onoff / on / off
svcreq("ex","wifi:onoff") --switch wifi start state

usb

usb serial port

  • service parameter tx:tx_data
    svcreq("ex","usb:tx:".."HelloWorld!") --Send tx_data using usb serial port

aui

audio input service

  • Service parameter mstart: start collecting audio data

  • Service parameter mstop: stop collecting audio data

  • Service parameters mget: get audio data

svcreq("ex","aui:mstart") --start

-- Loop update data
svcreq("ex","aui:mget")
local idx=svcget('$aui.micidx')
local v=svcget('$aui.micmval')
local v_tab=svcget('$aui.micvtab')
--....data processing
--
svcreq("ex","aui:mstop") --stop

config

operating system configuration

  • Service parameter vol: volnum speaker volume

  • Service parameter micgain: gain microphone gain

  • Service parameter micvol: volnum microphone volume

  • Service parameter scanwifi Search Wi-Fi list, monitor data through _svcind

  • Service parameter wificon:ssid:password Configure Wi-Fi and connect

  • Service parameter tzcfg:tz Configure time zone: CST-8; CST-0

  • Service parameter lang:lang_idx set language: 1-English; 2-Chinese

  • Service parameter restore Clear configuration, restore factory settings

  • Service parameter erasefs clear file system

  • Service parameter blg:backlight backlight brightness